Class: Stupidedi::Sets::AbstractSet
- Includes:
- Inspect
- Defined in:
- lib/stupidedi/sets/abstract_set.rb
Overview
AbstractSet describes the common interface implemented by its concrete subclasses. The two main implementations are RelativeSet and AbsoluteSet which are each optimized for different kinds of set operations.
Direct Known Subclasses
Set Operations collapse
-
#&(other) ⇒ AbstractSet
Computes the intersection of two sets: the set of elements common between both sets.
-
#+(other) ⇒ AbstractSet
Computes the union of two sets: the set of elements in either or both sets.
-
#-(other) ⇒ AbstractSet
Computes the difference of two sets: the set of elements elements in this set and not the other.
-
#^(other) ⇒ AbstractSet
Computes the symmetric difference of two sets: the set of elements which are in either of the two sets but not in both.
-
#|(other) ⇒ AbstractSet
Computes the union of two sets: the set of elements in either or both sets.
-
#~ ⇒ AbstractSet
Computes the complement of the set: the set of elements not in this set.
Set Ordering collapse
-
#<(other) ⇒ Object
True if this set is a subset of the ‘other` set and there exists at least one element in the `other` set that doesn’t belong to this set.
-
#<=(other) ⇒ Object
True if every element in this set also belongs to the ‘other` set.
-
#>(other) ⇒ Object
True if this set is a superset of the ‘other` set and there exists at least one element in this set that doesn’t belong to the ‘other` set.
-
#>=(other) ⇒ Object
True if every element in the ‘other` set also belongs to this set.
-
#disjoint?(other) ⇒ Boolean
True if this and the ‘other` set have no common elements.
-
#proper_subset?(other) ⇒ Boolean
True if this set is a subset of the ‘other` set and there exists at least one element in the `other` set that doesn’t belong to this set.
-
#proper_superset?(other) ⇒ Boolean
True if this set is a superset of the ‘other` set and there exists at least one element in this set that doesn’t belong to the ‘other` set.
-
#subset?(other) ⇒ Boolean
True if every element in this set also belongs to the ‘other` set.
-
#superset?(other) ⇒ Boolean
True if every element in the ‘other` set also belongs to this set.
Instance Method Summary collapse
-
#exclude?(object) ⇒ Boolean
True if the set does not include the given ‘object`.
-
#infinite? ⇒ Boolean
True if the set contains infinitely many elements.
-
#replace ⇒ AbstractSet
Returns the ‘other` set, converting it to an AbstractSet if it isn’t already.
-
#size ⇒ Numeric
Returns the number of elements in the set.
Methods included from Inspect
Instance Method Details
#&(other) ⇒ AbstractSet
Computes the intersection of two sets: the set of elements common between both sets.
107 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 107 def &(other) intersection(other) end |
#+(other) ⇒ AbstractSet
Computes the union of two sets: the set of elements in either or both sets
75 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 75 def +(other) union(other) end |
#-(other) ⇒ AbstractSet
Computes the difference of two sets: the set of elements elements in this set and not the other.
83 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 83 def -(other) difference(other) end |
#<(other) ⇒ Object
True if this set is a subset of the ‘other` set and there exists at least one element in the `other` set that doesn’t belong to this set
158 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 158 def <(other) proper_subset?(other) end |
#<=(other) ⇒ Object
True if every element in this set also belongs to the ‘other` set
164 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 164 def <=(other) subset?(other) end |
#>(other) ⇒ Object
True if this set is a superset of the ‘other` set and there exists at least one element in this set that doesn’t belong to the ‘other` set
161 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 161 def >(other) proper_superset?(other) end |
#>=(other) ⇒ Object
True if every element in the ‘other` set also belongs to this set
167 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 167 def >=(other) superset?(other) end |
#^(other) ⇒ AbstractSet
Computes the symmetric difference of two sets: the set of elements which are in either of the two sets but not in both.
99 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 99 def ^(other) symmetric_difference(other) end |
#disjoint?(other) ⇒ Boolean
True if this and the ‘other` set have no common elements
148 149 150 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 148 def disjoint?(other) intersection(other).empty? end |
#exclude?(object) ⇒ Boolean
True if the set does not include the given ‘object`
17 18 19 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 17 def exclude?(object) not include?(object) end |
#infinite? ⇒ Boolean
True if the set contains infinitely many elements
39 40 41 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 39 def infinite? not finite? end |
#proper_subset?(other) ⇒ Boolean
True if this set is a subset of the ‘other` set and there exists at least one element in the `other` set that doesn’t belong to this set
126 127 128 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 126 def proper_subset?(other) other.size > size and subset?(other) end |
#proper_superset?(other) ⇒ Boolean
True if this set is a superset of the ‘other` set and there exists at least one element in this set that doesn’t belong to the ‘other` set
141 142 143 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 141 def proper_superset?(other) other.size < size and superset?(other) end |
#replace ⇒ AbstractSet
Returns the ‘other` set, converting it to an Stupidedi::Sets::AbstractSet if it isn’t already.
36 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 36 abstract :replace, :args => %w(other) |
#size ⇒ Numeric
Returns the number of elements in the set
30 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 30 abstract :size |
#subset?(other) ⇒ Boolean
True if every element in this set also belongs to the ‘other` set
118 119 120 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 118 def subset?(other) intersection(other) == self end |
#superset?(other) ⇒ Boolean
True if every element in the ‘other` set also belongs to this set
133 134 135 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 133 def superset?(other) intersection(other) == other end |
#|(other) ⇒ AbstractSet
Computes the union of two sets: the set of elements in either or both sets
72 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 72 def |(other) union(other) end |
#~ ⇒ AbstractSet
Computes the complement of the set: the set of elements not in this set
91 |
# File 'lib/stupidedi/sets/abstract_set.rb', line 91 def ~; complement end |