[libgee] Fix adding second element to priority queue, fixes bug #647162
- From: Maciej Marcin Piechotka <mpiechotka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgee] Fix adding second element to priority queue, fixes bug #647162
- Date: Fri, 8 Apr 2011 13:41:29 +0000 (UTC)
commit 5dfb5ee87a27f866910dc1081a956498e5239418
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date: Fri Apr 8 15:24:27 2011 +0200
Fix adding second element to priority queue, fixes bug #647162
gee/priorityqueue.vala | 2 ++
tests/testpriorityqueue.vala | 10 ++++++++++
2 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/gee/priorityqueue.vala b/gee/priorityqueue.vala
index fd45aac..0b6a93e 100644
--- a/gee/priorityqueue.vala
+++ b/gee/priorityqueue.vala
@@ -114,6 +114,8 @@ public class Gee.PriorityQueue<G> : Gee.AbstractQueue<G> {
_r_prime = new Type2Node<G> (element);
_r_prime.parent = _r;
_r.type2_child = _r_prime;
+ if (_compare (_r_prime, _r) < 0)
+ _swap_data (_r_prime, _r);
} else {
// Form a tree with a single node N of type I consisting of element e
Type1Node<G> node = new Type1Node<G> (element);
diff --git a/tests/testpriorityqueue.vala b/tests/testpriorityqueue.vala
index 9274dd8..676a814 100644
--- a/tests/testpriorityqueue.vala
+++ b/tests/testpriorityqueue.vala
@@ -89,5 +89,15 @@ public class PriorityQueueTests : QueueTests {
assert (test_queue.poll () == "twelve");
assert (test_queue.peek () == "two");
assert (test_queue.poll () == "two");
+
+ // Add decreasing elements
+ assert (test_queue.offer ("2"));
+ assert (test_queue.offer ("1"));
+
+
+ assert (test_queue.peek () == "1");
+ assert (test_queue.poll () == "1");
+ assert (test_queue.peek () == "2");
+ assert (test_queue.poll () == "2");
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]