11using Lucene . Net . Diagnostics ;
22using System ;
3+ using System . Collections ;
4+ using System . Collections . Generic ;
35using System . Runtime . CompilerServices ;
46
57namespace Lucene . Net . Util . Packed
@@ -26,7 +28,8 @@ namespace Lucene.Net.Util.Packed
2628 /// <para/>
2729 /// NOTE: This was AbstractAppendingLongBuffer in Lucene
2830 /// </summary>
29- public abstract class AbstractAppendingInt64Buffer : Int64Values // LUCENENET NOTE: made public rather than internal because has public subclasses
31+ public abstract class AbstractAppendingInt64Buffer : Int64Values , // LUCENENET NOTE: made public rather than internal because has public subclasses
32+ IEnumerable < long > // LUCENENET specific
3033 {
3134 internal const int MIN_PAGE_SIZE = 64 ;
3235
@@ -105,7 +108,7 @@ public void Add(long l)
105108 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
106109 internal virtual void Grow ( int newBlockCount )
107110 {
108- Array . Resize < PackedInt32s . Reader > ( ref values , newBlockCount ) ;
111+ Array . Resize ( ref values , newBlockCount ) ;
109112 }
110113
111114 internal abstract void PackPendingValues ( ) ;
@@ -144,33 +147,27 @@ public int Get(long index, long[] arr, int off, int len)
144147 /// <summary>
145148 /// Return an iterator over the values of this buffer.
146149 /// </summary>
147- public virtual Iterator GetIterator ( )
150+ public virtual Enumerator GetEnumerator ( )
148151 {
149- return new Iterator ( this ) ;
152+ return new Enumerator ( this ) ;
150153 }
151154
152- public sealed class Iterator
155+ IEnumerator < long > IEnumerable < long > . GetEnumerator ( ) => GetEnumerator ( ) ;
156+
157+ IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
158+
159+ public sealed class Enumerator : IEnumerator < long >
153160 {
154161 private readonly AbstractAppendingInt64Buffer outerInstance ;
155162
156163 internal long [ ] currentValues ;
157164 internal int vOff , pOff ;
158165 internal int currentCount ; // number of entries of the current page
159166
160- internal Iterator ( AbstractAppendingInt64Buffer outerInstance )
167+ internal Enumerator ( AbstractAppendingInt64Buffer outerInstance )
161168 {
162169 this . outerInstance = outerInstance ;
163- vOff = pOff = 0 ;
164- if ( outerInstance . valuesOff == 0 )
165- {
166- currentValues = outerInstance . pending ;
167- currentCount = outerInstance . pendingOff ;
168- }
169- else
170- {
171- currentValues = new long [ outerInstance . values [ 0 ] . Count ] ;
172- FillValues ( ) ;
173- }
170+ Reset ( ) ; // LUCENENET specific - moved from ctor
174171 }
175172
176173 internal void FillValues ( )
@@ -191,15 +188,24 @@ internal void FillValues()
191188 }
192189
193190 /// <summary>
194- /// Whether or not there are remaining values. </summary>
195- public bool HasNext => pOff < currentCount ;
191+ /// Gets the current value.
192+ /// </summary>
193+ public long Current { get ; private set ; }
194+
195+ object IEnumerator . Current => Current ;
196196
197197 /// <summary>
198- /// Return the next long in the buffer. </summary>
199- public long Next ( )
198+ /// Advances the enumerator to the next value.
199+ /// </summary>
200+ public bool MoveNext ( )
200201 {
201- if ( Debugging . AssertsEnabled ) Debugging . Assert ( HasNext ) ;
202- long result = currentValues [ pOff ++ ] ;
202+ if ( pOff >= currentCount )
203+ {
204+ return false ;
205+ }
206+
207+ Current = currentValues [ pOff ++ ] ;
208+
203209 if ( pOff == currentCount )
204210 {
205211 vOff += 1 ;
@@ -213,7 +219,33 @@ public long Next()
213219 currentCount = 0 ;
214220 }
215221 }
216- return result ;
222+
223+ return true ;
224+ }
225+
226+ /// <summary>
227+ /// Resets the enumerator to its initial position.
228+ /// </summary>
229+ public void Reset ( )
230+ {
231+ vOff = pOff = 0 ;
232+ if ( outerInstance . valuesOff == 0 )
233+ {
234+ currentValues = outerInstance . pending ;
235+ currentCount = outerInstance . pendingOff ;
236+ }
237+ else
238+ {
239+ currentValues = new long [ outerInstance . values [ 0 ] . Count ] ;
240+ FillValues ( ) ;
241+ }
242+ }
243+
244+ /// <summary>
245+ /// Dispose of the resources used by the <see cref="Enumerator"/>.
246+ /// </summary>
247+ public void Dispose ( )
248+ {
217249 }
218250 }
219251
0 commit comments