class MultiSet(T)
- MultiSet(T)
- Reference
- Object
Included Modules
- Enumerable(T)
- Iterable(T)
Defined in:
datastructure/multi_set.crConstructors
-
.additive_identify : self
Returns the additive identity of this type.
-
.new(elements : Enumerable(T))
Creates a new multiset from the elements in elements.
-
.new(initial_capacity = nil)
Creates a new, empty multiset.
Class Method Summary
-
.from_counts(counts : Enumerable(Tuple(T, Int32))) : MultiSet(T)
Creates a new multiset from the enumerable of {element, count}.
Instance Method Summary
-
#&(other : MultiSet(T)) : self
Intersection.
-
#*(times : Int) : self
Repetition
-
#+(other : MultiSet(U)) : MultiSet(T | U) forall U
Addition.
-
#-(other : MultiSet) : self
Difference.
-
#-(other : Enumerable) : self
Difference.
-
#<<(object : T) : self
Adds object to the multiset and returns
self. -
#==(other : MultiSet) : Bool
Compares with other.
-
#===(object : T) : Bool
Returns
trueif object exists in the multiset. -
#add(object : T, count : Int32) : self
Adds object to the multiset count times and returns
self. -
#add(object : T) : self
Adds object to the multiset and returns
self. -
#clear : self
Removes all elements in the multiset and returns
self. -
#clone : self
Returns a new multiset with all of the elements cloned.
-
#concat(elems) : self
Adds
#eachelement of elems to the multisetset and returnsself. -
#count(object : T)
Returns the number of times that the object is present in the multiset.
-
#delete(object : T) : Bool
Removes the object from the multiset and returns
trueif it was present, otherwise returnsfalse. -
#delete(object : T, count : Int32) : Bool
Removes the object from the multiset at most count times and returns
trueif it was present, otherwise returnsfalse. -
#dup : self
Returns a new multiset with all of the same elements.
-
#each
Returns an iterator for each element of the multiset.
-
#each(&) : Nil
Yields each element of the multiset, and returns
nil. -
#each_count
Returns an iterator for each tuple of element and count of the multiset
-
#each_count(&) : Nil
Yields each pair of element and count of the multiset, and returns
nil. -
#empty? : Bool
Returns
trueif the multiset is empty. -
#includes?(object : T) : Bool
Returns
trueif object exists in the multiset. -
#inspect(io : IO) : Nil
Writes a string representation of the multiset to io.
-
#intersects?(other : self) : Bool
Returns
trueif the multiset and the given multiset have at least one element in common. -
#kind_count : Int32
Returns the number of kinds in the multiset.
-
#size : Int32
Returns the number of elements in the set.
-
#subset_of?(other : self) : Bool
Returns
trueif the multiset is a subset of the given multiset. -
#subtract(other : MultiSet(U)) : self forall U
Returns
selfafter removing other elements. -
#subtract(other : Enumerable) : self forall U
Returns
selfafter removing other elements. -
#superset_of?(other : self) : Bool
Returns true if the multiset is a superset of the given multiset.
-
#to_s(io : IO) : Nil
Writes a string representation of the multiset to io.
-
#|(other : MultiSet(U)) : MultiSet(T | U) forall U
Union.
Instance methods inherited from module Enumerable(T)
accumulate(init : U) : Array(U) forall Uaccumulate : Array(T)
accumulate(init : U, &block : U, T -> U) : Array(U) forall U
accumulate(&block : T, T -> T) : Array(T) accumulate, mex : T mex, mex_sorted : T mex_sorted, tally(*, default : Int32) : Hash(T, Int32) tally, unique : self
unique(&) : self unique
Constructor Detail
Returns the additive identity of this type.
This is an empty multiset
Class Method Detail
Creates a new multiset from the enumerable of {element, count}.
Instance Method Detail
Intersection.
MultiSet{1, 2, 2, 3} & MultiSet{2, 3, 3, 4} # => MultiSet{2, 3}
Repetition
MultiSet{1, 2, 2} * 2 # => MultiSet{1, 1, 2, 2, 2, 2}
Difference.
MultiSet{1, 2, 2, 3} - MultiSet{1, 2} # => MultiSet{2, 3}
MultiSet{1, 2, 2, 3} - [1, 2] # => MultiSet{2, 3}
Difference.
MultiSet{1, 2, 2, 3} - MultiSet{1, 2} # => MultiSet{2, 3}
MultiSet{1, 2, 2, 3} - [1, 2] # => MultiSet{2, 3}
Adds object to the multiset count times and returns self.
Removes the object from the multiset and returns true if it was present, otherwise returns false.
Removes the object from the multiset at most count times and returns true
if it was present, otherwise returns false.
Writes a string representation of the multiset to io.
set = MultiSet{3, 1, 4, 1, 5}
set.inspect # => "{3(1), 1(2), 4(1), 5(1)}"
Returns true if the multiset and the given multiset have at least one element in common.
Returns true if the multiset is a subset of the given multiset.
Returns self after removing other elements.
MultiSet{1, 2, 2, 3}.subtract MultiSet{1, 2} # => MultiSet{2, 3}
MultiSet{1, 2, 2, 3}.subtract [1, 2] # => MultiSet{2, 3}
Returns self after removing other elements.
MultiSet{1, 2, 2, 3}.subtract MultiSet{1, 2} # => MultiSet{2, 3}
MultiSet{1, 2, 2, 3}.subtract [1, 2] # => MultiSet{2, 3}
Returns true if the multiset is a superset of the given multiset.
Writes a string representation of the multiset to io.
set = MultiSet{3, 1, 4, 1, 5}
set.to_s # => "MultiSet{3, 1, 1, 4, 5}"
Union.
MultiSet{1, 2, 2} | MultiSet{2, 3} # => MultiSet{1, 2, 2, 3}