mllib: move remove_duplicates from v2v

Simple code motion.
This commit is contained in:
Pino Toscano
2016-09-23 17:40:09 +02:00
parent b5d57baf3d
commit d7551ec39b
4 changed files with 15 additions and 12 deletions

View File

@@ -297,6 +297,15 @@ let sort_uniq ?(cmp = Pervasives.compare) xs =
let xs = uniq ~cmp xs in
xs
let remove_duplicates xs =
let h = Hashtbl.create (List.length xs) in
let rec loop = function
| [] -> []
| x :: xs when Hashtbl.mem h x -> xs
| x :: xs -> Hashtbl.add h x true; x :: loop xs
in
loop xs
let push_back xsp x = xsp := !xsp @ [x]
let push_front x xsp = xsp := x :: !xsp
let pop_back xsp =

View File

@@ -147,6 +147,12 @@ val uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
(** Sort and uniquify a list. *)
val remove_duplicates : 'a list -> 'a list
(** Remove duplicates from an unsorted list; useful when the order
of the elements matter.
Please use [sort_uniq] when the order does not matter. *)
val push_back : 'a list ref -> 'a -> unit
val push_front : 'a -> 'a list ref -> unit
val pop_back : 'a list ref -> 'a

View File

@@ -81,15 +81,6 @@ let compare_app2_versions app1 app2 =
compare_version app1.Guestfs.app2_release app2.Guestfs.app2_release
)
let remove_duplicates xs =
let h = Hashtbl.create (List.length xs) in
let rec loop = function
| [] -> []
| x :: xs when Hashtbl.mem h x -> xs
| x :: xs -> Hashtbl.add h x true; x :: loop xs
in
loop xs
let du filename =
(* There's no OCaml binding for st_blocks, so run coreutils 'du'. *)
let cmd =

View File

@@ -46,9 +46,6 @@ val find_uefi_firmware : string -> Uefi.uefi_firmware
val compare_app2_versions : Guestfs.application2 -> Guestfs.application2 -> int
(** Compare two app versions. *)
val remove_duplicates : 'a list -> 'a list
(** Remove duplicates from a list. *)
val du : string -> int64
(** Return the true size of a file in bytes, including any wasted
space caused by internal fragmentation (the overhead of using