Class: Axiom::Relation::Index
- Inherits:
-
Object
- Object
- Axiom::Relation::Index
- Defined in:
- lib/axiom/relation/index.rb
Overview
Tuples keyed by a tuple
Instance Method Summary collapse
-
#<<(tuple) ⇒ Index
Add a tuple to the index.
-
#[](tuple) ⇒ Set<Tuple>
Return the tuples in the index based on the tuple key.
-
#each {|key, tuples| ... } ⇒ Index
Iterate over each entry in the index.
-
#initialize(key, header) ⇒ undefined
constructor
private
Initialize an index.
-
#merge(tuples) ⇒ Index
Add a set of tuples to the index.
Constructor Details
#initialize(key, header) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize an index
17 18 19 20 21 |
# 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 |
Instance Method Details
#<<(tuple) ⇒ Index
Add a tuple to the index
48 49 50 51 |
# File 'lib/axiom/relation/index.rb', line 48 def <<(tuple) self[tuple] << tuple.project(@header) self end |
#[](tuple) ⇒ Set<Tuple>
Return the tuples in the index based on the tuple key
85 86 87 |
# File 'lib/axiom/relation/index.rb', line 85 def [](tuple) @index[tuple.project(@key)] end |
#each {|key, tuples| ... } ⇒ Index
Iterate over each entry in the index
69 70 71 72 73 |
# File 'lib/axiom/relation/index.rb', line 69 def each(&block) return to_enum unless block_given? @index.each(&block) self end |
#merge(tuples) ⇒ Index
Add a set of tuples to the index
33 34 35 36 |
# File 'lib/axiom/relation/index.rb', line 33 def merge(tuples) tuples.each(&method(:<<)) self end |