iterator

package
v0.48.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build[T any, C any](iter storage.Iterator, decodeKey storage.DecodeKeyFunc[C], reconstruct storage.ReconstructFunc[T, C]) storage.IndexIterator[T, C]

Build creates a new index iterator from a storage iterator. The returned iterator is a iter.Seq and can be used directly in for loops:

for entry, err := range Build(iter, decodeKey, reconstruct) {
	if err != nil {
		return err
	}
	value, err := entry.Value()
	if err != nil {
		return err
	}
	// use value
}

func BuildPrefixIterator

func BuildPrefixIterator[T any, C any](
	iter storage.Iterator,
	decodeKey storage.DecodeKeyFunc[C],
	reconstruct storage.ReconstructFunc[T, C],
	keyPrefix func(key []byte) ([]byte, error),
) storage.IndexIterator[T, C]

BuildPrefixIterator creates a new index iterator from a storage iterator, yielding only the first entry per group. Two consecutive keys belong to the same group when keyPrefix returns equal byte slices for both. Since the iterator is assumed to be ordered with groups contiguous and the desired entry first within each group, this yields exactly one entry per group.

func CollectResults

func CollectResults[T any, C any](iter storage.IndexIterator[T, C], limit uint32, filter storage.IndexFilter[*T]) ([]T, *C, error)

CollectResults iterates over the storage iterator and collects results that match the filter. It returns when it reaches the limit or the iterator is exhausted. Returns the results matching the filter and the next cursor. A nil filter accepts all entries.

No error returns are expected during normal operation.

Types

type Entry

type Entry[T any, C any] struct {
	// contains filtered or unexported fields
}

Entry is a single stored entry returned by an index iterator.

func NewEntry

func NewEntry[T any, C any](cursor C, getValue func(C) (*T, error)) Entry[T, C]

func (Entry[T, C]) Cursor

func (i Entry[T, C]) Cursor() C

Cursor returns the cursor for the entry, which includes all data included in the storage key.

func (Entry[T, C]) Value

func (i Entry[T, C]) Value() (T, error)

Value returns the fully reconstructed value for the entry.

Any error indicates the value cannot be reconstructed from the storage value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL