MCPcopy Create free account
hub / github.com/couchbase/moss / Next

Method Next

iterator.go:229–287  ·  view source on GitHub ↗

Next returns ErrIteratorDone if the iterator is done.

()

Source from the content-addressed store, hash-verified

227
228// Next returns ErrIteratorDone if the iterator is done.
229func (iter *iterator) Next() error {
230 if len(iter.cursors) <= 0 {
231 return ErrIteratorDone
232 }
233
234 lastK := iter.cursors[0].k
235
236 for len(iter.cursors) > 0 {
237 next := iter.cursors[0]
238
239 if next.ssIndex < 0 && next.sc == nil {
240 err := iter.lowerLevelIter.Next()
241 if err == nil {
242 next.k, next.v, err = iter.lowerLevelIter.Current()
243 if err == nil && len(iter.cursors) > 1 {
244 heap.Fix(iter, 0)
245 }
246 }
247
248 if err != nil {
249 iter.lowerLevelIter.Close()
250 iter.lowerLevelIter = nil
251
252 heap.Pop(iter)
253 }
254 } else {
255 err := next.sc.Next()
256 if err != nil {
257 if err != ErrIteratorDone {
258 return err
259 }
260 heap.Pop(iter)
261 } else {
262 next.op, next.k, next.v = next.sc.Current()
263 if next.op == 0 {
264 heap.Pop(iter)
265 } else if len(iter.cursors) > 1 {
266 heap.Fix(iter, 0)
267 }
268 }
269 }
270
271 if len(iter.cursors) <= 0 {
272 return ErrIteratorDone
273 }
274
275 if !iteratorBytesEqual(iter.cursors[0].k, lastK) {
276 if !iter.iteratorOptions.IncludeDeletions &&
277 iter.cursors[0].op == OperationDel {
278 lastK = iter.cursors[0].k
279 continue
280 }
281
282 return nil
283 }
284 }
285
286 return ErrIteratorDone

Callers 1

startIteratorMethod · 0.95

Calls 5

iteratorBytesEqualFunction · 0.85
PopMethod · 0.80
NextMethod · 0.65
CurrentMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected