class TypeProf::Utils::WorkList

Public Class Methods

new() click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 144
def initialize
  @heap = []
  @set = MutableSet.new
end

Public Instance Methods

deletemin() click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 163
def deletemin
  return nil if @heap.empty?
  val = @heap[0][1]
  @set.delete(val)
  if @heap.size == 1
    @heap.pop
    return val
  end
  @heap[0] = @heap.pop
  i = 0
  while (j = i * 2 + 1) < @heap.size
    j += 1 if j + 1 < @heap.size && (@heap[j][0] <=> @heap[j + 1][0]) >= 0
    break if (@heap[i][0] <=> @heap[j][0]) < 0
    @heap[i], @heap[j] = @heap[j], @heap[i]
    i = j
  end
  return val
end
empty?() click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 186
def empty?
  @heap.empty?
end
insert(key, val) click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 149
def insert(key, val)
  i = @heap.size
  @heap << [key, val]
  while i > 0 && (@heap[i][0] <=> @heap[i / 2][0]) < 0
    @heap[i], @heap[i / 2] = @heap[i / 2], @heap[i]
    i /= 2
  end
  @set << val
end
inspect() click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 190
def inspect
  "#<#{ self.class }:#{ @heap.map {|_key, val| val }.inspect }>"
end
member?(val) click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 159
def member?(val)
  @set[val]
end
size() click to toggle source
# File typeprof-0.15.2/lib/typeprof/utils.rb, line 182
def size
  @heap.size
end