class Axiom::Relation::Index
Tuples keyed by a tuple
Public Class Methods
new(key, header)
click to toggle source
Initialize an index
@param [Header] key @param [Header] header
@return [undefined]
@api private
# File lib/axiom/relation/index.rb, line 17 def initialize(key, header) @key = key @header = header @index = Hash.new { |hash, tuple| hash[tuple] = Set.new } end
Public Instance Methods
<<(tuple)
click to toggle source
Add a tuple to the index
@example
index << tuple
@param [Tuple]
@return [Index]
@api public
# File lib/axiom/relation/index.rb, line 48 def <<(tuple) self[tuple] << tuple.project(@header) self end
[](tuple)
click to toggle source
Return the tuples in the index based on the tuple key
@example
index[tuple] # => tuples
@param [Tuple] tuple
@return [Set<Tuple>]
@api public
# File lib/axiom/relation/index.rb, line 85 def [](tuple) @index[tuple.project(@key)] end
each(&block)
click to toggle source
Iterate over each entry in the index
@example
index = Index.new(key_header, tuple_header) index.each { |key, tuples| ... }
@yield [key, tuples]
@yieldparam [Tuple] key
the key for the tuples
@yieldparam [Set<Tuple>] tuples
the indexed tuples
@return [Index]
@api public
# File lib/axiom/relation/index.rb, line 69 def each(&block) return to_enum unless block_given? @index.each(&block) self end
merge(tuples)
click to toggle source
Add a set of tuples to the index
@example
index.merge(tuples)
@param [Enumerable<Tuple>] tuples
@return [Index]
@api public
# File lib/axiom/relation/index.rb, line 33 def merge(tuples) tuples.each(&method(:<<)) self end