Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(patterns): add multi map #808

Merged
merged 5 commits into from
Mar 14, 2024
Merged

feat(patterns): add multi map #808

merged 5 commits into from
Mar 14, 2024

Conversation

0xRezaa
Copy link
Contributor

@0xRezaa 0xRezaa commented Mar 13, 2024

This PR adds a Data-structure to the patterns package called MultiMap (similar to already existing SetMultiMap).

It maps key pairs to values
(k1, k2) -> v

@example

const m = new MultiMap([['a', 1, 'one'],['a', 2, 'two'])
m.add('a', 3, 'three')

m.has('a', 1) // => true
m.has('a',2) // => true
m.has('a',3) // => true
m.has('a',4) // => false

m.get('a', 1) // => 'one'
m.get('a',2) // => 'two'
m.get('a',3) // => 'three'
m.get('a',4) // => undefined

m.delete('a', 1) // => true
m.has('a', 1) // => false

This PR also refactors the SetMultiMap to use the MultiMap internally.
The SetMultiMap acts as a Set on key value pairs.
So we can conceptually see it as following MultiMap:
(k, v) -> boolean

@0xRezaa 0xRezaa requested review from AviVahl, danieleww and daomry March 13, 2024 22:18
@daomry daomry merged commit 21fc1eb into master Mar 14, 2024
6 checks passed
@daomry daomry deleted the rezab/add-multi-map branch March 14, 2024 07:58
}
}

export function isMultiMap<K1, K2, V>(x: any): x is MultiMap<K1, K2, V> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use unknown instead of any

AviVahl added a commit that referenced this pull request Mar 17, 2024
AviVahl added a commit that referenced this pull request Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants