Documentation
¶
Overview ¶
Package seq provides an interface for sequence-like types that can be indexed and inserted into.
Protocompile avoids storing slices of its public types as a means of achieving memory efficiency. However, this means that it cannot return those slices, and thus must use proxy types that implement the interfaces in this package.
Index ¶
- func All[T any](seq Indexer[T]) iter.Seq2[int, T]
- func Append[T any](seq Inserter[T], values ...T)
- func Backward[T any](seq Indexer[T]) iter.Seq2[int, T]
- func Map[T, U any](seq Indexer[T], f func(T) U) iter.Seq[U]
- func ToSlice[T any](seq Indexer[T]) []T
- func Values[T any](seq Indexer[T]) iter.Seq[T]
- type Func
- type Indexer
- type Inserter
- type Setter
- type Slice
- type Slice2
- type SliceInserter
- type SliceInserter2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All returns an iterator over the elements in seq, like slices.All.
func Backward ¶
Backward returns an iterator over the elements in seq in reverse, like slices.Backward.
Types ¶
type Func ¶
Func implements Indexer[T] using an access function as underlying storage.
It uses a function that gets the value at the given index. Attempting to Set a value will panic.
type Indexer ¶
type Indexer[T any] interface { // Len returns the length of this sequence. Len() int // At returns the element at the given index. // // Should panic if idx < 0 or idx => Len(). At(idx int) T }
Indexer is a type that can be indexed like a slice.
type Inserter ¶
type Inserter[T any] interface { Setter[T] // Insert inserts an element at the given index. // // Should panic if idx < 0 or idx > Len(). Insert(idx int, value T) // Delete deletes the element at the given index. // // Should panic if idx < 0 or idx => Len(). Delete(idx int) }
Inserter is an Indexer that can be mutated by inserting or deleting values.
type Setter ¶
type Setter[T any] interface { Indexer[T] // SetAt sets the value of the element at the given index. // // Should panic if idx < 0 or idx => Len(). SetAt(idx int, value T) }
Setter is an Indexer that can be mutated by modifying already present values.
type Slice ¶
Slice implements Indexer[T] using an ordinary slice as the backing storage, and using the given functions to perform the conversion to and from the underlying raw values.
The first argument of Wrap/Unwrap given is the index the value has/will have in the slice.
func NewFixedSlice ¶
NewFixedSlice constructs a new Slice whose Set method panics. This function is intended for cases where the Slice will immediately be turned into an Indexer.
This method exists because Go currently will not infer type parameters of a type.
type Slice2 ¶
type Slice2[T, E1, E2 any] struct { // All functions on Slice2 assume that these two slices are // always of equal length. Slice1 []E1 Slice2 []E2 Wrap func(int, E1, E2) T Unwrap func(int, T) (E1, E2) }
Slice2 is like Slice, but it uses a pair of slices instead of one.
This is useful for cases where the raw data is represented in a struct-of-arrays format for memory efficiency.
type SliceInserter ¶
SliceInserter is like Slice, but also implements Inserter[T].
func EmptySliceInserter ¶
func EmptySliceInserter[T, E any]() SliceInserter[T, E]
EmptySliceInserter returns a SliceInserter that is always empty and whose insertion operations panic.
func NewSliceInserter ¶
func NewSliceInserter[T, E any]( slice *[]E, wrap func(int, E) T, unwrap func(int, T) E, ) SliceInserter[T, E]
NewSliceInserter constructs a new SliceInserter.
This method exists because Go currently will not infer type parameters of a type.
func (SliceInserter[T, _]) Delete ¶
func (s SliceInserter[T, _]) Delete(idx int)
Delete implements Inserter.
func (SliceInserter[T, _]) Insert ¶
func (s SliceInserter[T, _]) Insert(idx int, value T)
Insert implements Inserter.
func (SliceInserter[T, _]) SetAt ¶
func (s SliceInserter[T, _]) SetAt(idx int, value T)
SetAt implements Setter.
type SliceInserter2 ¶
type SliceInserter2[T, E1, E2 any] struct { // All functions on SliceInserter2 assume that these two slices are // always of equal length. Slice1 *[]E1 Slice2 *[]E2 Wrap func(int, E1, E2) T Unwrap func(int, T) (E1, E2) }
SliceInserter2 is like Slice2, but also implements Inserter[T].
func NewSliceInserter2 ¶
func NewSliceInserter2[T, E1, E2 any]( slice1 *[]E1, slice2 *[]E2, wrap func(int, E1, E2) T, unwrap func(int, T) (E1, E2), ) SliceInserter2[T, E1, E2]
NewSliceInserter2 constructs a new SliceInserter2.
This method exists because Go currently will not infer type parameters of a type.
func (SliceInserter2[T, _, _]) At ¶
func (s SliceInserter2[T, _, _]) At(idx int) T
At implements Indexer.
func (SliceInserter2[T, _, _]) Delete ¶
func (s SliceInserter2[T, _, _]) Delete(idx int)
Delete implements Inserter.
func (SliceInserter2[T, _, _]) Insert ¶
func (s SliceInserter2[T, _, _]) Insert(idx int, value T)
Insert implements Inserter.
func (SliceInserter2[T, _, _]) Len ¶
func (s SliceInserter2[T, _, _]) Len() int
Len implements Indexer.
func (SliceInserter2[T, _, _]) SetAt ¶
func (s SliceInserter2[T, _, _]) SetAt(idx int, value T)
SetAt implements Setter.