Simple code motion. --- mllib/common_utils.ml | 9 +++++++++ mllib/common_utils.mli | 6 ++++++ v2v/utils.ml | 9 --------- v2v/utils.mli | 3 --- 4 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml index 81d8202..78618f5 100644 --- a/mllib/common_utils.ml +++ b/mllib/common_utils.ml @@ -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 = diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli index 68c0d54..ad43345 100644 --- a/mllib/common_utils.mli +++ b/mllib/common_utils.mli @@ -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 diff --git a/v2v/utils.ml b/v2v/utils.ml index d1ddee7..fb0b802 100644 --- a/v2v/utils.ml +++ b/v2v/utils.ml @@ -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 = diff --git a/v2v/utils.mli b/v2v/utils.mli index 97d98ff..2bd1329 100644 --- a/v2v/utils.mli +++ b/v2v/utils.mli @@ -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 -- 2.7.4 _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs