Class: Axiom::Relation::Materialized

Inherits:
Axiom::Relation show all
Defined in:
lib/axiom/relation/materialized.rb

Overview

A materialized relation

Direct Known Subclasses

Empty

Constant Summary collapse

ZERO_TUPLE =
EMPTY_ARRAY

Instance Attribute Summary collapse

Attributes inherited from Axiom::Relation

#header

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Axiom::Relation

#==, #[], #each, #empty?, #include?, #replace

Methods included from Visitable

#accept

Constructor Details

#initialize(header, tuples, directions = Operation::Sorted::DirectionSet::EMPTY) ⇒ 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 a materialized Relation



73
74
75
76
# File 'lib/axiom/relation/materialized.rb', line 73

def initialize(header, tuples, directions = Operation::Sorted::DirectionSet::EMPTY)
  super(header, tuples)
  @directions = Operation::Sorted::DirectionSet.coerce(directions)
end

Instance Attribute Details

#directionsOperation::Sorted::DirectionSet (readonly)

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.

The relation sort order



15
16
17
# File 'lib/axiom/relation/materialized.rb', line 15

def directions
  @directions
end

Class Method Details

.new(*args) ⇒ Relation

Instantiate a materialized Relation

Examples:

of a materialized Array based relation

array    = [[1], [2], [3]]
relation = Relation::Materialized.new([[:id, Integer]], array)

of a materialized Set based relation

set      = Set[[1], [2], [3]]
relation = Relation::Materialized.new([[:id, Integer]], set)

of a materialized empty relation

relation = Relation::Materialized.new([[:id, Integer]])


35
36
37
38
39
40
41
# File 'lib/axiom/relation/materialized.rb', line 35

def self.new(*args)
  if equal?(Materialized) && empty?(args[1])
    Empty.new(args.first)
  else
    super
  end
end

Instance Method Details

#materializeself

A noop for Materialized relations

Examples:

materialized.materialize  # (Always returns self)


86
87
88
# File 'lib/axiom/relation/materialized.rb', line 86

def materialize
  self
end

#materialized?true

Return true for a Materialized relation

Examples:

relation.materialized?  # => true


98
99
100
# File 'lib/axiom/relation/materialized.rb', line 98

def materialized?
  true
end

#sizeInteger

Return the number of tuples

Examples:

materialized.size  # => 10


110
111
112
# File 'lib/axiom/relation/materialized.rb', line 110

def size
  tuples.size
end