Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aviate-labs/bimap.mo
Generic Bijective Maps in Motoko
https://github.com/aviate-labs/bimap.mo
Last synced: 3 months ago
JSON representation
Generic Bijective Maps in Motoko
- Host: GitHub
- URL: https://github.com/aviate-labs/bimap.mo
- Owner: aviate-labs
- License: apache-2.0
- Created: 2021-08-31T20:07:42.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-16T17:45:17.000Z (almost 2 years ago)
- Last Synced: 2024-04-19T01:33:16.046Z (7 months ago)
- Language: Motoko
- Homepage:
- Size: 14.6 KB
- Stars: 7
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-motoko - motoko-BiMap - A bimap (or "bidirectional map") is a map that preserves the uniqueness of its values as well as that of its keys. (Libraries / Data structures)
README
# BiMap
A Motoko module for bijective maps.
A bimap (or "bidirectional map") is a map that preserves the uniqueness of its values as well as that of its keys.
## Usage
```motoko
let m = BiMap.New(
BiHashMap.empty(0, Nat.equal, Hash.hash),
BiHashMap.empty(0, Text.equal, Text.hash),
Text.equal,
);m.insert(0, "a");
m.getByLeft(0);
// [(0, "a")];
m.getByRight("a");
// [(0, "a")];
```Works with any `object` that implements the following interface:
```motoko
type Map = {
// Returns the number of entries in this map.
size() : Nat;
// Returns an iterator over the key value pairs in this map.
entries() : Iter.Iter<(L, R)>;
// Gets the entry with the key `k` and returns its associated value if it existed or `null` otherwise.
get(k : L) : ?R;
// Removes the entry with the key `k` and returns the associated value if it existed or `null` otherwise.
remove(k : L) : ?R;
// Insert the value `v` at key `k`. Overwrites an existing entry with key `k`.
put(k : L, v : R) : ();
};
```## Predefined Empty Map Generators
- TrieMap
- HashMap