lib/bmg/operator/constants.rb in bmg-0.19.3 vs lib/bmg/operator/constants.rb in bmg-0.20.0
- old
+ new
@@ -8,19 +8,19 @@
# statically known.
#
class Constants
include Operator::Unary
- def initialize(type, operand, constants)
+ def initialize(type, operand, the_constants)
@type = type
@operand = operand
- @constants = constants
+ @the_constants = the_constants
end
protected
- attr_reader :constants
+ attr_reader :the_constants
public
def each
return to_enum unless block_given?
@@ -30,31 +30,31 @@
end
def insert(arg)
case arg
when Hash then operand.insert(allbut_constants(arg))
- when Relation then operand.insert(arg.allbut(constants.keys))
+ when Relation then operand.insert(arg.allbut(the_constants.keys))
when Enumerable then operand.insert(arg.map{|t| allbut_constants(t) })
else
super
end
end
- def update(tuple)
- shared = tuple.keys & constants.keys
+ def update(tuple, predicate = Predicate.tautology)
+ shared = tuple.keys & the_constants.keys
on_tuple = TupleAlgebra.project(tuple, shared)
- on_const = TupleAlgebra.project(constants, shared)
+ on_const = TupleAlgebra.project(the_constants, shared)
raise InvalidUpdateError, "Cannot violate relvar predicate" unless on_tuple == on_const
- operand.update(allbut_constants(tuple))
+ operand.update(allbut_constants(tuple), predicate)
end
- def delete
- operand.delete
+ def delete(predicate = Predicate.tautology)
+ operand.delete(predicate)
end
def to_ast
- [ :constants, operand.to_ast, constants.dup ]
+ [ :constants, operand.to_ast, the_constants.dup ]
end
public ### for internal reasons
def _count
@@ -63,36 +63,36 @@
protected ### optimization
def _page(type, ordering, page_index, options)
attrs = ordering.map{|(k,v)| k}
- cs_attrs = constants.keys
+ cs_attrs = the_constants.keys
if (attrs & cs_attrs).empty?
operand
.page(ordering, page_index, options)
- .constants(constants)
+ .constants(the_constants)
else
super
end
end
def _restrict(type, predicate)
- # bottom_p makes no reference to constants, top_p possibly
+ # bottom_p makes no reference to the_constants, top_p possibly
# does...
- top_p, bottom_p = predicate.and_split(constants.keys)
+ top_p, bottom_p = predicate.and_split(the_constants.keys)
if top_p.tautology?
- # push all situation: predicate made no reference to constants
+ # push all situation: predicate made no reference to the_constants
result = operand
result = result.restrict(bottom_p)
- result = result.constants(constants)
+ result = result.constants(the_constants)
result
- elsif (top_p.free_variables - constants.keys).empty?
- # top_p applies to constants only
- if eval = top_p.evaluate(constants)
+ elsif (top_p.free_variables - the_constants.keys).empty?
+ # top_p applies to the_constants only
+ if eval = top_p.evaluate(the_constants)
result = operand
result = result.restrict(bottom_p)
- result = result.constants(constants)
+ result = result.constants(the_constants)
result
else
Relation.empty(type)
end
elsif bottom_p.tautology?
@@ -102,31 +102,31 @@
else
# top_p and bottom_p are complex predicates. Let apply each
# of them
result = operand
result = result.restrict(bottom_p)
- result = result.constants(constants)
+ result = result.constants(the_constants)
result = result.restrict(top_p)
result
end
rescue Predicate::NotSupportedError
super
end
protected ### inspect
def args
- [ constants ]
+ [ the_constants ]
end
private
def extend_it(tuple)
- tuple.merge(@constants)
+ tuple.merge(@the_constants)
end
def allbut_constants(tuple)
- TupleAlgebra.allbut(tuple, constants.keys)
+ TupleAlgebra.allbut(tuple, the_constants.keys)
end
end # class Constants
end # module Operator
end # module Bmg