Class: Bud::SetLattice

Inherits:
Lattice show all
Defined in:
lib/bud/lattice-lib.rb

Overview

A set lattice contains zero or more primitive (non-lattice) values.

Direct Known Subclasses

PositiveSetLattice

Instance Method Summary (collapse)

Methods inherited from Lattice

#<=>, #==, #eql?, global_mfuncs, global_morphs, #hash, lattice_kinds, mfuncs, monotone, morph, morphs, #reject_input, #reveal, #wrap_unsafe, wrapper, wrapper_name

Constructor Details

- (SetLattice) initialize(i = Set.new)



226
227
228
229
230
231
232
# 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

Instance Method Details

- (Object) inspect

Override default “inspect” implementation to produce slightly nicer output



239
240
241
# File 'lib/bud/lattice-lib.rb', line 239

def inspect
  "<#{self.class.wrapper}: #{reveal.to_a.sort.inspect}>"
end

- (Object) merge(i)



234
235
236
# File 'lib/bud/lattice-lib.rb', line 234

def merge(i)
  wrap_unsafe(@v | i.reveal)
end

- (Object) probe(val, preds)

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.



294
295
296
297
298
299
300
301
# File 'lib/bud/lattice-lib.rb', line 294

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