MultiSet<T> class
Represents a multiset (also known as a bag) containing elements with multiplicity.
Unlike a standard set, a multiset allows duplicate elements. Each element has a multiplicity value representing how many times it appears.
Example:
final ms = MultiSet<int>.fromIterable([1, 1, 1, 2, 2, 3]);
print(ms.multiplicity(1)); // Output: 3
print(ms.cardinality); // Output: 6 (total count including duplicates)
Constructors
- MultiSet()
- Creates an empty multiset.
-
MultiSet.fromIterable(Iterable<
T> elements) - Creates a multiset from an iterable of elements.
Properties
- cardinality → int
-
Returns the total cardinality of the multiset.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Returns true if the multiset contains no elements.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- uniqueCount → int
-
Returns the number of unique elements in the multiset.
no setter
Methods
-
add(
T element, [int count = 1]) → void -
Adds
elementis not specified, adds the element once. -
difference(
MultiSet< T> other) → MultiSet<T> -
Returns the difference of this multiset with
other. -
intersection(
MultiSet< T> other) → MultiSet<T> -
Returns the intersection of this multiset with
other. -
multiplicity(
T element) → int -
Returns the multiplicity of
elementin this multiset. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
T element, [int count = 1]) → void -
Removes
elementfrom the multisetcounttimes. -
sum(
MultiSet< T> other) → MultiSet<T> -
Returns the sum of this multiset with
other. -
toSet(
) → CustomSet< T> - Converts this multiset to a standard set.
-
toString(
) → String -
A string representation of this object.
override
-
union(
MultiSet< T> other) → MultiSet<T> -
Returns the union of this multiset with
other.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited