Skip to content

Instantly share code, notes, and snippets.

@dgraham
Created October 4, 2011 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgraham/1260596 to your computer and use it in GitHub Desktop.
Save dgraham/1260596 to your computer and use it in GitHub Desktop.
EM::PriorityQueue using RBTree
module EventMachine
class PriorityQueue < Queue
def initialize(&comparator)
super
@items = Items.new(comparator)
end
class Items
def initialize(comparator)
require 'rbtree'
@items = MultiRBTree.new
@items.readjust(comparator)
end
def push(*args)
args.each do |obj|
@items[obj] = nil
end
end
def shift
value = @items.shift
value ? value[0] : nil
end
def method_missing(name, *args, &block)
@items.send(name, *args, &block)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment