[libgee/0.6] 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/0.6] Fix adding second element to priority queue, fixes bug #647162
- Date: Fri, 8 Apr 2011 13:41:24 +0000 (UTC)
commit 1821ee977015cef8f7f111854e6a8a9447898f01
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 74337a0..6a6f8bf 100644
--- a/gee/priorityqueue.vala
+++ b/gee/priorityqueue.vala
@@ -107,6 +107,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 9c82ab2..cbeac2f 100644
--- a/tests/testpriorityqueue.vala
+++ b/tests/testpriorityqueue.vala
@@ -114,5 +114,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]