Documentation
¶
Index ¶
- Constants
- Variables
- func Copy[T, Ref any](ctx context.Context, b *Builder[T, Ref], it *Iterator[T, Ref]) error
- func DebugTree[T, Ref any](ctx context.Context, params ReadParams[T, Ref], x Root[T, Ref], w io.Writer) error
- func ListEntries[T, Ref any](ctx context.Context, params ReadParams[T, Ref], idx Index[T, Ref]) ([]T, error)
- func MaxEntry[T, Ref any](ctx context.Context, params ReadParams[T, Ref], x Root[T, Ref], ...) error
- func NextIndexFromSlice[T, Ref any](idxs []Index[T, Ref]) func(ctx context.Context, dst *Index[T, Ref]) error
- func PointsToEntries[T, Ref any](root Root[T, Ref]) bool
- func PointsToIndexes[T, Ref any](root Root[T, Ref]) bool
- type Builder
- type BuilderParams
- type CompareFunc
- type Decoder
- type Encoder
- type Getter
- type Index
- type IndexDecoder
- type IndexEncoder
- type IndexHandler
- type Iterator
- type IteratorParams
- type Poster
- type ReadParams
- type Root
- type Store
- type StreamReader
- func (r *StreamReader[T, Ref]) Buffered() int
- func (r *StreamReader[T, Ref]) Next(ctx context.Context, dst *T) error
- func (r *StreamReader[T, Ref]) Peek(ctx context.Context, dst *T) error
- func (r *StreamReader[T, Ref]) PeekNoLoad(dst *T) error
- func (r *StreamReader[T, Ref]) Seek(ctx context.Context, gteq T) error
- type StreamReaderParams
- type StreamWriter
- type StreamWriterParams
Constants ¶
const (
MaxTreeDepth = 255
)
Variables ¶
var ErrOutOfRoom = errors.New("out of room")
ErrOutOfRoom is returned when an encoder does not have enough room to write an entry.
Functions ¶
func ListEntries ¶
func ListEntries[T, Ref any](ctx context.Context, params ReadParams[T, Ref], idx Index[T, Ref]) ([]T, error)
ListEntries returns a slice of all the entries pointed to by idx, directly. If idx points to other indexes directly, then ListEntries returns the entries for those indexes.
func MaxEntry ¶
func MaxEntry[T, Ref any](ctx context.Context, params ReadParams[T, Ref], x Root[T, Ref], lt maybe.Maybe[T], dst *T) error
MaxEntry returns the entry in span with the greatest (ordered last) key.
func NextIndexFromSlice ¶
func NextIndexFromSlice[T, Ref any](idxs []Index[T, Ref]) func(ctx context.Context, dst *Index[T, Ref]) error
NextIndexFromSlice returns a NextIndex function for StreamReaders which will iterate over the provided slice.
func PointsToEntries ¶
PointsToEntries returns true if root points to non-index Entries
func PointsToIndexes ¶
PointsToIndexes returns true if root points to indexes.
Types ¶
type Builder ¶
type Builder[T, Ref any] struct { // contains filtered or unexported fields }
func NewBuilder ¶
func NewBuilder[T, Ref any](params BuilderParams[T, Ref]) *Builder[T, Ref]
type BuilderParams ¶
type BuilderParams[T, Ref any] struct { Store Poster[Ref] MeanSize int MaxSize int Seed *[16]byte Compare CompareFunc[T] NewEncoder func() Encoder[T] NewIndexEncoder func() IndexEncoder[T, Ref] Copy func(dst *T, src T) }
type Decoder ¶
type Decoder[T, Ref any] interface { // ReadEntry parses an entry from src into ent. It returns the number of bytes read or an error. Read(src []byte, ent *T) (int, error) // PeekEntry is like ReadEntry except it should not affect the state of the Decoder Peek(src []byte, ent *T) error // Reset returns the decoder to the original state for the star of a node. Reset(parent Index[T, Ref]) }
type Encoder ¶
type Encoder[T any] interface { // Write encodes ent to dst and returns the number of bytes written or an error. // ErrOutOfRoom should be returned to indicate that the entry will not fit in the buffer. Write(dst []byte, ent T) (int, error) // EncodednLen returns the number of bytes that it would take to encode ent. // Calling EncodedLen should not affect the state of the Encoder. EncodedLen(ent T) int // Reset returns the encoder to it's orginally contructed state. Reset() }
type Getter ¶
type Getter[Ref any] interface { // Get fills buf with data at ref, or returns an error. // Get will always return an n <= MaxSize() Get(ctx context.Context, ref Ref, buf []byte) (n int, err error) // MaxSize returns the maximum amount of bytes that could be stored at a ref. MaxSize() int }
Getter is used to retrieve nodes from storage by Ref
type Index ¶
type Index[T, Ref any] struct { Ref Ref // IsNatural is true if this index is a natural boundary // A natural boundary. IsNatural bool Span state.Span[T] Count uint }
func ListIndexes ¶
func ListIndexes[T, Ref any](ctx context.Context, params ReadParams[T, Ref], root Root[T, Ref]) ([]Index[T, Ref], error)
ListIndexes returns the immediate children of root if any.
type IndexDecoder ¶
type IndexDecoder[T, Ref any] interface { Read(src []byte, ent *Index[T, Ref]) (int, error) // PeekEntry is like ReadEntry except it should not affect the state of the Decoder Peek(src []byte, ent *Index[T, Ref]) error // Reset returns the decoder to the original state for the star of a node. Reset(parent Index[T, Ref]) }
type IndexEncoder ¶
type IndexHandler ¶
type Iterator ¶
type Iterator[T, Ref any] struct { // contains filtered or unexported fields }
func NewIterator ¶
func NewIterator[T, Ref any](params IteratorParams[T, Ref]) *Iterator[T, Ref]
type IteratorParams ¶
type IteratorParams[T, Ref any] struct { Store Getter[Ref] NewDecoder func() Decoder[T, Ref] NewIndexDecoder func() IndexDecoder[T, Ref] Compare CompareFunc[T] Copy func(dst *T, src T) Root Root[T, Ref] Span state.Span[T] }
type Poster ¶
type Poster[Ref any] interface { // Posts stores the data and returns a Ref for retrieving it. Post(ctx context.Context, data []byte) (Ref, error) // MaxSize is the maximum amount of data that can be Posted in bytes MaxSize() int }
Poster is used to store nodes in storage and retrieve a Ref
type ReadParams ¶
type ReadParams[T, Ref any] struct { Store Getter[Ref] NewDecoder func() Decoder[T, Ref] NewIndexDecoder func() IndexDecoder[T, Ref] Compare CompareFunc[T] }
ReadParams are parameters needed to read from a tree
type Root ¶
Root is the root of the tree It contains the same information as an Index, plus the depth of the tree
type StreamReader ¶
type StreamReader[T, Ref any] struct { // contains filtered or unexported fields }
func NewStreamReader ¶
func NewStreamReader[T, Ref any](params StreamReaderParams[T, Ref]) *StreamReader[T, Ref]
func (*StreamReader[T, Ref]) Buffered ¶
func (r *StreamReader[T, Ref]) Buffered() int
Buffered returns the number of bytes in the StreamReader which have not been read.
func (*StreamReader[T, Ref]) Next ¶
func (r *StreamReader[T, Ref]) Next(ctx context.Context, dst *T) error
func (*StreamReader[T, Ref]) Peek ¶
func (r *StreamReader[T, Ref]) Peek(ctx context.Context, dst *T) error
func (*StreamReader[T, Ref]) PeekNoLoad ¶
func (r *StreamReader[T, Ref]) PeekNoLoad(dst *T) error
type StreamReaderParams ¶
type StreamWriter ¶
type StreamWriter[T, Ref any] struct { // contains filtered or unexported fields }
func NewStreamWriter ¶
func NewStreamWriter[T, Ref any](params StreamWriterParams[T, Ref]) *StreamWriter[T, Ref]
func (*StreamWriter[T, Ref]) Append ¶
func (w *StreamWriter[T, Ref]) Append(ctx context.Context, ent T) error
func (*StreamWriter[T, Ref]) Buffered ¶
func (w *StreamWriter[T, Ref]) Buffered() int