iter

package
v0.0.0-...-8762c42 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyU64 = &EmptyUnary[uint64]{}
	EmptyKV  = &EmptyDual[[]byte, []byte]{}
)

Functions

func Count

func Count[T any](s Unary[T]) (cnt int, err error)

func CountDual

func CountDual[K, V any](s Dual[K, V]) (cnt int, err error)

func CountKV

func CountKV(s KV) (int, error)

func CountU64

func CountU64(s U64) (int, error)

func ExpectEqual

func ExpectEqual[V comparable](tb testing.TB, s1, s2 Unary[V])

func ExpectEqualU64

func ExpectEqualU64(tb testing.TB, s1, s2 Unary[uint64])

func ToArr

func ToArr[T any](s Unary[T]) (res []T, err error)

func ToArrKVMust

func ToArrKVMust(s KV) ([][]byte, [][]byte)

func ToArrU64Must

func ToArrU64Must(s U64) []uint64

func ToDualArray

func ToDualArray[K, V any](s Dual[K, V]) (keys []K, values []V, err error)

func ToKVArray

func ToKVArray(s KV) ([][]byte, [][]byte, error)

func ToU64Arr

func ToU64Arr(s U64) ([]uint64, error)

Types

type ArrStream

type ArrStream[V any] struct {
	// contains filtered or unexported fields
}

func Array

func Array[V any](arr []V) *ArrStream[V]

func ReverseArray

func ReverseArray[V any](arr []V) *ArrStream[V]

func (*ArrStream[V]) Close

func (it *ArrStream[V]) Close()

func (*ArrStream[V]) HasNext

func (it *ArrStream[V]) HasNext() bool

func (*ArrStream[V]) Next

func (it *ArrStream[V]) Next() (V, error)

func (*ArrStream[V]) NextBatch

func (it *ArrStream[V]) NextBatch() ([]V, error)

type Closer

type Closer interface {
	Close()
}

type Dual

type Dual[K, V any] interface {
	Next() (K, V, error)
	HasNext() bool
}

Dual - return 2 items - usually called Key and Value (or `k` and `v`) Example:

for s.HasNext() {
	k, v, err := s.Next()
	if err != nil {
		return err
	}
}

type EmptyDual

type EmptyDual[K, V any] struct{}

func (EmptyDual[K, V]) HasNext

func (EmptyDual[K, V]) HasNext() bool

func (EmptyDual[K, V]) Next

func (EmptyDual[K, V]) Next() (k K, v V, err error)

type EmptyUnary

type EmptyUnary[T any] struct{}

func (EmptyUnary[T]) HasNext

func (EmptyUnary[T]) HasNext() bool

func (EmptyUnary[T]) Next

func (EmptyUnary[T]) Next() (v T, err error)

type FilterDualIter

type FilterDualIter[K, V any] struct {
	// contains filtered or unexported fields
}

FilterDualIter - analog `map` (in terms of map-filter-reduce pattern) please avoid reading from Disk/DB more elements and then filter them. Better push-down filter conditions to lower-level iterator to reduce disk reads amount.

func FilterDual

func FilterDual[K, V any](it Dual[K, V], filter func(K, V) bool) *FilterDualIter[K, V]

func FilterKV

func FilterKV(it KV, filter func(k, v []byte) bool) *FilterDualIter[[]byte, []byte]

func (*FilterDualIter[K, v]) Close

func (m *FilterDualIter[K, v]) Close()

func (*FilterDualIter[K, V]) HasNext

func (m *FilterDualIter[K, V]) HasNext() bool

func (*FilterDualIter[K, V]) Next

func (m *FilterDualIter[K, V]) Next() (k K, v V, err error)

type FilterUnaryIter

type FilterUnaryIter[T any] struct {
	// contains filtered or unexported fields
}

FilterUnaryIter - analog `map` (in terms of map-filter-reduce pattern) please avoid reading from Disk/DB more elements and then filter them. Better push-down filter conditions to lower-level iterator to reduce disk reads amount.

func FilterU64

func FilterU64(it U64, filter func(k uint64) bool) *FilterUnaryIter[uint64]

func FilterUnary

func FilterUnary[T any](it Unary[T], filter func(T) bool) *FilterUnaryIter[T]

func (*FilterUnaryIter[T]) Close

func (m *FilterUnaryIter[T]) Close()

func (*FilterUnaryIter[T]) HasNext

func (m *FilterUnaryIter[T]) HasNext() bool

func (*FilterUnaryIter[T]) Next

func (m *FilterUnaryIter[T]) Next() (k T, err error)

type IntersectIter

