mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
Merge pull request #25 from vbmithr/hashtbl
CCHashtbl: renamed keys and values to iter_keys and iter_values, added k...
This commit is contained in:
commit
bd84b620ec
3 changed files with 31 additions and 0 deletions
|
|
@ -8,3 +8,4 @@
|
||||||
- hcarty (Hezekiah M. Carty)
|
- hcarty (Hezekiah M. Carty)
|
||||||
- struktured (Carmelo Piccione)
|
- struktured (Carmelo Piccione)
|
||||||
- Bernardo da Costa
|
- Bernardo da Costa
|
||||||
|
- Vincent Bernardoff (vbmithr)
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -81,6 +84,14 @@ module type S = sig
|
||||||
val values : 'a t -> 'a sequence
|
val values : 'a t -> 'a 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].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val values_list : ('a, 'b) Hashtbl.t -> 'b list
|
||||||
|
(** [values t] is the list of values in [t].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val map_list : (key -> 'a -> 'b) -> 'a t -> 'b list
|
val map_list : (key -> 'a -> 'b) -> 'a t -> 'b list
|
||||||
(** Map on a hashtable's items, collect into a list *)
|
(** Map on a hashtable's items, collect into a list *)
|
||||||
|
|
||||||
|
|
@ -108,6 +119,9 @@ module Make(X : Hashtbl.HashedType) = struct
|
||||||
|
|
||||||
let values tbl k = iter (fun _ v -> k v) tbl
|
let values tbl k = 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 =
|
||||||
fold
|
fold
|
||||||
(fun x y acc -> f x y :: acc)
|
(fun x y acc -> f x y :: acc)
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,14 @@ 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].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val values_list : ('a, 'b) Hashtbl.t -> 'b list
|
||||||
|
(** [values t] is the list of values in [t].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
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 *)
|
||||||
|
|
||||||
|
|
@ -73,6 +81,14 @@ module type S = sig
|
||||||
val values : 'a t -> 'a sequence
|
val values : 'a t -> 'a 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].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val values_list : ('a, 'b) Hashtbl.t -> 'b list
|
||||||
|
(** [values t] is the list of values in [t].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val map_list : (key -> 'a -> 'b) -> 'a t -> 'b list
|
val map_list : (key -> 'a -> 'b) -> 'a t -> 'b list
|
||||||
(** Map on a hashtable's items, collect into a list *)
|
(** Map on a hashtable's items, collect into a list *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue