@rimbu/bimultimap

A bidirectional immutable MultiMap of keys and values for TypeScript

Usage no npm install needed!

<script type="module">
  import rimbuBimultimap from 'https://cdn.skypack.dev/@rimbu/bimultimap';
</script>

README

@rimbu/bimultimap

A BiMultiMap is a bidirectional MultiMap of keys and values, where each key-value association also has an inverse value-key association. There is a many-to-many mapping between keys and values.

This package exports the following types:

Name Description
BiMultiMap<K, V> a generic BiMultiMap between keys of type K and values of type V
HashBiMultiMap<K, V> a BiMultiMap implementation where keys and values are hashed
SortedBiMultiMap<K, V> a BiMultiMap implementation where keys and values are sorted

For complete documentation please visit the BiMultiap page in the Rimbu Docs.

Or Try Out Rimbu in CodeSandBox.

Installation

All types are exported through @rimbu/core. It is recommended to use that package.

To install this package only:

Yarn/NPM

yarn add @rimbu/bimultimap

or

npm i @rimbu/bimultimap

Deno

Create a file called rimbu.ts and add the following:

export * from 'https://deno.land/x/rimbu/bimultimap/mod.ts';

Or using a pinned version (x.y.z):

export * from 'https://deno.land/x/rimbu@x.y.z/bimultimap/mod.ts';

Then import what you need from rimbu.ts:

import { HashBiMultiMap } from './rimbu.ts';

Because Rimbu uses complex types, it's recommended to use the --no-check flag (your editor should already have checked your code) and to specify a tsconfig.json file with the settings described below.

Running your script then becomes:

deno run --no-check --config tsconfig.json <your-script>.ts

Usage

import { HashBiMultiMap } from '@rimbu/bimultimap';

const biMultiMap = HashBiMultiMap.of([1, 'a'], [2, 'b'], [3, 'b']);
console.log(biMultiMap.toString());
// HashBiMultiMap(1 <-> ['a'], 2 <-> ['b'], 3 <-> ['b'])

console.log(biMultiMap.getValues(1).toArray());
// ['a']
console.log(biMultiMap.getKeys('b').toArray());
// [2, 3]

Author

Arvid Nicolaas

Contributing

Feel very welcome to contribute to further improve Rimbu. Please read our Contributing guide.

Contributors

Made with contributors-img.

License

Licensed under the MIT License, Copyright © 2020-present Arvid Nicolaas.

See LICENSE for more information.