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 2014/09/16 00:53:02 UTC
[11/13] git commit: Fixed TestLongBitSet.TestSmall
Fixed TestLongBitSet.TestSmall
Fixed LongBitSet.Set by making the same change I made to OpenBitSet.Set.
Small rename of the bits variable in LongBitSet. Minor fix to the
BitSetSupport.Equals method, which was supposed to be an extension
method useful for debugging.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/e5d7b155
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/e5d7b155
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/e5d7b155
Branch: refs/heads/master
Commit: e5d7b155ea09fc3ef8a80d91a6d1f2e53ad016c6
Parents: e232ed4
Author: Prad Nelluru <pr...@microsoft.com>
Authored: Fri Sep 12 16:19:01 2014 -0700
Committer: Prad Nelluru <pr...@microsoft.com>
Committed: Fri Sep 12 16:19:01 2014 -0700
----------------------------------------------------------------------
src/Lucene.Net.Core/Support/BitSetSupport.cs | 2 +-
src/Lucene.Net.Core/Util/LongBitSet.cs | 82 ++++++++++----------
.../core/Util/TestLongBitSet.cs | 15 ++--
3 files changed, 50 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e5d7b155/src/Lucene.Net.Core/Support/BitSetSupport.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/BitSetSupport.cs b/src/Lucene.Net.Core/Support/BitSetSupport.cs
index 3ffa0a8..471a216 100644
--- a/src/Lucene.Net.Core/Support/BitSetSupport.cs
+++ b/src/Lucene.Net.Core/Support/BitSetSupport.cs
@@ -281,7 +281,7 @@ namespace Lucene.Net.Support
}
//Compares a BitArray with an OpenBitSet
- public static bool Equals(BitArray a, OpenBitSet b)
+ public static bool Equal(this BitArray a, OpenBitSet b)
{
var bitArrayCardinality = a.Cardinality();
if (bitArrayCardinality != b.Cardinality())
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e5d7b155/src/Lucene.Net.Core/Util/LongBitSet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/LongBitSet.cs b/src/Lucene.Net.Core/Util/LongBitSet.cs
index b1ea5ff..6c0093b 100644
--- a/src/Lucene.Net.Core/Util/LongBitSet.cs
+++ b/src/Lucene.Net.Core/Util/LongBitSet.cs
@@ -30,7 +30,7 @@ namespace Lucene.Net.Util
/// </summary>
public sealed class LongBitSet
{
- private readonly long[] Bits_Renamed;
+ private readonly long[] bits;
private readonly long NumBits;
private readonly int NumWords;
@@ -77,8 +77,8 @@ namespace Lucene.Net.Util
public LongBitSet(long numBits)
{
this.NumBits = numBits;
- Bits_Renamed = new long[Bits2words(numBits)];
- NumWords = Bits_Renamed.Length;
+ bits = new long[Bits2words(numBits)];
+ NumWords = bits.Length;
}
public LongBitSet(long[] storedBits, long numBits)
@@ -89,7 +89,7 @@ namespace Lucene.Net.Util
throw new System.ArgumentException("The given long array is too small to hold " + numBits + " bits");
}
this.NumBits = numBits;
- this.Bits_Renamed = storedBits;
+ this.bits = storedBits;
}
/// <summary>
@@ -105,7 +105,7 @@ namespace Lucene.Net.Util
{
get
{
- return Bits_Renamed;
+ return bits;
}
}
@@ -116,7 +116,7 @@ namespace Lucene.Net.Util
/// </summary>
public long Cardinality()
{
- return BitUtil.Pop_array(Bits_Renamed, 0, Bits_Renamed.Length);
+ return BitUtil.Pop_array(bits, 0, bits.Length);
}
public bool Get(long index)
@@ -127,7 +127,7 @@ namespace Lucene.Net.Util
// array-index-out-of-bounds-exception, removing the need for an explicit check.
int bit = (int)(index & 0x3f); // mod 64
long bitmask = 1L << bit;
- return (Bits_Renamed[i] & bitmask) != 0;
+ return (bits[i] & bitmask) != 0;
}
public void Set(long index)
@@ -136,7 +136,7 @@ namespace Lucene.Net.Util
int wordNum = (int)(index >> 6); // div 64
int bit = (int)(index & 0x3f); // mod 64
long bitmask = 1L << bit;
- Bits_Renamed[wordNum] |= bitmask;
+ bits[wordNum] |= bitmask;
}
public bool GetAndSet(long index)
@@ -145,8 +145,8 @@ namespace Lucene.Net.Util
int wordNum = (int)(index >> 6); // div 64
int bit = (int)(index & 0x3f); // mod 64
long bitmask = 1L << bit;
- bool val = (Bits_Renamed[wordNum] & bitmask) != 0;
- Bits_Renamed[wordNum] |= bitmask;
+ bool val = (bits[wordNum] & bitmask) != 0;
+ bits[wordNum] |= bitmask;
return val;
}
@@ -156,7 +156,7 @@ namespace Lucene.Net.Util
int wordNum = (int)(index >> 6);
int bit = (int)(index & 0x03f);
long bitmask = 1L << bit;
- Bits_Renamed[wordNum] &= ~bitmask;
+ bits[wordNum] &= ~bitmask;
}
public bool GetAndClear(long index)
@@ -165,8 +165,8 @@ namespace Lucene.Net.Util
int wordNum = (int)(index >> 6); // div 64
int bit = (int)(index & 0x3f); // mod 64
long bitmask = 1L << bit;
- bool val = (Bits_Renamed[wordNum] & bitmask) != 0;
- Bits_Renamed[wordNum] &= ~bitmask;
+ bool val = (bits[wordNum] & bitmask) != 0;
+ bits[wordNum] &= ~bitmask;
return val;
}
@@ -179,7 +179,7 @@ namespace Lucene.Net.Util
Debug.Assert(index >= 0 && index < NumBits);
int i = (int)(index >> 6);
int subIndex = (int)(index & 0x3f); // index within the word
- long word = Bits_Renamed[i] >> subIndex; // skip all the bits to the right of index
+ long word = bits[i] >> subIndex; // skip all the bits to the right of index
if (word != 0)
{
@@ -188,7 +188,7 @@ namespace Lucene.Net.Util
while (++i < NumWords)
{
- word = Bits_Renamed[i];
+ word = bits[i];
if (word != 0)
{
return (i << 6) + Number.NumberOfTrailingZeros(word);
@@ -207,7 +207,7 @@ namespace Lucene.Net.Util
Debug.Assert(index >= 0 && index < NumBits, "index=" + index + " numBits=" + NumBits);
int i = (int)(index >> 6);
int subIndex = (int)(index & 0x3f); // index within the word
- long word = (Bits_Renamed[i] << (63 - subIndex)); // skip all the bits to the left of index
+ long word = (bits[i] << (63 - subIndex)); // skip all the bits to the left of index
if (word != 0)
{
@@ -216,7 +216,7 @@ namespace Lucene.Net.Util
while (--i >= 0)
{
- word = Bits_Renamed[i];
+ word = bits[i];
if (word != 0)
{
return (i << 6) + 63 - Number.NumberOfLeadingZeros(word);
@@ -234,7 +234,7 @@ namespace Lucene.Net.Util
int pos = Math.Min(NumWords, other.NumWords);
while (--pos >= 0)
{
- Bits_Renamed[pos] |= other.Bits_Renamed[pos];
+ bits[pos] |= other.bits[pos];
}
}
@@ -246,7 +246,7 @@ namespace Lucene.Net.Util
int pos = Math.Min(NumWords, other.NumWords);
while (--pos >= 0)
{
- Bits_Renamed[pos] ^= other.Bits_Renamed[pos];
+ bits[pos] ^= other.bits[pos];
}
}
@@ -257,7 +257,7 @@ namespace Lucene.Net.Util
int pos = Math.Min(NumWords, other.NumWords);
while (--pos >= 0)
{
- if ((Bits_Renamed[pos] & other.Bits_Renamed[pos]) != 0)
+ if ((bits[pos] & other.bits[pos]) != 0)
{
return true;
}
@@ -272,11 +272,11 @@ namespace Lucene.Net.Util
int pos = Math.Min(NumWords, other.NumWords);
while (--pos >= 0)
{
- Bits_Renamed[pos] &= other.Bits_Renamed[pos];
+ bits[pos] &= other.bits[pos];
}
if (NumWords > other.NumWords)
{
- Arrays.Fill(Bits_Renamed, other.NumWords, NumWords, 0L);
+ Arrays.Fill(bits, other.NumWords, NumWords, 0L);
}
}
@@ -284,10 +284,10 @@ namespace Lucene.Net.Util
/// this = this AND NOT other </summary>
public void AndNot(LongBitSet other)
{
- int pos = Math.Min(NumWords, other.Bits_Renamed.Length);
+ int pos = Math.Min(NumWords, other.bits.Length);
while (--pos >= 0)
{
- Bits_Renamed[pos] &= ~other.Bits_Renamed[pos];
+ bits[pos] &= ~other.bits[pos];
}
}
@@ -327,18 +327,18 @@ namespace Lucene.Net.Util
if (startWord == endWord)
{
- Bits_Renamed[startWord] ^= (startmask & endmask);
+ bits[startWord] ^= (startmask & endmask);
return;
}
- Bits_Renamed[startWord] ^= startmask;
+ bits[startWord] ^= startmask;
for (int i = startWord + 1; i < endWord; i++)
{
- Bits_Renamed[i] = ~Bits_Renamed[i];
+ bits[i] = ~bits[i];
}
- Bits_Renamed[endWord] ^= endmask;
+ bits[endWord] ^= endmask;
}
/// <summary>
@@ -360,17 +360,17 @@ namespace Lucene.Net.Util
//LUCENE TO-DO
long startmask = -1L << (int)startIndex;
- long endmask = -(int)((uint)1L >> (int)-endIndex); // 64-(endIndex&0x3f) is the same as -endIndex due to wrap
+ long endmask = (long)(0xffffffffffffffffUL >> (int)-endIndex);//-(int)((uint)1L >> (int)-endIndex); // 64-(endIndex&0x3f) is the same as -endIndex due to wrap
if (startWord == endWord)
{
- Bits_Renamed[startWord] |= (startmask & endmask);
+ bits[startWord] |= (startmask & endmask);
return;
}
- Bits_Renamed[startWord] |= startmask;
- Arrays.Fill(Bits_Renamed, startWord + 1, endWord, -1L);
- Bits_Renamed[endWord] |= endmask;
+ bits[startWord] |= startmask;
+ Arrays.Fill(bits, startWord + 1, endWord, -1L);
+ bits[endWord] |= endmask;
}
/// <summary>
@@ -400,19 +400,19 @@ namespace Lucene.Net.Util
if (startWord == endWord)
{
- Bits_Renamed[startWord] &= (startmask | endmask);
+ bits[startWord] &= (startmask | endmask);
return;
}
- Bits_Renamed[startWord] &= startmask;
- Arrays.Fill(Bits_Renamed, startWord + 1, endWord, 0L);
- Bits_Renamed[endWord] &= endmask;
+ bits[startWord] &= startmask;
+ Arrays.Fill(bits, startWord + 1, endWord, 0L);
+ bits[endWord] &= endmask;
}
public LongBitSet Clone()
{
- long[] bits = new long[this.Bits_Renamed.Length];
- Array.Copy(this.Bits_Renamed, 0, bits, 0, bits.Length);
+ long[] bits = new long[this.bits.Length];
+ Array.Copy(this.bits, 0, bits, 0, bits.Length);
return new LongBitSet(bits, NumBits);
}
@@ -433,7 +433,7 @@ namespace Lucene.Net.Util
{
return false;
}
- return Arrays.Equals(Bits_Renamed, other.Bits_Renamed);
+ return Arrays.Equals(bits, other.bits);
}
public override int GetHashCode()
@@ -441,7 +441,7 @@ namespace Lucene.Net.Util
long h = 0;
for (int i = NumWords; --i >= 0; )
{
- h ^= Bits_Renamed[i];
+ h ^= bits[i];
h = (h << 1) | ((long)((ulong)h >> 63)); // rotate left
}
// fold leftmost bits into right and add a constant to prevent
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e5d7b155/src/Lucene.Net.Tests/core/Util/TestLongBitSet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestLongBitSet.cs b/src/Lucene.Net.Tests/core/Util/TestLongBitSet.cs
index a9264e8..7eab97d 100644
--- a/src/Lucene.Net.Tests/core/Util/TestLongBitSet.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestLongBitSet.cs
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+using System;
using Lucene.Net.Randomized.Generators;
using Lucene.Net.Support;
using NUnit.Framework;
@@ -101,26 +102,26 @@ namespace Lucene.Net.Util
int idx;
idx = Random().Next(sz);
- a.Set(idx, true);
+ a.SafeSet(idx, true);
b.Set(idx);
idx = Random().Next(sz);
- a.Set(idx, false);
+ a.SafeSet(idx, false);
b.Clear(idx);
idx = Random().Next(sz);
- a.Set(idx, !a.Get(idx));
+ a.SafeSet(idx, !a.Get(idx));
b.Flip(idx, idx + 1);
idx = Random().Next(sz);
- a.Set(idx, !a.Get(idx));
+ a.SafeSet(idx, !a.SafeGet(idx));
b.Flip(idx, idx + 1);
-
+
bool val2 = b.Get(idx);
bool val = b.GetAndSet(idx);
Assert.IsTrue(val2 == val);
Assert.IsTrue(b.Get(idx));
-
+
if (!val)
{
b.Clear(idx);
@@ -131,7 +132,7 @@ namespace Lucene.Net.Util
// test that the various ways of accessing the bits are equivalent
DoGet(a, b);
-
+
// test ranges, including possible extension
int fromIndex, toIndex;
fromIndex = Random().Next(sz / 2);