Class: Axiom::Algebra::Union

Inherits:
Relation show all
Includes:
Relation::Operation::Set
Defined in:
lib/axiom/algebra/union.rb

Overview

The union between relations

Defined Under Namespace

Modules: Methods

Instance Attribute Summary

Attributes included from Operation::Binary

#left, #right

Attributes inherited from Relation

#header

Instance Method Summary collapse

Methods included from Relation::Operation::Set

#initialize

Methods included from Relation::Operation::Binary

#initialize

Methods included from Operation::Binary

#initialize

Methods inherited from Relation

#==, #[], #directions, #empty?, #include?, #initialize, #materialize, #materialized?, new, #replace

Methods included from Visitable

#accept

Instance Method Details

#delete(other) ⇒ Union

Delete a relation from the Union

Examples:

new_relation = union.delete(other)

Parameters:

Returns:



56
57
58
# File 'lib/axiom/algebra/union.rb', line 56

def delete(other)
  left.delete(other).union(right.delete(other))
end

#each {|tuple| ... } ⇒ self

Iterate over each tuple in the set

Examples:

union = Union.new(left, right)
union.each { |tuple| ... }

Yields:

  • (tuple)

Yield Parameters:

  • tuple (Tuple)

    each tuple in the set

Returns:

  • (self)


24
25
26
27
28
29
30
# File 'lib/axiom/algebra/union.rb', line 24

def each
  return to_enum unless block_given?
  seen = {}
  left.each  { |tuple| yield seen[tuple] = tuple           }
  right.each { |tuple| yield tuple unless seen.key?(tuple) }
  self
end

#insert(other) ⇒ Union

Insert a relation into the Union

Examples:

new_relation = union.insert(other)

Parameters:

Returns:



42
43
44
# File 'lib/axiom/algebra/union.rb', line 42

def insert(other)
  left.insert(other).union(right.insert(other))
end