Skip to content

Commit

Permalink
Merge pull request #437 from BridgeTheMasterBuilder/master
Browse files Browse the repository at this point in the history
Fix CCMultiMap
  • Loading branch information
c-cube authored Aug 4, 2023
2 parents ba516e8 + c97b934 commit 01358f9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ to list authors based on the git commits.
Assuming your are in a clone of the repository:

1. Some dependencies are required, you'll need
`opam install benchmark qcheck-core iter gen mdx uutf`.
`opam install benchmark qcheck-core iter gen mdx uutf yojson`.
2. run `make all` to enable everything (including tests).
3. make your changes, commit, push, and open a PR.
4. use `make test` without moderation! It must pass before a PR
Expand Down
39 changes: 28 additions & 11 deletions src/data/CCMultiMap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module type S = sig
val find : t -> key -> value list
(** 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 *)

val count : t -> key -> int
Expand Down Expand Up @@ -224,11 +224,21 @@ module type BIDIR = sig
val mem_right : t -> right -> bool
(** Is the right key present in at least one pair? *)

val find_left : t -> left -> right iter
(** Find all bindings for this given left-key *)
val find_left : t -> left -> right list
(** List of values for this given left-key.
This used to return an iter, but returns a list since NEXT_RELEASE. *)

val find_right : t -> right -> left iter
(** Find all bindings for this given right-key *)
val find_left_iter : t -> left -> right iter
(** Iterate on bindings for this given left-key
@since NEXT_RELEASE *)

val find_right : t -> right -> left list
(** List of values for this given right-key.
This used to return an iter, but returns a list since NEXT_RELEASE. *)

val find_right_iter : t -> right -> left iter
(** Iterate on bindings for this given left-key
@since NEXT_RELEASE *)

val find1_left : t -> left -> right option
(** like {!find_left} but returns at most one value *)
Expand Down Expand Up @@ -281,14 +291,21 @@ module MakeBidir (L : OrderedType) (R : OrderedType) = struct

let cardinal_left m = MapL.size m.left
let cardinal_right m = MapR.size m.right
let find_left m a = MapL.find_iter m.left a
let find_right 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 m a)
let remove_right m b = _fold_iter (fun m a -> remove m a b) m (find_right m b)
let find_left m a = MapL.find m.left a
let find_left_iter m a = MapL.find_iter m.left a
let find_right m b = MapR.find m.right 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_right m b = MapR.mem m.right b
let find1_left m a = _head_iter (find_left m a)
let find1_right m b = _head_iter (find_right m b)
let find1_left m a = _head_iter (find_left_iter m a)
let find1_right m b = _head_iter (find_right_iter m b)
let fold f acc m = MapL.fold m.left acc f
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
Expand Down
18 changes: 13 additions & 5 deletions src/data/CCMultiMap.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module type S = sig
val find : t -> key -> value list
(** 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. *)

val count : t -> key -> int
Expand Down Expand Up @@ -119,11 +119,19 @@ module type BIDIR = sig
val mem_right : t -> right -> bool
(** Is the right key present in at least one pair? *)

val find_left : t -> left -> right iter
(** Find all bindings for this given left-key. *)
val find_left : t -> left -> right list
(** List of values for this given left-key. *)

val find_right : t -> right -> left iter
(** Find all bindings for this given right-key. *)
val find_left_iter : t -> left -> right iter
(** Iterate on bindings for this given left-key.
@since NEXT_RELEASE *)

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 NEXT_RELEASE *)

val find1_left : t -> left -> right option
(** Like {!find_left} but returns at most one value. *)
Expand Down

0 comments on commit 01358f9

Please sign in to comment.