lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject git commit: LUCENENET-529 AOORE in Lucene.Net.Spatial.Util.FixedBitSet
Date Tue, 03 Dec 2013 22:07:15 GMT
Updated Branches:
  refs/heads/master 1a18965e5 -> b568cb505


LUCENENET-529 AOORE in Lucene.Net.Spatial.Util.FixedBitSet


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

Branch: refs/heads/master
Commit: b568cb505a0f7b4a29065bf87cb09c175f01f3d3
Parents: 1a18965
Author: synhershko <itamar@code972.com>
Authored: Wed Dec 4 00:07:03 2013 +0200
Committer: synhershko <itamar@code972.com>
Committed: Wed Dec 4 00:07:03 2013 +0200

----------------------------------------------------------------------
 .../Spatial/Util/CompatibilityExtensions.cs     | 107 ++++++++++++++++---
 1 file changed, 94 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b568cb50/src/contrib/Spatial/Util/CompatibilityExtensions.cs
----------------------------------------------------------------------
diff --git a/src/contrib/Spatial/Util/CompatibilityExtensions.cs b/src/contrib/Spatial/Util/CompatibilityExtensions.cs
index e802662..26a1462 100644
--- a/src/contrib/Spatial/Util/CompatibilityExtensions.cs
+++ b/src/contrib/Spatial/Util/CompatibilityExtensions.cs
@@ -21,6 +21,7 @@ using Lucene.Net.Support.Compatibility;
 #else
 using System.Collections.Concurrent;
 #endif
+using System.Collections.Generic;
 using System.Diagnostics;
 using Lucene.Net.Analysis.Tokenattributes;
 using Lucene.Net.Index;
@@ -37,14 +38,18 @@ namespace Lucene.Net.Spatial.Util
 
         public static void Append(this ITermAttribute termAtt, char ch)
         {
-            termAtt.SetTermBuffer(termAtt.Term + new string(new[] { ch })); // TODO: Not
optimal, but works
+            termAtt.SetTermBuffer(termAtt.Term + new string(new[] {ch})); // TODO: Not optimal,
but works
         }
 
-        private static readonly ConcurrentDictionary<string, IBits> _docsWithFieldCache
= new ConcurrentDictionary<string, IBits>();
+        private static readonly ConcurrentDictionary<Key<string, IndexReader>, IBits>
_docsWithFieldCache =
+            new ConcurrentDictionary<Key<string, IndexReader>, IBits>();
 
         internal static IBits GetDocsWithField(this FieldCache fc, IndexReader reader, String
field)
         {
-            return _docsWithFieldCache.GetOrAdd(field, f => DocsWithFieldCacheEntry_CreateValue(reader,
new Entry(field, null), false));
+            return _docsWithFieldCache.GetOrAdd(new Key<string, IndexReader>(field,
reader),
+                                                key =>
+                                                DocsWithFieldCacheEntry_CreateValue(key.Item2,
+                                                                                    new Entry(key.Item1,
null), false));
         }
 
         /// <summary> <p/>
@@ -67,7 +72,8 @@ namespace Lucene.Net.Spatial.Util
             _docsWithFieldCache.Clear();
         }
 
-        private static IBits DocsWithFieldCacheEntry_CreateValue(IndexReader reader, Entry
entryKey, bool setDocsWithField /* ignored */)
+        private static IBits DocsWithFieldCacheEntry_CreateValue(IndexReader reader, Entry
entryKey,
+                                                                 bool setDocsWithField /*
ignored */)
         {
             var field = entryKey.field;
             FixedBitSet res = null;
@@ -98,7 +104,7 @@ namespace Lucene.Net.Spatial.Util
                     {
                         res.Set(termDocs.Doc);
                     }
-        
+
                     term = terms.Next();
                     if (term == null)
                     {
@@ -121,7 +127,21 @@ namespace Lucene.Net.Spatial.Util
         }
 
         /* table of number of leading zeros in a byte */
-        public static readonly byte[] nlzTable = { 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4,
4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0 };
+
+        public static readonly byte[] nlzTable =
+            {
+                8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3
+                , 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1
+                , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
+                , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+                , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+                , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+            };
 
         /// <summary>
         /// Returns the number of leading zero bits.
@@ -132,11 +152,23 @@ namespace Lucene.Net.Spatial.Util
         {
             int n = 0;
             // do the first step as a long
-            var y = (int)((ulong)x >> 32);
-            if (y == 0) { n += 32; y = (int)(x); }
-            if ((y & 0xFFFF0000) == 0) { n += 16; y <<= 16; }
-            if ((y & 0xFF000000) == 0) { n += 8; y <<= 8; }
-            return n + nlzTable[(uint)y >> 24];
+            var y = (int) ((ulong) x >> 32);
+            if (y == 0)
+            {
+                n += 32;
+                y = (int) (x);
+            }
+            if ((y & 0xFFFF0000) == 0)
+            {
+                n += 16;
+                y <<= 16;
+            }
+            if ((y & 0xFF000000) == 0)
+            {
+                n += 8;
+                y <<= 8;
+            }
+            return n + nlzTable[(uint) y >> 24];
             /* implementation without table:
               if ((y & 0xF0000000) == 0) { n+=4; y<<=4; }
               if ((y & 0xC0000000) == 0) { n+=2; y<<=2; }
@@ -175,10 +207,11 @@ namespace Lucene.Net.Spatial.Util
     /// </summary>
     internal class Entry
     {
-        internal readonly String field;        // which Fieldable
-        internal readonly Object custom;       // which custom comparator or parser
+        internal readonly String field; // which Fieldable
+        internal readonly Object custom; // which custom comparator or parser
 
         /* Creates one of these objects for a custom comparator/parser. */
+
         public Entry(String field, Object custom)
         {
             this.field = field;
@@ -186,6 +219,7 @@ namespace Lucene.Net.Spatial.Util
         }
 
         /* Two of these are equal iff they reference the same field and type. */
+
         public override bool Equals(Object o)
         {
             var other = o as Entry;
@@ -207,9 +241,56 @@ namespace Lucene.Net.Spatial.Util
         }
 
         /* Composes a hashcode based on the field and type. */
+
         public override int GetHashCode()
         {
             return field.GetHashCode() ^ (custom == null ? 0 : custom.GetHashCode());
         }
     }
+
+    internal struct Key<T1, T2> : IEquatable<Key<T1, T2>>
+    {
+        public bool Equals(Key<T1, T2> other)
+        {
+            return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) &&
+                   EqualityComparer<T2>.Default.Equals(Item2, other.Item2);
+        }
+
+        public override bool Equals(object obj)
+        {
+            if (ReferenceEquals(null, obj))
+            {
+                return false;
+            }
+            return obj is Key<T1, T2> && Equals((Key<T1, T2>) obj);
+        }
+
+        public override int GetHashCode()
+        {
+            unchecked
+            {
+                return (EqualityComparer<T1>.Default.GetHashCode(Item1)*397) ^
+                       EqualityComparer<T2>.Default.GetHashCode(Item2);
+            }
+        }
+
+        public static bool operator ==(Key<T1, T2> left, Key<T1, T2> right)
+        {
+            return left.Equals(right);
+        }
+
+        public static bool operator !=(Key<T1, T2> left, Key<T1, T2> right)
+        {
+            return !left.Equals(right);
+        }
+
+        public readonly T1 Item1;
+        public readonly T2 Item2;
+
+        public Key(T1 item1, T2 item2)
+        {
+            Item1 = item1;
+            Item2 = item2;
+        }
+    }
 }


Mime
View raw message