class TypeProf::Utils::Set

Attributes

tbl[R]

Public Class Methods

[](*values) click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 23
def self.[](*values)
  tbl = {}
  values.each do |v|
    tbl[v] = true
  end
  new(tbl)
end
new(tbl) click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 31
def initialize(tbl)
  @tbl = tbl
  @tbl.freeze
end

Public Instance Methods

add(new_val) click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 52
def add(new_val)
  tbl = @tbl.dup
  tbl[new_val] = true
  Set.new(tbl)
end
each(&blk) click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 36
def each(&blk)
  @tbl.each_key(&blk)
end
include?(elem) click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 77
def include?(elem)
  @tbl[elem]
end
inspect() click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 71
def inspect
  s = []
  each {|v| s << v.inspect }
  "{#{ s.join(", ") }}"
end
intersection(other) click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 81
def intersection(other)
  tbl = {}
  h = 0
  each do |elem|
    if other.include?(elem)
      tbl << elem
      h ^= elem.hash
    end
  end
  Set.new(tbl, h)
end
map() { |elem| ... } click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 62
def map(&blk)
  tbl = {}
  each do |elem|
    v = yield(elem)
    tbl[v] = true
  end
  Set.new(tbl)
end
size() click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 58
def size
  @tbl.size
end
sum(other) click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 42
def sum(other)
  if @tbl.size == 0
    other
  elsif other.tbl.size == 0
    self
  else
    Set.new(@tbl.merge(other.tbl))
  end
end