class Bud::SetLattice
A set lattice contains zero or more primitive (non-lattice) values.
Public Class Methods
new(i=Set.new)
click to toggle source
# File lib/bud/lattice-lib.rb, line 226 def initialize(i=Set.new) reject_input(i) unless i.kind_of? Enumerable reject_input(i) if i.any? {|e| e.kind_of? Bud::Lattice} i = Set.new(i) unless i.kind_of? Set @v = i end
Public Instance Methods
inspect()
click to toggle source
Override default “inspect” implementation to produce slightly nicer output
# File lib/bud/lattice-lib.rb, line 239 def inspect "<#{self.class.wrapper}: #{reveal.to_a.sort.inspect}>" end
merge(i)
click to toggle source
# File lib/bud/lattice-lib.rb, line 234 def merge(i) wrap_unsafe(@v | i.reveal) end
probe(val, preds)
click to toggle source
Assuming that this set contains Structs, this method takes a value “val” and a hash of predicates “preds”. It returns all the structs t where val = t for all k,v in preds; an empty array is returned if no matches found.
# File lib/bud/lattice-lib.rb, line 314 def probe(val, preds) return @v if preds.empty? probe_val = schema_fetch(val, preds.keys) build_index(preds.values) index = @join_indexes[preds.values] return index[probe_val] || [] end
Private Instance Methods
build_index(cols)
click to toggle source
# File lib/bud/lattice-lib.rb, line 328 def build_index(cols) @join_indexes ||= {} return @join_indexes[cols] if @join_indexes.has_key? cols idx = {} @v.each do |val| index_val = schema_fetch(val, cols) idx[index_val] ||= [] idx[index_val] << val end @join_indexes[cols] = idx return idx end
schema_fetch(val, cols)
click to toggle source
# File lib/bud/lattice-lib.rb, line 324 def schema_fetch(val, cols) cols.map {|s| val[s]} end