mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-09 04:35:29 -05:00
fix(CCMultiMap): Rename functions find_left and find_right in the bidirectional multimap to find_left_iter and find_right_iter respectively to reflect their usage, and add new functions to replace the old find_left and find_right that return a list of values rather than an iterator, to make the signatures of CCMultiMap.S and CCMultiMap.BIDIR cohere. Additionally, change the return type of S.find_iter from t -> key -> (value -> unit) -> unit to t -> key -> value iter. These types are the same though, it's just for clarity since CCMultiMap already exposes an iter type
This commit is contained in:
parent
4fb0df50e9
commit
528b9030a4
2 changed files with 39 additions and 16 deletions
|
|
@ -30,7 +30,7 @@ module type S = sig
|
||||||
val find : t -> key -> value list
|
val find : t -> key -> value list
|
||||||
(** List of values for this key *)
|
(** List of values for this key *)
|
||||||
|
|
||||||
val find_iter : t -> key -> (value -> unit) -> unit
|
val find_iter : t -> key -> value iter
|
||||||
(** Iterate on bindings for this key *)
|
(** Iterate on bindings for this key *)
|
||||||
|
|
||||||
val count : t -> key -> int
|
val count : t -> key -> int
|
||||||
|
|
@ -224,11 +224,19 @@ module type BIDIR = sig
|
||||||
val mem_right : t -> right -> bool
|
val mem_right : t -> right -> bool
|
||||||
(** Is the right key present in at least one pair? *)
|
(** Is the right key present in at least one pair? *)
|
||||||
|
|
||||||
val find_left : t -> left -> right iter
|
val find_left : t -> left -> right list
|
||||||
(** Find all bindings for this given left-key *)
|
(** List of values for this given left-key *)
|
||||||
|
|
||||||
val find_right : t -> right -> left iter
|
val find_left_iter : t -> left -> right iter
|
||||||
(** Find all bindings for this given right-key *)
|
(** Iterate on bindings for this given left-key
|
||||||
|
@since 3.12 *)
|
||||||
|
|
||||||
|
val find_right : t -> right -> left list
|
||||||
|
(** List of values for this given right-key *)
|
||||||
|
|
||||||
|
val find_right_iter : t -> right -> left iter
|
||||||
|
(** Iterate on bindings for this given left-key
|
||||||
|
@since 3.12 *)
|
||||||
|
|
||||||
val find1_left : t -> left -> right option
|
val find1_left : t -> left -> right option
|
||||||
(** like {!find_left} but returns at most one value *)
|
(** like {!find_left} but returns at most one value *)
|
||||||
|
|
@ -281,14 +289,21 @@ module MakeBidir (L : OrderedType) (R : OrderedType) = struct
|
||||||
|
|
||||||
let cardinal_left m = MapL.size m.left
|
let cardinal_left m = MapL.size m.left
|
||||||
let cardinal_right m = MapR.size m.right
|
let cardinal_right m = MapR.size m.right
|
||||||
let find_left m a = MapL.find_iter m.left a
|
let find_left m a = MapL.find m.left a
|
||||||
let find_right m b = MapR.find_iter m.right b
|
let find_left_iter m a = MapL.find_iter m.left a
|
||||||
let remove_left m a = _fold_iter (fun m b -> remove m a b) m (find_left m a)
|
let find_right m b = MapR.find m.right b
|
||||||
let remove_right m b = _fold_iter (fun m a -> remove m a b) m (find_right m b)
|
let find_right_iter m b = MapR.find_iter m.right b
|
||||||
|
|
||||||
|
let remove_left m a =
|
||||||
|
_fold_iter (fun m b -> remove m a b) m (find_left_iter m a)
|
||||||
|
|
||||||
|
let remove_right m b =
|
||||||
|
_fold_iter (fun m a -> remove m a b) m (find_right_iter m b)
|
||||||
|
|
||||||
let mem_left m a = MapL.mem m.left a
|
let mem_left m a = MapL.mem m.left a
|
||||||
let mem_right m b = MapR.mem m.right b
|
let mem_right m b = MapR.mem m.right b
|
||||||
let find1_left m a = _head_iter (find_left m a)
|
let find1_left m a = _head_iter (find_left_iter m a)
|
||||||
let find1_right m b = _head_iter (find_right m b)
|
let find1_right m b = _head_iter (find_right_iter m b)
|
||||||
let fold f acc m = MapL.fold m.left acc f
|
let fold f acc m = MapL.fold m.left acc f
|
||||||
let pairs m = MapL.to_iter m.left
|
let pairs m = MapL.to_iter m.left
|
||||||
let add_pairs m seq = _fold_iter (fun m (a, b) -> add m a b) m seq
|
let add_pairs m seq = _fold_iter (fun m (a, b) -> add m a b) m seq
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ module type S = sig
|
||||||
val find : t -> key -> value list
|
val find : t -> key -> value list
|
||||||
(** List of values for this key. *)
|
(** List of values for this key. *)
|
||||||
|
|
||||||
val find_iter : t -> key -> (value -> unit) -> unit
|
val find_iter : t -> key -> value iter
|
||||||
(** Iterate on bindings for this key. *)
|
(** Iterate on bindings for this key. *)
|
||||||
|
|
||||||
val count : t -> key -> int
|
val count : t -> key -> int
|
||||||
|
|
@ -119,11 +119,19 @@ module type BIDIR = sig
|
||||||
val mem_right : t -> right -> bool
|
val mem_right : t -> right -> bool
|
||||||
(** Is the right key present in at least one pair? *)
|
(** Is the right key present in at least one pair? *)
|
||||||
|
|
||||||
val find_left : t -> left -> right iter
|
val find_left : t -> left -> right list
|
||||||
(** Find all bindings for this given left-key. *)
|
(** List of values for this given left-key. *)
|
||||||
|
|
||||||
val find_right : t -> right -> left iter
|
val find_left_iter : t -> left -> right iter
|
||||||
(** Find all bindings for this given right-key. *)
|
(** Iterate on bindings for this given left-key.
|
||||||
|
@since 3.12 *)
|
||||||
|
|
||||||
|
val find_right : t -> right -> left list
|
||||||
|
(** List of values for this given right-key. *)
|
||||||
|
|
||||||
|
val find_right_iter : t -> right -> left iter
|
||||||
|
(** Iterate on bindings for this given left-key.
|
||||||
|
@since 3.12 *)
|
||||||
|
|
||||||
val find1_left : t -> left -> right option
|
val find1_left : t -> left -> right option
|
||||||
(** Like {!find_left} but returns at most one value. *)
|
(** Like {!find_left} but returns at most one value. *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue