CCHashtbl: Added functions {keys,values}_list.

This commit is contained in:
Vincent Bernardoff 2014-12-22 16:40:40 +01:00
parent 9fb2d54f01
commit 22e5b26b94
2 changed files with 9 additions and 0 deletions

View file

@ -40,6 +40,9 @@ let keys tbl k = Hashtbl.iter (fun key _ -> k key) tbl
let values tbl k = Hashtbl.iter (fun _ v -> k v) tbl let values tbl k = Hashtbl.iter (fun _ v -> k v) tbl
let keys_list tbl = Hashtbl.fold (fun k _ a -> k::a) tbl []
let values_list tbl = Hashtbl.fold (fun _ v a -> v::a) tbl []
let map_list f h = let map_list f h =
Hashtbl.fold Hashtbl.fold
(fun x y acc -> f x y :: acc) (fun x y acc -> f x y :: acc)

View file

@ -44,6 +44,12 @@ val keys : ('a,'b) Hashtbl.t -> 'a sequence
val values : ('a,'b) Hashtbl.t -> 'b sequence val values : ('a,'b) Hashtbl.t -> 'b sequence
(** Iterate on values in the table *) (** Iterate on values in the table *)
val keys_list : ('a, 'b) Hashtbl.t -> 'a list
(** [keys t] is the list of keys in [t]. *)
val values_list : ('a, 'b) Hashtbl.t -> 'b list
(** [values t] is the list of values in [t]. *)
val map_list : ('a -> 'b -> 'c) -> ('a, 'b) Hashtbl.t -> 'c list val map_list : ('a -> 'b -> 'c) -> ('a, 'b) Hashtbl.t -> 'c list
(** Map on a hashtable's items, collect into a list *) (** Map on a hashtable's items, collect into a list *)