github.com/coyove/sdss@v0.0.0-20231129015646-c2ec58cca6a2/contrib/roaring/shortiterator.go (about) 1 package roaring 2 3 type shortIterable interface { 4 hasNext() bool 5 next() uint16 6 } 7 8 type shortPeekable interface { 9 shortIterable 10 peekNext() uint16 11 advanceIfNeeded(minval uint16) 12 } 13 14 type shortIterator struct { 15 slice []uint16 16 loc int 17 } 18 19 func (si *shortIterator) hasNext() bool { 20 return si.loc < len(si.slice) 21 } 22 23 func (si *shortIterator) next() uint16 { 24 a := si.slice[si.loc] 25 si.loc++ 26 return a 27 } 28 29 func (si *shortIterator) peekNext() uint16 { 30 return si.slice[si.loc] 31 } 32 33 func (si *shortIterator) advanceIfNeeded(minval uint16) { 34 if si.hasNext() && si.peekNext() < minval { 35 si.loc = advanceUntil(si.slice, si.loc, len(si.slice), minval) 36 } 37 } 38 39 type reverseIterator struct { 40 slice []uint16 41 loc int 42 } 43 44 func (si *reverseIterator) hasNext() bool { 45 return si.loc >= 0 46 } 47 48 func (si *reverseIterator) next() uint16 { 49 a := si.slice[si.loc] 50 si.loc-- 51 return a 52 }