Skip to content

Commit 053b729

Browse files
author
Gianmarco Garrisi
committed
Fix #6 for change_priority and change_priority_by. Publishing new version of crate
1 parent 96c91be commit 053b729

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "priority-queue"
3-
version = "0.4.4"
3+
version = "0.4.5"
44
authors = ["Gianmarco Garrisi <gianmarcogarrisi@tutanota.com>"]
55
description = "A Priority Queue implemented as a heap with a function to efficiently change the priority of an item."
66
repository = "https://github.com/garro95/priority-queue"

README.rst

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Feel free to contribute to this project with pull requests and/or issues. All co
6565
Changes
6666
-------
6767

68+
* 0.4.5 Fix #6 for `change_priority` and `change_priority_by`
6869
* 0.4.4 Fix #6
6970
* 0.4.3 Fix #4 changing the way PriorityQueue serializes.
7071
Note that old serialized PriorityQueues may be incompatible with the new version.

src/lib.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,14 @@ mod tests {
121121
let mut pq = PriorityQueue::new();
122122
pq.push("Processor", 1);
123123
pq.push("Mainboard", 2);
124-
pq.push("Ram", 5);
124+
pq.push("RAM", 5);
125+
pq.push("GPU", 4);
126+
pq.push("Disk", 3);
125127
pq.change_priority("Processor", 10);
126128
assert_eq!(pq.peek(), Some((&"Processor", &10)));
127129

128-
pq.change_priority("Ram", 11);
129-
assert_eq!(pq.peek(), Some((&"Ram", &11)));
130+
pq.change_priority("RAM", 11);
131+
assert_eq!(pq.peek(), Some((&"RAM", &11)));
130132
}
131133

132134
#[test]
@@ -166,11 +168,11 @@ mod tests {
166168
fn change_priority_by() {
167169
use std::iter::FromIterator;
168170

169-
let v = vec!(("a", 1), ("b", 2), ("f", 7));
171+
let v = vec!(("a", 1), ("b", 2), ("f", 7), ("g", 6), ("h", 5));
170172
let mut pq = PriorityQueue::from_iter(v.into_iter());
171173

172174
pq.change_priority_by("b", |b| b+8);
173-
assert_eq!(pq.into_sorted_vec().as_slice(), &["b", "f", "a"]);
175+
assert_eq!(pq.into_sorted_vec().as_slice(), &["b", "f", "g", "h", "a"]);
174176
}
175177

176178
#[test]

src/pqueue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<I, P> PriorityQueue<I, P>
249249
let tmp = *self.heap.get_unchecked(pos);
250250
while (pos > 0) &&
251251
(self.map.get_index(*self.heap.get_unchecked(parent(pos))).unwrap().1 <
252-
self.map.get_index(*self.heap.get_unchecked(pos)).unwrap().1)
252+
self.map.get_index(tmp).unwrap().1)
253253
{
254254
*self.heap.get_unchecked_mut(pos) = *self.heap.get_unchecked(parent(pos));
255255
*self.qp.get_unchecked_mut(*self.heap.get_unchecked(pos)) = pos;
@@ -285,7 +285,7 @@ impl<I, P> PriorityQueue<I, P>
285285
let tmp = *self.heap.get_unchecked(pos);
286286
while (pos > 0) &&
287287
(self.map.get_index(*self.heap.get_unchecked(parent(pos))).unwrap().1 <
288-
self.map.get_index(*self.heap.get_unchecked(pos)).unwrap().1)
288+
self.map.get_index(tmp).unwrap().1)
289289
{
290290
*self.heap.get_unchecked_mut(pos) = *self.heap.get_unchecked(parent(pos));
291291
*self.qp.get_unchecked_mut(*self.heap.get_unchecked(pos)) = pos;

0 commit comments

Comments
 (0)