class MultiSet(T)

Included Modules

Defined in:

datastructure/multi_set.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Enumerable(T)

accumulate(init : U) : Array(U) forall U
accumulate : 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

def self.additive_identify : self #

Returns the additive identity of this type.

This is an empty multiset


[View source]
def self.new(elements : Enumerable(T)) #

Creates a new multiset from the elements in elements.


[View source]
def self.new(initial_capacity = nil) #

Creates a new, empty multiset.


[View source]

Class Method Detail

def self.from_counts(counts : Enumerable(Tuple(T, Int32))) : MultiSet(T) #

Creates a new multiset from the enumerable of {element, count}.


[View source]

Instance Method Detail

def &(other : MultiSet(T)) : self #

Intersection.

MultiSet{1, 2, 2, 3} & MultiSet{2, 3, 3, 4} # => MultiSet{2, 3}

[View source]
def *(times : Int) : self #

Repetition

MultiSet{1, 2, 2} * 2 # => MultiSet{1, 1, 2, 2, 2, 2}

[View source]
def +(other : MultiSet(U)) : MultiSet(T | U) forall U #

Addition. Same as #|.


[View source]
def -(other : MultiSet) : self #

Difference.

MultiSet{1, 2, 2, 3} - MultiSet{1, 2} # => MultiSet{2, 3}
MultiSet{1, 2, 2, 3} - [1, 2]         # => MultiSet{2, 3}

[View source]
def -(other : Enumerable) : self #

Difference.

MultiSet{1, 2, 2, 3} - MultiSet{1, 2} # => MultiSet{2, 3}
MultiSet{1, 2, 2, 3} - [1, 2]         # => MultiSet{2, 3}

[View source]
def <<(object : T) : self #

Adds object to the multiset and returns self.


[View source]
def ==(other : MultiSet) : Bool #

Compares with other.


[View source]
def ===(object : T) : Bool #

Returns true if object exists in the multiset.


[View source]
def add(object : T, count : Int32) : self #

Adds object to the multiset count times and returns self.


[View source]
def add(object : T) : self #

Adds object to the multiset and returns self.


[View source]
def clear : self #

Removes all elements in the multiset and returns self.


[View source]
def clone : self #

Returns a new multiset with all of the elements cloned.


[View source]
def concat(elems) : self #

Adds #each element of elems to the multisetset and returns self.


[View source]
def count(object : T) #

Returns the number of times that the object is present in the multiset.


[View source]
def delete(object : T) : Bool #

Removes the object from the multiset and returns true if it was present, otherwise returns false.


[View source]
def delete(object : T, count : Int32) : Bool #

Removes the object from the multiset at most count times and returns true if it was present, otherwise returns false.


[View source]
def dup : self #

Returns a new multiset with all of the same elements.


[View source]
def each #

Returns an iterator for each element of the multiset.


[View source]
def each(&) : Nil #

Yields each element of the multiset, and returns nil.


[View source]
def each_count #

Returns an iterator for each tuple of element and count of the multiset


[View source]
def each_count(&) : Nil #

Yields each pair of element and count of the multiset, and returns nil.


[View source]
def empty? : Bool #

Returns true if the multiset is empty.


[View source]
def includes?(object : T) : Bool #

Returns true if object exists in the multiset.


[View source]
def inspect(io : IO) : Nil #

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)}"

[View source]
def intersects?(other : self) : Bool #

Returns true if the multiset and the given multiset have at least one element in common.


[View source]
def kind_count : Int32 #

Returns the number of kinds in the multiset.


[View source]
def size : Int32 #

Returns the number of elements in the set.


[View source]
def subset_of?(other : self) : Bool #

Returns true if the multiset is a subset of the given multiset.


[View source]
def subtract(other : MultiSet(U)) : self forall U #

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}

[View source]
def subtract(other : Enumerable) : self forall U #

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}

[View source]
def superset_of?(other : self) : Bool #

Returns true if the multiset is a superset of the given multiset.


[View source]
def to_s(io : IO) : Nil #

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}"

[View source]
def |(other : MultiSet(U)) : MultiSet(T | U) forall U #

Union.

MultiSet{1, 2, 2} | MultiSet{2, 3} # => MultiSet{1, 2, 2, 3}

[View source]