File tree 2 files changed +50
-9
lines changed
2 files changed +50
-9
lines changed Original file line number Diff line number Diff line change 1
1
# CHANGE HISTORY
2
2
3
+ ## 2.1.0 / 2014-03-03
4
+
5
+ Ostatnicky has found a bug! As it turns out both #deq and #shift were
6
+ aliased incorrectly to ` push ` , when they should have been to ` pop ` .
7
+ With this release that has been fixes, but we have modified ` shift `
8
+ to instead return the lowest priority item, which is a more polymorphic
9
+ definition with its use in Array. In addition we have added ` peek ` as
10
+ an alias for ` top ` , and added ` bottom ` , which it the opposite of ` top ` .
11
+
12
+ Changes:
13
+
14
+ * Fix ` deq ` as alias of ` pop ` , not ` push ` .
15
+ * Fix ` shift ` to be like ` pop ` but opposite priority.
16
+ * Add ` peek ` as alias of ` top ` .
17
+ * Add ` bottom ` method as opposite of ` top ` .
18
+
19
+
3
20
## 2.0.2 / 2011-10-29
4
21
5
22
It's been one of those days. I went to to get a wash cloth for the shower,
Original file line number Diff line number Diff line change 18
18
class PQueue
19
19
20
20
#
21
- VERSION = "2.0 .0" #:erb: VERSION = "<%= version %>"
21
+ VERSION = "2.1 .0" #:erb: VERSION = "<%= version %>"
22
22
23
23
#
24
24
# Returns a new priority queue.
@@ -78,17 +78,17 @@ def push(v)
78
78
end
79
79
80
80
#
81
- # Alias of #push.
81
+ # Traditional alias for #push.
82
82
#
83
- alias :<< : push
83
+ alias enq push
84
84
85
85
#
86
86
# Alias of #push.
87
87
#
88
- alias enq push
88
+ alias :<< : push
89
89
90
90
#
91
- # Return the element with the highest priority and remove it from
91
+ # Get the element with the highest priority and remove it from
92
92
# the queue.
93
93
#
94
94
# The highest priority is determined by the block given at instantiation
@@ -104,14 +104,24 @@ def pop
104
104
end
105
105
106
106
#
107
- # Alias of #push .
107
+ # Traditional alias for #pop .
108
108
#
109
- alias shift push
109
+ alias deq pop
110
110
111
+ # Get the element with the lowest priority and remove it from
112
+ # the queue.
113
+ #
114
+ # The lowest priority is determined by the block given at instantiation
115
+ # time.
111
116
#
112
- # Alias of #pop.
117
+ # The deletion time is O(log n), with n is the size of the queue.
118
+ #
119
+ # Return nil if the queue is empty.
113
120
#
114
- alias deq push
121
+ def shift
122
+ return nil if empty?
123
+ @que . shift
124
+ end
115
125
116
126
#
117
127
# Returns the element with the highest priority, but
@@ -122,6 +132,20 @@ def top
122
132
return @que . last
123
133
end
124
134
135
+ #
136
+ # Traditional alias for #top.
137
+ #
138
+ alias peek top
139
+
140
+ #
141
+ # Returns the element with the lowest priority, but
142
+ # does not remove it from the queue.
143
+ #
144
+ def bottom
145
+ return nil if empty?
146
+ return @que . first
147
+ end
148
+
125
149
#
126
150
# Add more than one element at the same time. See #push.
127
151
#
You can’t perform that action at this time.
0 commit comments