Multiset implementation
npm install @emilbayes/multiset@emilbayes/multiset
> Multiset implementation
``js
const Multiset = require('@emilbayes/multiset')
const m = new Multiset([1, 1, 2, 3, 4, 4, 3, 8, 1])
console.log(m.count(1)) // => 3
console.log(m.count(4)) // => 2
console.log(m.size) // => 9
console.log(m.uniqueSize) // => 5
m.add(10)
console.log(m.size) // => 10
console.log(m.uniqueSize) // => 6
`
Create a new Multiset with optional initial array of elements, and optionalkey
identity , which defaults to strict equality.
Number of total elements in the Multiset.
Number of unique elements in the Multiset.
Add elm to the Multiset, with optional multiplicity n.key
Equality is checked with .
Delete elm from the Multiset, optionally decrementing by n.key
If final count is 0 or less, the element is removed from the Multiset.
Equality is checked with .
Check for existence.
Count occurrences of elm in the Multiset.
Check if m and rhs contain the same elements with same multiplicity.
Check if m is a subset of superset, meaning superset contain the samem
elements with at least the least the same multiplicity as .
Filter unique elements from the Multiset, preserving count in the new Multiset.
A new Multiset is created but if the elements are not primitives, they will
share references between the two Multisets.
Find the difference m \ rhs, copying the Multiset with the differencerhs
contained in the new Multiset. can either be a Multiset or an Array.
Iterate elements of the Multiset as an array, meaning elements with multiplicity
will be enumerated n times.
Map elements of the Multiset as an array, meaning elements with multiplicity
will be enumerated n times. Returns the resulting array.
Reduce elements of the Multiset as an array, meaning elements with multiplicity
will be enumerated n times. Returns the resulting accumulated value.
Clone the Multiset.
A new Multiset is created but if the elements are not primitives, they will
share references between the two Multisets.
Iterate elements of the Multiset with multiplicity.
Iterate [elm, multiplicity] of the Multiset.
Iterate multiplicity of the Multiset.
Iterate unqiue elm of the Multiset.
`sh``
npm install @emilbayes/multiset