lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [02/20] lucenenet git commit: Lucene.Net.Core.Util.Automaton: Using OpenBitSet instead of BitArray because it is a closer match to the original BitSet. BitArray has shown to be causing problems in other contexts.
Date Sun, 02 Apr 2017 07:06:02 GMT
Lucene.Net.Core.Util.Automaton: Using OpenBitSet instead of BitArray because it is a closer
match to the original BitSet. BitArray has shown to be causing problems in other contexts.


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

Branch: refs/heads/api-work
Commit: 3e8d52b2a34267d7ddf13239a470cf140257aa8f
Parents: 1944d9e
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Apr 2 09:15:45 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Apr 2 09:15:45 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Support/Number.cs           | 20 ------------
 src/Lucene.Net.Core/Util/Automaton/Automaton.cs |  6 ++--
 .../Util/Automaton/BasicOperations.cs           | 12 +++----
 .../Util/Automaton/MinimizationOperations.cs    | 33 ++++++++++----------
 .../Util/Automaton/SpecialOperations.cs         | 12 +++----
 5 files changed, 32 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3e8d52b2/src/Lucene.Net.Core/Support/Number.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Number.cs b/src/Lucene.Net.Core/Support/Number.cs
index 223a0ca..9f572b8 100644
--- a/src/Lucene.Net.Core/Support/Number.cs
+++ b/src/Lucene.Net.Core/Support/Number.cs
@@ -202,26 +202,6 @@ namespace Lucene.Net.Support
         }
 
         /// <summary>
-        /// Returns the index of the first bit that is set to true that occurs
-        /// on or after the specified starting index. If no such bit exists
-        /// then -1 is returned.
-        /// </summary>
-        /// <param name="bits">The BitArray object.</param>
-        /// <param name="fromIndex">The index to start checking from (inclusive).</param>
-        /// <returns>The index of the next set bit.</returns>
-        public static int NextSetBit(System.Collections.BitArray bits, int fromIndex)
-        {
-            for (int i = fromIndex; i < bits.Length; i++)
-            {
-                if (bits[i] == true)
-                {
-                    return i;
-                }
-            }
-            return -1;
-        }
-
-        /// <summary>
         /// Converts a System.String number to long.
         /// </summary>
         /// <param name="s"></param>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3e8d52b2/src/Lucene.Net.Core/Util/Automaton/Automaton.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Automaton/Automaton.cs b/src/Lucene.Net.Core/Util/Automaton/Automaton.cs
index dc32efb..5741337 100644
--- a/src/Lucene.Net.Core/Util/Automaton/Automaton.cs
+++ b/src/Lucene.Net.Core/Util/Automaton/Automaton.cs
@@ -531,10 +531,10 @@ namespace Lucene.Net.Util.Automaton
             }
             State[] live = GetLiveStates();
 
-            BitArray liveSet = new BitArray(states.Length);
+            OpenBitSet liveSet = new OpenBitSet(states.Length);
             foreach (State s in live)
             {
-                liveSet.SafeSet(s.number, true);
+                liveSet.Set(s.number);
             }
 
             foreach (State s in states)
