Class Multiset
In: lib/multiset.rb
Parent: Set

Multiset implements a collection of unordered values and allows duplicates.

Example

  require 'multiset'
  s1 = Multiset.new [1, 2]              # -> #<Multiset: {1, 2}>
  s1.add(2)                             # -> #<Multiset: {1, 2, 2}>
  s1.merge([2, 6])                      # -> #<Multiset: {1, 2, 2, 2, 3}>
  s1.multiplicity(2)                    # -> 3
  s1.multiplicity(3)                    # -> 1

Methods

&   <<   ==   ^   add   cardinality   delete   delete_if   each   eql?   intersection   length   merge   multiplicity   proper_subset?   proper_superset?   size   subset?   subtract   superset?   to_a  

Public Instance methods

Returns a new set containing elements common to the set and the given enumerable object.

<<(o)

Alias for add

==(set)

Alias for eql?

Returns a new set containing elements exclusive between the set and the given enumerable object. (set ^ enum) is equivalent to ((set | enum) - (set & enum)).

Adds the given object to the set and returns self. Use merge to add many elements at once.

Returns the total number of elements in a multiset, including repeated memberships

Deletes all the identical object from the set and returns self. If n is given, it will remove that amount of identical objects from the set. Use subtract to delete many different items at once.

Deletes every element of the set for which block evaluates to true, and returns self.

Calls the given block once for each element in the set, passing the element as parameter. Returns an enumerator if no block is given.

Returns true if two sets are equal. Two multisets are equal if they have the same cardinalities and each element has the same multiplicity in both sets. The equality of each element inside the multiset is defined according to Object#eql?.

intersection(enum)

Alias for #&

length()

Alias for cardinality

Merges the elements of the given enumerable object to the set and returns self.

Returns the number of times an element belongs to the multiset.

Returns true if the set is a proper subset of the given set.

Returns true if the set is a proper superset of the given set.

size()

Alias for cardinality

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

Deletes every element that appears in the given enumerable object and returns self.

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

Converts the set to an array. The order of elements is uncertain.

[Validate]