https://github.com/github/multimap
A map in which more than one value may be stored under each key.
https://github.com/github/multimap
keep multimap
Last synced: 7 months ago
JSON representation
A map in which more than one value may be stored under each key.
- Host: GitHub
- URL: https://github.com/github/multimap
- Owner: github
- License: mit
- Created: 2020-05-21T22:59:22.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-02-19T23:23:02.000Z (about 1 year ago)
- Last Synced: 2025-06-20T07:07:26.863Z (9 months ago)
- Topics: keep, multimap
- Language: JavaScript
- Homepage:
- Size: 426 KB
- Stars: 38
- Watchers: 3
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# MultiMap
The [multimap][1] data structure is a map in which more than one value may be stored under each key.
[1]: https://en.wikipedia.org/wiki/Multimap
## Installation
```
$ npm install @github/multimap
```
## Usage
```js
import MultiMap from '@github/multimap'
```
```ts
const map = new MultiMap()
map.set('a', 1)
map.set('a', 2)
map.get('a') // => Set([1, 2])
map.has('a') // => true
map.size // => 1
```
### Constructors
- `MultiMap()` - Create an empty map.
- `MultiMap(iterable)` - Create a map with values from an iterable yielding key value pairs: `new MultiMap([['k', 1], ['k', 2]])`
### Methods
- `get(key)` - Retrieve the Set of values stored under a key or the empty Set if the key does not exist.
- `set(key, value)` - Add a value to the key's set without removing previous values. Returns the map so `set` can be chained.
- `has(key)` - Returns true if a value is stored under the key.
- `delete(key)` - Remove key and all of key's values. Returns true if the key existed.
- `delete(key, value)` - Remove a value from the key's set. Returns true if the key and value existed.
- `drain(value)` - Remove a value from all keys that reference it. Returns an array of keys removed.
- `clear()` - Remove all keys and values to empty the map.
- `keys()` - An iterator of map keys.
- `values()` - An iterator of Sets of values for all keys.
- `entries()` - An iterator of [key, Set] pairs.
### Properties
- `size` - The number of keys in the map.
## Development
```
npm install
npm test
```
## License
Distributed under the MIT license. See LICENSE for details.