class SkewHeapMap
A dynamic priority queue based on key/value pair mappings. Values are stored in an Element
, ordered by their associated keys. The inherited peek
and pop
methods return an Element
(see Defined Under Namespace below), whose key and value can be accessed via elt.key
and elt.value
, respectively.
- Author
-
Paul J Sanchez (pjs@alum.mit.edu)
- Copyright
-
Copyright © Paul J Sanchez
- License
-
LGPL
Constants
- Element
An
Element
provides storage and access for the key/value pairs.
Public Class Methods
Construct and initialize a new SkewHeapMap
. If provided, the key and value arrays must be synchronized, i.e., the first element of value_ary
is the value associated with the first element of key_ary
. If a comparator block is provided it will be used to determine order for the keys, otherwise the default comparator will be used for keys.
- Arguments
-
key_ary
-> an optional array of keys to add to the new skew heap. -
value_ary
-> an optional array of values to add to the new skew heap.
-
SkewHeap::new
# File lib/skewheapmap.rb, line 29 def initialize(key_ary=[], value_ary=[], &block) if block super() {|x,y| block[x.key, y.key]} else super() {|x,y| x.key <=> y.key} end key_ary.each_index {|i| push(key_ary[i], value_ary[i])} unless (key_ary.empty? || key_ary.size != value_ary.size) end
Public Instance Methods
Add the provided value to the skewheap, ordered by the key value.
SkewHeap#push
# File lib/skewheapmap.rb, line 40 def push(key, value) super(Element.new(key, value)) unless key.nil? end