You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2016/10/04 20:02:04 UTC

[34/46] lucenenet git commit: Changed Facet.Taxonomy.LRUHashMap Size and MaxSize methods to Count and Capacity properties (.NETified)

Changed Facet.Taxonomy.LRUHashMap Size and MaxSize methods to Count and Capacity properties (.NETified)


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

Branch: refs/heads/master
Commit: 4319c5d1281469a0f7f34cc3bfa91f3fdbc21197
Parents: 66e3932
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Sun Sep 25 16:18:05 2016 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Mon Oct 3 23:31:56 2016 +0700

----------------------------------------------------------------------
 .../Directory/DirectoryTaxonomyReader.cs        |  4 +--
 src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs     | 30 +++++++++++---------
 .../Taxonomy/TestLRUHashMap.cs                  | 14 ++++-----
 3 files changed, 25 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4319c5d1/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs
index 98bd09e..0a60bff 100644
--- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs
@@ -393,8 +393,8 @@ namespace Lucene.Net.Facet.Taxonomy.Directory
                 EnsureOpen();
                 // LUCENENET NOTE: No locking required here,
                 // since our LRU implementation is thread-safe
-                categoryCache.MaxSize = value;
-                ordinalCache.MaxSize = value;
+                categoryCache.Capacity = value;
+                ordinalCache.Capacity = value;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4319c5d1/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs
index 1f7883f..059f834 100644
--- a/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs
@@ -62,28 +62,28 @@ namespace Lucene.Net.Facet.Taxonomy
         // Record last access so we can tie break if 2 calls make it in within
         // the same millisecond.
         private long lastAccess;
-        private int maxSize;
+        private int capacity;
 
-        public LRUHashMap(int maxSize)
+        public LRUHashMap(int capacity)
         {
-            if (maxSize < 1)
+            if (capacity < 1)
             {
-                throw new ArgumentOutOfRangeException("maxSize must be at least 1");
+                throw new ArgumentOutOfRangeException("capacity must be at least 1");
             }
-            this.maxSize = maxSize;
-            this.cache = new Dictionary<TKey, CacheDataObject>(maxSize);
+            this.capacity = capacity;
+            this.cache = new Dictionary<TKey, CacheDataObject>(capacity);
         }
 
-        public virtual int MaxSize
+        public virtual int Capacity
         {
-            get { return maxSize; }
+            get { return capacity; }
             set
             {
                 if (value < 1)
                 {
-                    throw new ArgumentOutOfRangeException("MaxSize must be at least 1");
+                    throw new ArgumentOutOfRangeException("Capacity must be at least 1");
                 }
-                maxSize = value;
+                capacity = value;
             }
         }
 
@@ -105,7 +105,7 @@ namespace Lucene.Net.Facet.Taxonomy
                         timestamp = GetTimestamp()
                     };
                     // We have added a new item, so we may need to remove the eldest
-                    if (cache.Count > MaxSize)
+                    if (cache.Count > Capacity)
                     {
                         // Remove the eldest item (lowest timestamp) from the cache
                         cache.Remove(cache.OrderBy(x => x.Value.timestamp).First().Key);
@@ -155,10 +155,12 @@ namespace Lucene.Net.Facet.Taxonomy
             return cache.ContainsKey(key);
         }
 
-        // LUCENENET TODO: Rename to Count (.NETify)
-        public int Size()
+        public int Count
         {
-            return cache.Count;
+            get
+            {
+                return cache.Count;
+            }
         }
 
         private long GetTimestamp()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4319c5d1/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs
index c08bca8..1f7afb1 100644
--- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs
+++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestLRUHashMap.cs
@@ -31,27 +31,27 @@ namespace Lucene.Net.Facet.Taxonomy
         public virtual void TestLru()
         {
             LRUHashMap<string, string> lru = new LRUHashMap<string, string>(3);
-            Assert.AreEqual(0, lru.Size());
+            Assert.AreEqual(0, lru.Count);
             lru.Put("one", "Hello world");
-            Assert.AreEqual(1, lru.Size());
+            Assert.AreEqual(1, lru.Count);
             lru.Put("two", "Hi man");
-            Assert.AreEqual(2, lru.Size());
+            Assert.AreEqual(2, lru.Count);
             lru.Put("three", "Bonjour");
-            Assert.AreEqual(3, lru.Size());
+            Assert.AreEqual(3, lru.Count);
             lru.Put("four", "Shalom");
-            Assert.AreEqual(3, lru.Size());
+            Assert.AreEqual(3, lru.Count);
             Assert.NotNull(lru.Get("three"));
             Assert.NotNull(lru.Get("two"));
             Assert.NotNull(lru.Get("four"));
             Assert.Null(lru.Get("one"));
             lru.Put("five", "Yo!");
-            Assert.AreEqual(3, lru.Size());
+            Assert.AreEqual(3, lru.Count);
             Assert.Null(lru.Get("three")); // three was last used, so it got removed
             Assert.NotNull(lru.Get("five"));
             lru.Get("four");
             lru.Put("six", "hi");
             lru.Put("seven", "hey dude");
-            Assert.AreEqual(3, lru.Size());
+            Assert.AreEqual(3, lru.Count);
             Assert.Null(lru.Get("one"));
             Assert.Null(lru.Get("two"));
             Assert.Null(lru.Get("three"));