Class: Stupidedi::Sets::AbstractSet

Inherits:
Object
  • Object
show all
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

AbsoluteSet, RelativeComplement, RelativeSet

Set Operations (collapse)

Set Ordering (collapse)

Instance Method Summary (collapse)

Methods included from Inspect

#inspect

Instance Method Details

- (AbstractSet) &(other)

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

- (AbstractSet) +(other)

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

- (AbstractSet) -(other)

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

- (Boolean) <(other)

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

- (Boolean) <=(other)

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

- (Boolean) >(other)

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

- (Boolean) >=(other)

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

- (AbstractSet) ^(other)

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

- (Boolean) disjoint?(other)

True if this and the other set have no common elements

Returns:

  • (Boolean)

See Also:



148
149
150
# File 'lib/stupidedi/sets/abstract_set.rb', line 148

def disjoint?(other)
  intersection(other).empty?
end

- (Boolean) exclude?(object)

True if the set does not include the given object

Returns:

  • (Boolean)


17
18
19
# File 'lib/stupidedi/sets/abstract_set.rb', line 17

def exclude?(object)
  not include?(object)
end

- (Boolean) infinite?

True if the set contains infinitely many elements

Returns:

  • (Boolean)


39
40
41
# File 'lib/stupidedi/sets/abstract_set.rb', line 39

def infinite?
  not finite?
end

- (Boolean) proper_subset?(other)

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

Returns:

  • (Boolean)

See Also:



126
127
128
# File 'lib/stupidedi/sets/abstract_set.rb', line 126

def proper_subset?(other)
  other.size > size and subset?(other)
end

- (Boolean) proper_superset?(other)

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

Returns:

  • (Boolean)

See Also:



141
142
143
# File 'lib/stupidedi/sets/abstract_set.rb', line 141

def proper_superset?(other)
  other.size < size and superset?(other)
end

- (AbstractSet) replace

Returns the other set, converting it to an Stupidedi::Sets::AbstractSet if it isn't already.

Returns:



36
# File 'lib/stupidedi/sets/abstract_set.rb', line 36

abstract :replace, :args => %w(other)

- (Numeric) size

Returns the number of elements in the set

Returns:

  • (Numeric)


30
# File 'lib/stupidedi/sets/abstract_set.rb', line 30

abstract :size

- (Boolean) subset?(other)

True if every element in this set also belongs to the other set

Returns:

  • (Boolean)

See Also:



118
119
120
# File 'lib/stupidedi/sets/abstract_set.rb', line 118

def subset?(other)
  intersection(other) == self
end

- (Boolean) superset?(other)

True if every element in the other set also belongs to this set

Returns:

  • (Boolean)

See Also:



133
134
135
# File 'lib/stupidedi/sets/abstract_set.rb', line 133

def superset?(other)
  intersection(other) == other
end

- (AbstractSet) |(other)

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