mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
mllib: move remove_duplicates from v2v
Simple code motion.
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user