Class: PoorPriorityQueue
- Inherits:
-
Hash
show all
- Defined in:
- lib/amp/dependencies/priority_queue/poor_priority_queue.rb
Overview
A Poor mans Priority Queue. (Very inefficent but minimal implemention).
Instance Method Summary
collapse
Methods inherited from Hash
#[], #get, #pick, with_keys
Instance Method Details
#delete(object) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/amp/dependencies/priority_queue/poor_priority_queue.rb', line 40
def delete(object)
return nil unless self.has_key?(object)
result = [object, self[object]]
super
result
end
|
#delete_min ⇒ Object
25
26
27
28
29
30
|
# File 'lib/amp/dependencies/priority_queue/poor_priority_queue.rb', line 25
def delete_min
return nil if self.empty?
min_k, min_p = *min
self.delete(min_k)
[min_k, min_p]
end
|
#delete_min_return_key ⇒ Object
32
33
34
|
# File 'lib/amp/dependencies/priority_queue/poor_priority_queue.rb', line 32
def delete_min_return_key
delete_min[0] rescue nil
end
|
#delete_min_return_priority ⇒ Object
36
37
38
|
# File 'lib/amp/dependencies/priority_queue/poor_priority_queue.rb', line 36
def delete_min_return_priority
delete_min[1] rescue nil
end
|
7
8
9
10
11
12
13
14
15
|
# File 'lib/amp/dependencies/priority_queue/poor_priority_queue.rb', line 7
def min
return nil if self.empty?
min_k = self.keys.first
min_p = self[min_k]
self.each do | k, p |
min_k, min_p = k, p if p < min_p
end
[min_k, min_p]
end
|
17
18
19
|
# File 'lib/amp/dependencies/priority_queue/poor_priority_queue.rb', line 17
def min_key
min[0] rescue nil
end
|
#min_priority ⇒ Object
21
22
23
|
# File 'lib/amp/dependencies/priority_queue/poor_priority_queue.rb', line 21
def min_priority
min[1] rescue nil
end
|
#push(object, priority) ⇒ Object
3
4
5
|
# File 'lib/amp/dependencies/priority_queue/poor_priority_queue.rb', line 3
def push(object, priority)
self[object] = priority
end
|