Class: Alf::Engine::Semi::Hash

Inherits:
Object
  • Object
show all
Includes:
Cog, Alf::Engine::Semi
Defined in:
lib/alf/engine/semi/hash.rb

Overview

Filters tuples from left that match or do not match tuples from right.

Constant Summary

Constants included from Cog

Cog::EMPTY_CHILDREN, Cog::EMPTY_OPTIONS

Instance Attribute Summary collapse

Attributes included from Compiler::Cog

#compiler, #expr

Instance Method Summary collapse

Methods included from Cog

#children, #each, #options, #to_s

Methods included from Compiler::Cog

#cog_orders, #orderedby?, #relation_type, #to_ascii_tree, #to_cog, #to_relation

Constructor Details

#initialize(left, right, predicate, expr = nil, compiler = nil) ⇒ Hash

Creates a Semi::Hash instance



20
21
22
23
24
25
# File 'lib/alf/engine/semi/hash.rb', line 20

def initialize(left, right, predicate, expr = nil, compiler = nil)
  super(expr, compiler)
  @left = left
  @right = right
  @predicate = predicate
end

Instance Attribute Details

#leftEnumerable (readonly)

Returns The left operand.

Returns:

  • (Enumerable)

    The left operand



11
12
13
# File 'lib/alf/engine/semi/hash.rb', line 11

def left
  @left
end

#predicateBoolean (readonly)

Returns Match (true) or not match (false)?.

Returns:

  • (Boolean)

    Match (true) or not match (false)?



17
18
19
# File 'lib/alf/engine/semi/hash.rb', line 17

def predicate
  @predicate
end

#rightEnumerable (readonly)

Returns The right operand.

Returns:

  • (Enumerable)

    The right operand



14
15
16
# File 'lib/alf/engine/semi/hash.rb', line 14

def right
  @right
end

Instance Method Details

#_eachObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/alf/engine/semi/hash.rb', line 33

def _each
  index = nil
  left.each do |left_tuple|
    index ||= Materialize::Hash.new(right, lambda{|t|
      AttrList.new(left_tuple.keys & t.keys)
    }, false).prepare
    if index[left_tuple, true].empty? != predicate
      yield left_tuple 
    end
  end
end

#argumentsObject



45
46
47
# File 'lib/alf/engine/semi/hash.rb', line 45

def arguments
  [ predicate ]
end

#operandsObject

Returns left and right operands in an array



28
29
30
# File 'lib/alf/engine/semi/hash.rb', line 28

def operands
  [ left, right ]
end