Class: Cantor::AbstractSet
- Inherits:
-
Object
- Object
- Cantor::AbstractSet
- Defined in:
- lib/cantor/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
- #contain?(object) ⇒ Boolean
-
#exclude?(object) ⇒ Boolean
True if the set does not include the given ‘object`.
-
#infinite? ⇒ Boolean
True if the set contains infinitely many elements.
-
#member?(object) ⇒ Boolean
True if the set includes the given ‘object` abstract :include?, :args => %w(object).
-
#present? ⇒ Boolean
False if #size ‘== 0` abstract :empty?.
Instance Method Details
#&(other) ⇒ AbstractSet
Computes the intersection of two sets: the set of elements common between both sets.
114 |
# File 'lib/cantor/abstract_set.rb', line 114 def &(other) intersection(other) end |
#+(other) ⇒ AbstractSet
Computes the union of two sets: the set of elements in either or both sets
82 |
# File 'lib/cantor/abstract_set.rb', line 82 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.
90 |
# File 'lib/cantor/abstract_set.rb', line 90 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
165 |
# File 'lib/cantor/abstract_set.rb', line 165 def <(other) proper_subset?(other) end |
#<=(other) ⇒ Object
True if every element in this set also belongs to the ‘other` set
171 |
# File 'lib/cantor/abstract_set.rb', line 171 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
168 |
# File 'lib/cantor/abstract_set.rb', line 168 def >(other) proper_superset?(other) end |
#>=(other) ⇒ Object
True if every element in the ‘other` set also belongs to this set
174 |
# File 'lib/cantor/abstract_set.rb', line 174 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.
106 |
# File 'lib/cantor/abstract_set.rb', line 106 def ^(other) symmetric_difference(other) end |
#contain?(object) ⇒ Boolean
18 19 20 |
# File 'lib/cantor/abstract_set.rb', line 18 def contain?(object) include?(object) end |
#disjoint?(other) ⇒ Boolean
True if this and the ‘other` set have no common elements
155 156 157 |
# File 'lib/cantor/abstract_set.rb', line 155 def disjoint?(other) intersection(other).empty? end |
#exclude?(object) ⇒ Boolean
True if the set does not include the given ‘object`
23 24 25 |
# File 'lib/cantor/abstract_set.rb', line 23 def exclude?(object) not include?(object) end |
#infinite? ⇒ Boolean
True if the set contains infinitely many elements
51 52 53 |
# File 'lib/cantor/abstract_set.rb', line 51 def infinite? not finite? end |
#member?(object) ⇒ Boolean
True if the set includes the given ‘object` abstract :include?, :args => %w(object)
14 15 16 |
# File 'lib/cantor/abstract_set.rb', line 14 def member?(object) include?(object) end |
#present? ⇒ Boolean
False if #size ‘== 0` abstract :empty?
35 36 37 |
# File 'lib/cantor/abstract_set.rb', line 35 def present? not empty? 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
133 134 135 |
# File 'lib/cantor/abstract_set.rb', line 133 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
148 149 150 |
# File 'lib/cantor/abstract_set.rb', line 148 def proper_superset?(other) other.size < size and superset?(other) end |
#subset?(other) ⇒ Boolean
True if every element in this set also belongs to the ‘other` set
125 126 127 |
# File 'lib/cantor/abstract_set.rb', line 125 def subset?(other) intersection(other) == self end |
#superset?(other) ⇒ Boolean
True if every element in the ‘other` set also belongs to this set
140 141 142 |
# File 'lib/cantor/abstract_set.rb', line 140 def superset?(other) intersection(other) == other end |
#|(other) ⇒ AbstractSet
Computes the union of two sets: the set of elements in either or both sets
79 |
# File 'lib/cantor/abstract_set.rb', line 79 def |(other) union(other) end |
#~ ⇒ AbstractSet
Computes the complement of the set: the set of elements not in this set
98 |
# File 'lib/cantor/abstract_set.rb', line 98 def ~; complement end |