add a few functions to CCHashTrie

This commit is contained in:
Simon Cruanes 2015-09-04 22:20:00 +02:00
parent 0aef0300b8
commit 8efd5003f8
2 changed files with 32 additions and 0 deletions

View file

@ -48,15 +48,28 @@ module type S = sig
val fold : ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b
(** {6 Conversions} *)
val to_list : 'a t -> (key * 'a) list
val add_list : 'a t -> (key * 'a) list -> 'a t
val of_list : (key * 'a) list -> 'a t
val add_seq : 'a t -> (key * 'a) sequence -> 'a t
val of_seq : (key * 'a) sequence -> 'a t
val to_seq : 'a t -> (key * 'a) sequence
(** {6 IO} *)
val print : key printer -> 'a printer -> 'a t printer
val as_tree : 'a t -> [`L of int * (key * 'a) list | `N ] ktree
(** For debugging purpose: explore the structure of the tree,
with [`L (h,l)] being a leaf (with shared hash [h])
and [`N] an inner node *)
end
module type KEY = sig
@ -308,6 +321,15 @@ module Make(Key : KEY)
let of_list l = add_list empty l
let add_seq m s =
let m = ref m in
s (fun (k,v) -> m := add k v !m);
!m
let of_seq s = add_seq empty s
let to_seq m yield = iter (fun k v -> yield (k,v)) m
let print ppk ppv out m =
let first = ref true in
iter

View file

@ -59,12 +59,22 @@ module type S = sig
val fold : ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b
(** {6 Conversions} *)
val to_list : 'a t -> (key * 'a) list
val add_list : 'a t -> (key * 'a) list -> 'a t
val of_list : (key * 'a) list -> 'a t
val add_seq : 'a t -> (key * 'a) sequence -> 'a t
val of_seq : (key * 'a) sequence -> 'a t
val to_seq : 'a t -> (key * 'a) sequence
(** {6 IO} *)
val print : key printer -> 'a printer -> 'a t printer
val as_tree : 'a t -> [`L of int * (key * 'a) list | `N ] ktree