Class: Bmg::Operator::Matching
- Inherits:
-
Object
- Object
- Bmg::Operator::Matching
- Includes:
- Binary
- Defined in:
- lib/bmg/operator/matching.rb
Overview
Matching operator.
Filters tuples of left operand to those matching at least one tuple in right operand.
Instance Attribute Summary
Attributes included from Bmg::Operator
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(type, left, right, on) ⇒ Matching
constructor
A new instance of Matching.
- #to_ast ⇒ Object
Methods included from Binary
Methods included from Bmg::Operator
Methods included from Relation
#_count, #bind, #count, #debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_csv, #to_json, #to_xlsx, #type, #update, #visit, #with_type, #with_type_attrlist, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #minus, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap
Methods included from Algebra::Shortcuts
#cross_product, #exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where
Constructor Details
#initialize(type, left, right, on) ⇒ Matching
Returns a new instance of Matching.
12 13 14 15 16 17 |
# File 'lib/bmg/operator/matching.rb', line 12 def initialize(type, left, right, on) @type = type @left = left @right = right @on = on end |
Instance Method Details
#each ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bmg/operator/matching.rb', line 25 def each return to_enum unless block_given? index = Hash.new right.each_with_object(index) do |t, index| key = tuple_project(t, on) index[key] = true end left.each do |tuple| key = tuple_project(tuple, on) yield tuple if index.has_key?(key) end end |
#to_ast ⇒ Object
38 39 40 |
# File 'lib/bmg/operator/matching.rb', line 38 def to_ast [ :matching, left.to_ast, right.to_ast, on ] end |