@@ -544,7 +544,7 @@ namespace Lucene.Net.Util.Automaton
                 for (int i = 0; i < s.numTransitions; i++)
                 {
                     Transition t = s.TransitionsArray[i];
-                    if (liveSet.SafeGet(t.to.Number))
+                    if (liveSet.Get(t.to.number))
                     {
                         s.TransitionsArray[upto++] = s.TransitionsArray[i];
                     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3e8d52b2/src/Lucene.Net.Core/Util/Automaton/BasicOperations.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Automaton/BasicOperations.cs b/src/Lucene.Net.Core/Util/Automaton/BasicOperations.cs
index 567c450..a5f53f7 100644
--- a/src/Lucene.Net.Core/Util/Automaton/BasicOperations.cs
+++ b/src/Lucene.Net.Core/Util/Automaton/BasicOperations.cs
@@ -1079,8 +1079,8 @@ namespace Lucene.Net.Util.Automaton
                 State[] states = a.GetNumberedStates();
                 LinkedList<State> pp = new LinkedList<State>();
                 LinkedList<State> pp_other = new LinkedList<State>();
-                BitArray bb = new BitArray(states.Length);
-                BitArray bb_other = new BitArray(states.Length);
+                OpenBitSet bb = new OpenBitSet(states.Length);
+                OpenBitSet bb_other = new OpenBitSet(states.Length);
                 pp.AddLast(a.initial);
                 List<State> dest = new List<State>();
                 bool accept = a.initial.accept;
@@ -1089,7 +1089,7 @@ namespace Lucene.Net.Util.Automaton
                     c = Character.CodePointAt(s, i);
                     accept = false;
                     pp_other.Clear();
-                    bb_other.SetAll(false);
+                    bb_other.Clear(0, bb_other.Length - 1);
                     foreach (State p in pp)
                     {
                         dest.Clear();
@@ -1100,9 +1100,9 @@ namespace Lucene.Net.Util.Automaton
                             {
                                 accept = true;
                             }
-                            if (!bb_other.SafeGet(q.number))
+                            if (!bb_other.Get(q.number))
                             {
-                                bb_other.SafeSet(q.number, true);
+                                bb_other.Set(q.number);
                                 pp_other.AddLast(q);
                             }
                         }
@@ -1110,7 +1110,7 @@ namespace Lucene.Net.Util.Automaton
                     LinkedList<State> tp = pp;
                     pp = pp_other;
                     pp_other = tp;
-                    BitArray tb = bb;
+                    OpenBitSet tb = bb;
                     bb = bb_other;
                     bb_other = tb;
                 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3e8d52b2/src/Lucene.Net.Core/Util/Automaton/MinimizationOperations.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Automaton/MinimizationOperations.cs b/src/Lucene.Net.Core/Util/Automaton/MinimizationOperations.cs
index 579845f..4555f70 100644
--- a/src/Lucene.Net.Core/Util/Automaton/MinimizationOperations.cs
+++ b/src/Lucene.Net.Core/Util/Automaton/MinimizationOperations.cs
@@ -87,8 +87,9 @@ namespace Lucene.Net.Util.Automaton
             StateList[,] active = new StateList[statesLen, sigmaLen];
             StateListNode[,] active2 = new StateListNode[statesLen, sigmaLen];
             LinkedList<Int32Pair> pending = new LinkedList<Int32Pair>();
-            BitArray pending2 = new BitArray(sigmaLen * statesLen);
-            BitArray split = new BitArray(statesLen), refine = new BitArray(statesLen), refine2
= new BitArray(statesLen);
+            OpenBitSet pending2 = new OpenBitSet(sigmaLen * statesLen);
+            OpenBitSet split = new OpenBitSet(statesLen), 
+                refine = new OpenBitSet(statesLen), refine2 = new OpenBitSet(statesLen);
             for (int q = 0; q < statesLen; q++)
             {
                 splitblock[q] = new List<State>();
@@ -135,7 +136,7 @@ namespace Lucene.Net.Util.Automaton
             {
                 int j = (active[0, x].Count <= active[1, x].Count) ? 0 : 1;
                 pending.AddLast(new Int32Pair(j, x));
-                pending2.SafeSet(x * statesLen + j, true);
+                pending2.Set(x * statesLen + j);
             }
             // process pending until fixed point
             int k = 2;
@@ -145,7 +146,7 @@ namespace Lucene.Net.Util.Automaton
                 pending.Remove(ip);
                 int p = ip.N1;
                 int x = ip.N2;
-                pending2.SafeSet(x * statesLen + p, false);
+                pending2.Clear(x * statesLen + p);
                 // find states that need to be split off their blocks
                 for (StateListNode m = active[p, x].First; m != null; m = m.Next)
                 {
@@ -155,22 +156,22 @@ namespace Lucene.Net.Util.Automaton
                         foreach (State s in r)
                         {
                             int i = s.number;
-                            if (!split.SafeGet(i))
+                            if (!split.Get(i))
                             {
-                                split.SafeSet(i, true);
+                                split.Set(i);
                                 int j = block[i];
                                 splitblock[j].Add(s);
-                                if (!refine2.SafeGet(j))
+                                if (!refine2.Get(j))
                                 {
-                                    refine2.SafeSet(j, true);
-                                    refine.SafeSet(j, true);
+                                    refine2.Set(j);
+                                    refine.Set(j);
                                 }
                             }
                         }
                     }
                 }
                 // refine blocks
-                for (int j = Number.NextSetBit(refine, 0); j >= 0; j = Number.NextSetBit(refine,
j + 1))
+                for (int j = refine.NextSetBit(0); j >= 0; j = refine.NextSetBit(j + 1))
                 {
                     List<State> sb = splitblock[j];
                     if (sb.Count < partition[j].Count)
@@ -196,27 +197,27 @@ namespace Lucene.Net.Util.Automaton
                         for (int c = 0; c < sigmaLen; c++)
                         {
                             int aj = active[j, c].Count, ak = active[k, c].Count, ofs = c
* statesLen;
-                            if (!pending2.SafeGet(ofs + j) && 0 < aj &&
aj <= ak)
+                            if (!pending2.Get(ofs + j) && 0 < aj && aj
<= ak)
                             {
-                                pending2.SafeSet(ofs + j, true);
+                                pending2.Set(ofs + j);
                                 pending.AddLast(new Int32Pair(j, c));
                             }
                             else
                             {
-                                pending2.SafeSet(ofs + k, true);
+                                pending2.Set(ofs + k);
                                 pending.AddLast(new Int32Pair(k, c));
                             }
                         }
                         k++;
                     }
-                    refine2.SafeSet(j, false);
+                    refine2.Clear(j);
                     foreach (State s in sb)
                     {
-                        split.SafeSet(s.number, false);
+                        split.Clear(s.number);
                     }
                     sb.Clear();
                 }
-                refine.SetAll(false);
+                refine.Clear(0, refine.Length - 1);
             }
             // make a new state for each equivalence class, set initial state
             State[] newstates = new State[k];

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3e8d52b2/src/Lucene.Net.Core/Util/Automaton/SpecialOperations.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Automaton/SpecialOperations.cs b/src/Lucene.Net.Core/Util/Automaton/SpecialOperations.cs
index 7dfffe9..9de45e5 100644
--- a/src/Lucene.Net.Core/Util/Automaton/SpecialOperations.cs
+++ b/src/Lucene.Net.Core/Util/Automaton/SpecialOperations.cs
@@ -84,7 +84,7 @@ namespace Lucene.Net.Util.Automaton
             {
                 return true;
             }