type IntersectIter[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

IntersectIter

func (*IntersectIter[T]) Close

func (m *IntersectIter[T]) Close()

func (*IntersectIter[T]) HasNext

func (m *IntersectIter[T]) HasNext() bool

func (*IntersectIter[T]) Next

func (m *IntersectIter[T]) Next() (T, error)

type KV

type KV Dual[[]byte, []byte]

often used shortcuts

func UnionKV

func UnionKV(x, y KV, limit int) KV

type NextPageDual

type NextPageDual[K, V any] func(pageToken string) (keys []K, values []V, nextPageToken string, err error)

internal types

type NextPageUnary

type NextPageUnary[T any] func(pageToken string) (arr []T, nextPageToken string, err error)

internal types

type Paginated

type Paginated[T any] struct {
	// contains filtered or unexported fields
}

PaginatedIter - for remote-list pagination

Rationale: If an API does not support pagination from the start, supporting it later is troublesome because adding pagination breaks the API's behavior. Clients that are unaware that the API now uses pagination could incorrectly assume that they received a complete result, when in fact they only received the first page.

To support pagination (returning list results in pages) in a List method, the API shall:

  • The client uses this field to request a specific page of the list results.
  • define an int32 field page_size in the List method's request message. Clients use this field to specify the maximum number of results to be returned by the server. The server may further constrain the maximum number of results returned in a single page. If the page_size is 0, the server will decide the number of results to be returned.
  • define a string field next_page_token in the List method's response message. This field represents the pagination token to retrieve the next page of results. If the value is "", it means no further results for the request.

see: https://cloud.google.com/apis/design/design_patterns

func Paginate

func Paginate[T any](f NextPageUnary[T]) *Paginated[T]

func PaginateU64

func PaginateU64(f NextPageUnary[uint64]) *Paginated[uint64]

func (*Paginated[T]) Close

func (it *Paginated[T]) Close()

func (*Paginated[T]) HasNext

func (it *Paginated[T]) HasNext() bool

func (*Paginated[T]) Next

func (it *Paginated[T]) Next() (v T, err error)

type PaginatedDual

type PaginatedDual[K, V any] struct {
	// contains filtered or unexported fields
}

func PaginateDual

func PaginateDual[K, V any](f NextPageDual[K, V]) *PaginatedDual[K, V]

func PaginateKV

func PaginateKV(f NextPageDual[[]byte, []byte]) *PaginatedDual[[]byte, []byte]

func (*PaginatedDual[K, V]) Close

func (it *PaginatedDual[K, V]) Close()

func (*PaginatedDual[K, V]) HasNext

func (it *PaginatedDual[K, V]) HasNext() bool

func (*PaginatedDual[K, V]) Next

func (it *PaginatedDual[K, V]) Next() (k K, v V, err error)

type PairsWithErrorIter

type PairsWithErrorIter struct {
	// contains filtered or unexported fields
}

PairsWithErrorIter - return N, keys and then error

func PairsWithError

func PairsWithError(errorAt int) *PairsWithErrorIter

func (*PairsWithErrorIter) HasNext

func (m *PairsWithErrorIter) HasNext() bool

func (*PairsWithErrorIter) Next

func (m *PairsWithErrorIter) Next() ([]byte, []byte, error)

type RangeIter

type RangeIter[T constraints.Integer] struct {
	// contains filtered or unexported fields
}

func Range

func Range[T constraints.Integer](from, to T) *RangeIter[T]

func (*RangeIter[T]) Close

func (it *RangeIter[T]) Close()

func (*RangeIter[T]) HasNext

func (it *RangeIter[T]) HasNext() bool

func (*RangeIter[T]) Next

func (it *RangeIter[T]) Next() (T, error)

type TransformDualIter

type TransformDualIter[K, V any] struct {
	// contains filtered or unexported fields
}

TransformDualIter - analog `map` (in terms of map-filter-reduce pattern)

func TransformDual

func TransformDual[K, V any](it Dual[K, V], transform func(K, V) (K, V, error)) *TransformDualIter[K, V]

func TransformKV

func TransformKV(it KV, transform func(k, v []byte) ([]byte, []byte, error)) *TransformDualIter[[]byte, []byte]

func (*TransformDualIter[K, v]) Close

func (m *TransformDualIter[K, v]) Close()

func (*TransformDualIter[K, V]) HasNext

func (m *TransformDualIter[K, V]) HasNext() bool

func (*TransformDualIter[K, V]) Next

func (m *TransformDualIter[K, V]) Next() (K, V, error)

type TransformKV2U64Iter

type TransformKV2U64Iter[K, V []byte] struct {
	// contains filtered or unexported fields
}

func TransformKV2U64

func TransformKV2U64[K, V []byte](it KV, transform func(K, V) (uint64, error)) *TransformKV2U64Iter[K, V]

func (*TransformKV2U64Iter[K, v]) Close

func (m *TransformKV2U64Iter[K, v]) Close()

func (*TransformKV2U64Iter[K, V]) HasNext

func (m *TransformKV2U64Iter[K, V]) HasNext() bool

func (*TransformKV2U64Iter[K, V]) Next

func (m *TransformKV2U64Iter[K, V]) Next() (uint64, error)

type U64

type U64 Unary[uint64]

often used shortcuts

type Unary

type Unary[V any] interface {
	Next() (V, error)
	//NextBatch() ([]V, error)
	HasNext() bool
}

Unary - return 1 item. Example:

for s.HasNext() {
	v, err := s.Next()
	if err != nil {
		return err
	}
}

func Intersect

func Intersect[T constraints.Ordered](x, y Unary[T], limit int) Unary[T]

func Union

func Union[T constraints.Ordered](x, y Unary[T], asc order.By, limit int) Unary[T]

type UnionKVIter

type UnionKVIter struct {
	// contains filtered or unexported fields
}

UnionKVIter - merge 2 kv.Pairs streams to 1 in lexicographically order 1-st stream has higher priority - when 2 streams return same key

func (*UnionKVIter) Close

func (m *UnionKVIter) Close()

func (m *UnionKVIter) ToArray() (keys, values [][]byte, err error) { return ToKVArray(m) }

func (*UnionKVIter) HasNext

func (m *UnionKVIter) HasNext() bool

func (*UnionKVIter) Next

func (m *UnionKVIter) Next() ([]byte, []byte, error)

type UnionUnary

type UnionUnary[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

UnionUnary

func (*UnionUnary[T]) Close

func (m *UnionUnary[T]) Close()

func (*UnionUnary[T]) HasNext

func (m *UnionUnary[T]) HasNext() bool

func (*UnionUnary[T]) Next

func (m *UnionUnary[T]) Next() (res T, err error)

Jump to

Keyboard shortcuts

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