19 using System.Collections;
20 using Lucene.Net.Search;
21 using Lucene.Net.Util;
23 namespace Lucene.Net.Spatial.Util
36 private readonly BitArray bits;
43 public static int bits2words(
int numBits)
45 var numLong = (int)((uint)numBits >> 6);
46 if ((numBits & 63) != 0)
55 bits =
new BitArray(numBits);
64 bits =
new BitArray(other.bits);
77 public override bool IsCacheable
88 public int Cardinality()
91 for (var i = 0; i < bits.Length; i++)
98 public bool Get(
int index)
103 public void Set(
int index)
105 bits.Set(index,
true);
108 public bool GetAndSet(
int index)
110 var ret = bits[index];
111 bits.Set(index,
true);
115 public void Clear(
int index)
117 bits.Set(index,
false);
120 public bool GetAndClear(
int index)
122 var ret = bits[index];
123 bits.Set(index,
false);
133 public int NextSetBit(
int index)
135 if (index >= bits.Length || index < 0)
136 throw new ArgumentException(
"Invalid index",
"index");
138 for (var i = index; i < bits.Length; i++)
140 if (bits[i])
return i;
149 public int PrevSetBit(
int index)
151 if (index >= bits.Length || index < 0)
152 throw new ArgumentException(
"Invalid index",
"index");
154 for (var i = index; i >= 0; i--)
156 if (bits[i])
return i;
187 Or(other.bits, other.bits.Length);
190 private void Or(BitArray otherArr,
int otherLen)
192 var thisArr = this.bits;
193 int pos = Math.Min(thisArr.Length, otherLen);
196 thisArr[pos] |= otherArr[pos];
232 And(other.bits, other.bits.Length);
235 private void And(BitArray otherArr,
int otherLen)
237 var thisArr = this.bits;
238 int pos = Math.Min(thisArr.Length, otherLen);
241 thisArr[pos] &= otherArr[pos];
243 if (thisArr.Length > otherLen)
245 for (var i = otherLen; i < thisArr.Length; i++)
277 AndNot(other.bits, other.bits.Length);
280 private void AndNot(BitArray otherArr,
int otherLen)
282 var thisArr = this.bits;
283 int pos = Math.Min(thisArr.Length, otherLen);
286 thisArr[pos] &= !otherArr[pos];
338 public void Set(
int startIndex,
int endIndex)
341 for (
int i = startIndex; i < endIndex; i++)
375 public void Clear(
int startIndex,
int endIndex)
377 for (
int i = startIndex; i < endIndex; i++)
390 public override bool Equals(Object o)
403 return bits.
Equals(other.bits);
406 public override int GetHashCode()
408 return bits.GetHashCode();
421 private int curDocId = -1;
422 private readonly IEnumerator enumerator;
426 enumerator = bitset.bits.GetEnumerator();
429 public override int DocID()
434 public override int NextDoc()
436 while (enumerator.MoveNext())
439 if ((
bool)enumerator.Current)
return curDocId;
441 return curDocId = NO_MORE_DOCS;
444 public override int Advance(
int target)
447 while ((doc = NextDoc()) < target)