-            return IsFinite(a.initial, new BitArray(a.GetNumberOfStates()), new BitArray(a.GetNumberOfStates()));
+            return IsFinite(a.initial, new OpenBitSet(a.GetNumberOfStates()), new OpenBitSet(a.GetNumberOfStates()));
         }
 
         /// <summary>
@@ -93,18 +93,18 @@ namespace Lucene.Net.Util.Automaton
         /// </summary>
         // TODO: not great that this is recursive... in theory a
         // large automata could exceed java's stack
-        private static bool IsFinite(State s, BitArray path, BitArray visited)
+        private static bool IsFinite(State s, OpenBitSet path, OpenBitSet visited)
         {
-            path.SafeSet(s.number, true);
+            path.Set(s.number);
             foreach (Transition t in s.GetTransitions())
             {
-                if (path.SafeGet(t.to.number) || (!visited.SafeGet(t.to.number) &&
!IsFinite(t.to, path, visited)))
+                if (path.Get(t.to.number) || (!visited.Get(t.to.number) && !IsFinite(t.to,
path, visited)))
                 {
                     return false;
                 }
             }
-            path.SafeSet(s.number, false);
-            visited.SafeSet(s.number, true);
+            path.Clear(s.number);
+            visited.Set(s.number);
             return true;
         }
 


Mime
View raw message