diff --git a/erigon-lib/kv/stream/stream_interface.go b/erigon-lib/kv/stream/stream_interface.go index 6974c58e468..819154853a0 100644 --- a/erigon-lib/kv/stream/stream_interface.go +++ b/erigon-lib/kv/stream/stream_interface.go @@ -16,6 +16,8 @@ package stream +import "errors" + // Streams - it's iterator-like composable high-level abstraction - which designed for inter-process communication and between processes: // - cancelable // - return errors @@ -38,6 +40,10 @@ package stream // check in loops on stream. Duo has very limited API - user has no way to // terminate it - but user can specify more strict conditions when creating stream (then server knows better when to stop) +// Indicates the iterator has no more elements. Meant to be returned by implementations of Next() +// when there are no more elements. +var ErrIteratorExhausted = errors.New("iterator exhausted") + // Uno - return 1 item. Example: // // for s.HasNext() { diff --git a/erigon-lib/recsplit/eliasfano32/elias_fano.go b/erigon-lib/recsplit/eliasfano32/elias_fano.go index 37580963e5c..fb00f12b300 100644 --- a/erigon-lib/recsplit/eliasfano32/elias_fano.go +++ b/erigon-lib/recsplit/eliasfano32/elias_fano.go @@ -18,7 +18,6 @@ package eliasfano32 import ( "encoding/binary" - "errors" "fmt" "io" "math" @@ -27,6 +26,7 @@ import ( "unsafe" "github.com/erigontech/erigon-lib/common/bitutil" + "github.com/erigontech/erigon-lib/kv/stream" ) // EliasFano algo overview https://www.antoniomallia.it/sorted-integers-compression-with-elias-fano-encoding.html @@ -44,8 +44,6 @@ const ( superQSize uint64 = 1 + qPerSuperQ/2 // 1 + 64/2 = 33 ) -var ErrEliasFanoIterExhausted = errors.New("elias fano iterator exhausted") - // EliasFano can be used to encode one monotone sequence type EliasFano struct { data []uint64 @@ -486,7 +484,7 @@ func (efi *EliasFanoIter) decrement() { func (efi *EliasFanoIter) Next() (uint64, error) { if !efi.HasNext() { - return 0, ErrEliasFanoIterExhausted + return 0, stream.ErrIteratorExhausted } idx64, shift := efi.lowerIdx/64, efi.lowerIdx%64 lower := efi.lowerBits[idx64] >> shift diff --git a/erigon-lib/recsplit/eliasfano32/elias_fano_test.go b/erigon-lib/recsplit/eliasfano32/elias_fano_test.go index 89ec594603e..89976581072 100644 --- a/erigon-lib/recsplit/eliasfano32/elias_fano_test.go +++ b/erigon-lib/recsplit/eliasfano32/elias_fano_test.go @@ -355,7 +355,7 @@ func TestIterator(t *testing.T) { require.NoError(t, err) } _, err := it.Next() - require.ErrorIs(t, err, ErrEliasFanoIterExhausted) + require.ErrorIs(t, err, stream.ErrIteratorExhausted) it = ef.ReverseIterator() for range offsets { @@ -363,7 +363,7 @@ func TestIterator(t *testing.T) { require.NoError(t, err) } _, err = it.Next() - require.ErrorIs(t, err, ErrEliasFanoIterExhausted) + require.ErrorIs(t, err, stream.ErrIteratorExhausted) }) t.Run("article-example1", func(t *testing.T) {