mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
add a few functions to CCHashTrie
This commit is contained in:
parent
0aef0300b8
commit
8efd5003f8
2 changed files with 32 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue