class Bud::BagLattice
XXX: Should this be just syntax sugar for a map lattice instead?
Public Class Methods
new(i={})
click to toggle source
# File lib/bud/lattice-lib.rb, line 371 def initialize(i={}) reject_input(i) unless i.class <= Hash i.each do |k, mult| reject_input(i) if k.class <= Bud::Lattice reject_input(i) unless (mult.class <= Integer && mult > 0) end @v = i end
Public Instance Methods
merge(i)
click to toggle source
Note that for merge to be idempotent, we need to use the traditional definition of multiset union (per-element max of multiplicities, rather than sum of multiplicities).
# File lib/bud/lattice-lib.rb, line 383 def merge(i) rv = @v.merge(i.reveal) do |k, lhs_v, rhs_v| [lhs_v, rhs_v].max end wrap_unsafe(rv) end