19 using Lucene.Net.Support;
23 namespace Lucene.Net.Util
39 public AnonymousClassDocIdSetIterator(
SortedVIntList enclosingInstance)
41 InitBlock(enclosingInstance);
45 this.enclosingInstance = enclosingInstance;
52 return enclosingInstance;
56 internal int bytePos = 0;
57 internal int lastInt = 0;
58 internal int doc = - 1;
60 private void Advance()
63 sbyte b = Enclosing_Instance.bytes[bytePos++];
64 lastInt += (b & Lucene.Net.Util.SortedVIntList.VB1);
65 for (
int s = Lucene.Net.Util.SortedVIntList.BIT_SHIFT; (b & ~ Lucene.Net.Util.SortedVIntList.VB1) != 0; s += Lucene.Net.Util.SortedVIntList.BIT_SHIFT)
67 b = Enclosing_Instance.bytes[bytePos++];
68 lastInt += ((b & Lucene.Net.Util.SortedVIntList.VB1) << s);
72 public override int DocID()
77 public override int NextDoc()
79 if (bytePos >= Enclosing_Instance.lastBytePos)
91 public override int Advance(
int target)
93 while (bytePos < Enclosing_Instance.lastBytePos)
96 if (lastInt >= target)
101 return doc = NO_MORE_DOCS;
108 internal const int BITS2VINTLIST_SIZE = 8;
111 private sbyte[] bytes;
112 private int lastBytePos;
119 public SortedVIntList(params
int[] sortedInts):this(sortedInts, sortedInts.Length)
130 SortedVIntListBuilder builder =
new SortedVIntListBuilder(
this);
131 for (
int i = 0; i < inputSize; i++)
133 builder.AddInt(sortedInts[i]);
143 SortedVIntListBuilder builder =
new SortedVIntListBuilder(
this);
145 while (nextInt != - 1)
147 builder.AddInt(nextInt);
158 SortedVIntListBuilder builder =
new SortedVIntListBuilder(
this);
160 while (nextInt != - 1)
162 builder.AddInt(nextInt);
176 SortedVIntListBuilder builder =
new SortedVIntListBuilder(
this);
186 private class SortedVIntListBuilder
190 this.enclosingInstance = enclosingInstance;
192 private SortedVIntList enclosingInstance;
193 public SortedVIntList Enclosing_Instance
197 return enclosingInstance;
201 private int lastInt = 0;
203 internal SortedVIntListBuilder(SortedVIntList enclosingInstance)
205 InitBlock(enclosingInstance);
206 Enclosing_Instance.InitBytes();
210 internal virtual void AddInt(
int nextInt)
212 int diff = nextInt - lastInt;
215 throw new System.ArgumentException(
"Input not sorted or first element negative.");
218 if ((Enclosing_Instance.lastBytePos + Enclosing_Instance.MAX_BYTES_PER_INT) > Enclosing_Instance.bytes.Length)
221 Enclosing_Instance.ResizeBytes((Enclosing_Instance.bytes.Length * 2) + Enclosing_Instance.MAX_BYTES_PER_INT);
225 while ((diff & ~ Lucene.Net.Util.SortedVIntList.VB1) != 0)
228 Enclosing_Instance.bytes[Enclosing_Instance.lastBytePos++] = (sbyte) ((diff & Lucene.Net.Util.SortedVIntList.VB1) | ~ Lucene.Net.Util.SortedVIntList.VB1);
229 diff =
Number.
URShift(diff, Lucene.Net.Util.SortedVIntList.BIT_SHIFT);
231 Enclosing_Instance.bytes[Enclosing_Instance.lastBytePos++] = (sbyte) diff;
232 Enclosing_Instance.size++;
236 internal virtual void Done()
238 Enclosing_Instance.ResizeBytes(Enclosing_Instance.lastBytePos);
243 private void InitBytes()
246 bytes =
new sbyte[128];
250 private void ResizeBytes(
int newSize)
252 if (newSize != bytes.Length)
254 sbyte[] newBytes =
new sbyte[newSize];
255 Array.Copy(bytes, 0, newBytes, 0, lastBytePos);
260 private const int VB1 = 0x7F;
261 private const int BIT_SHIFT = 7;
262 private int MAX_BYTES_PER_INT = (31 / BIT_SHIFT) + 1;
265 public virtual int Size
271 public virtual int ByteSize
273 get {
return bytes.Length; }
277 public override bool IsCacheable
286 return new AnonymousClassDocIdSetIterator(
this);