lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [2/5] lucenenet git commit: Added ToArray method to the PQ. Added more tests to check resizing.
Date Sun, 01 Mar 2015 19:41:05 GMT
Added ToArray method to the PQ. Added more tests to check resizing.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/bf98bcab
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/bf98bcab
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/bf98bcab

Branch: refs/heads/master
Commit: bf98bcabf991085f6cf35a62db12011e403769d1
Parents: abce0d5
Author: Guido Tagliavini Ponce <t-gupon@microsoft.com>
Authored: Wed Feb 18 12:01:33 2015 -0800
Committer: Guido Tagliavini Ponce <t-gupon@microsoft.com>
Committed: Wed Feb 18 12:01:33 2015 -0800

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/PriorityQueue.cs       |  7 +++++
 .../core/Util/TestPriorityQueue.cs              | 29 ++++++++++++++++++++
 2 files changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bf98bcab/src/Lucene.Net.Core/Util/PriorityQueue.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/PriorityQueue.cs b/src/Lucene.Net.Core/Util/PriorityQueue.cs
index 9b76121..296cac6 100644
--- a/src/Lucene.Net.Core/Util/PriorityQueue.cs
+++ b/src/Lucene.Net.Core/Util/PriorityQueue.cs
@@ -282,6 +282,13 @@ namespace Lucene.Net.Util
             QueueSize = 0;
         }
 
+        public T[] ToArray()
+        {
+            T[] copy = new T[QueueSize];
+            Array.Copy(Heap, 1, copy, 0, QueueSize);
+            return copy;
+        }
+
         private void Resize()
         {
             int newSize = Math.Min(ArrayUtil.MAX_ARRAY_LENGTH - 1, 2*MaxSize);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bf98bcab/src/Lucene.Net.Tests/core/Util/TestPriorityQueue.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestPriorityQueue.cs b/src/Lucene.Net.Tests/core/Util/TestPriorityQueue.cs
index eed8cc0..4f2f70e 100644
--- a/src/Lucene.Net.Tests/core/Util/TestPriorityQueue.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestPriorityQueue.cs
@@ -373,6 +373,35 @@ namespace Lucene.Net.Util
         }
 
         [Test]
+        public static void TestIntegrityAfterResize()
+        {
+            // Tests that after a resize, the queue keeps working fine
+            PriorityQueue<int?> pq = new IntegerQueue(4);
+            pq.Add(3);
+            pq.Add(-2);
+            pq.Add(1);
+            pq.Add(-10);
+            pq.Add(-100);  // Resize
+            Assert.AreEqual(pq.Top(), -100);
+
+            pq.Add(-1000);
+            Assert.AreEqual(pq.Top(), -1000);
+
+            pq.Pop();
+            Assert.AreEqual(pq.Top(), -100);
+
+            pq.Add(0);
+            Assert.AreEqual(pq.Top(), -100);
+
+            for(int i = 0; i < 100; i++)
+            {
+                pq.Add(5);  // Lots of resizes
+            }
+            
+            Assert.AreEqual(pq.Top(), -100);
+        }
+
+        [Test]
         public virtual void TestClear()
         {
             PriorityQueue<int?> pq = new IntegerQueue(3);


Mime
View raw message