[containers-users] Request for comments on BiMap

Simon Cruanes simon.cruanes.2007 at m4x.org
Fri Feb 23 02:07:02 GMT 2018


This looks pretty ok (albeit far from complete, a proper module will
have to have conversion from/to lists, from/to sequences, and probably
some other convenient functions such as membership testing or
cardinality or is_empty).

Some comments for future inclusion in containers:

- The module type Bimap should be called S (main signature).
- Also, what add does on collision over any key should be clearly
specified in the docs
- that find functions can raise Not_found must be properly documented (@raise)
- in the implementation of add, don't use !=, use L.compare (resp.
  R.compare). != will be almost always wrong.

Le Fri, 23 Feb 2018, SP wrote:

> I've started working on a BiMap, a map where (key, value) is also
> (value, key) in a one-to-one relationship.
> https://github.com/c-cube/ocaml-containers/compare/master...orbifx:bimap
> As I'm writing this I have written `empty`, `add`, `find_left` and
> `find_right`.
> The idea is that when adding a left-key, right-value to the BiMap, it
> doesn't just check for the preexistence of the left key, but also checks
> if the right value already has a left key and removes it if so. Vice
> versa for right key, left value.

> One question I have is why are map values first in the order of
> parameters? For example:
> https://github.com/c-cube/ocaml-containers/blob/master/src/data/CCMultiMap.ml#L294


Simon Cruanes

key 49AA62B6, fingerprint 949F EB87 8F06 59C6 D7D3  7D8D 4AC0 1D08 49AA 62B6
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.ocaml.org/pipermail/containers-users/attachments/20180222/509c92aa/attachment.sig>

More information about the Containers-users mailing list