Documentation ¶
Index ¶
- func IterFactory[T any](s []T) liter.Factory[T]
- func IterSlice[T any](i liter.Iter[T], buf []T) []T
- func Len[T any](s []T) int
- func NewIter[T any](s []T) liter.Wrapper[T]
- type Buffer
- func (buf Buffer[T]) Cap(c int) Slice[T]
- func (buf Buffer[T]) Empty(c int) Slice[T]
- func (buf Buffer[T]) Lener(i interface{}) Slice[T]
- func (buf Buffer[T]) ReduceCapacity(c int) Slice[T]
- func (buf Buffer[T]) Slice(c int) Slice[T]
- func (buf Buffer[T]) Split(c int) (Slice[T], Buffer[T])
- func (buf Buffer[T]) Zeros(c int) Slice[T]
- type Iter
- type Lener
- type Less
- type Slice
- func (s Slice[T]) AppendNotZero(ts ...T) []T
- func (s Slice[T]) AtIdx(idx int) T
- func (s Slice[T]) Buffer() Buffer[T]
- func (s Slice[T]) CheckCapacity(c int) Slice[T]
- func (s Slice[T]) Clone() Slice[T]
- func (s Slice[T]) ForAll(fn func(idx int, t T)) *sync.WaitGroup
- func (s Slice[T]) Idx(idx int) (int, bool)
- func (s Slice[T]) IdxCheck(idx int) bool
- func (s Slice[T]) Iter() liter.Wrapper[T]
- func (s Slice[T]) IterFactory() (i liter.Iter[T], t T, done bool)
- func (s Slice[T]) Len() int
- func (s Slice[T]) Pop() (T, Slice[T])
- func (s Slice[T]) Remove(idxs ...int) Slice[T]
- func (s Slice[T]) RemoveOrdered(idxs ...int) Slice[T]
- func (s Slice[T]) Search(fn func(T) bool) int
- func (s Slice[T]) Shift() (T, Slice[T])
- func (s Slice[T]) Sort(less Less[T]) Slice[T]
- func (s Slice[T]) Swap(i, j int)
- type Slicer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IterFactory ¶
IterFactory fulfills liter.Factory.
func IterSlice ¶
IterSlice creates a slice from an liter.Iter. If the Iter fulfills Slicer, then the Slice method will be used. If it fulfill Lener, that will be used for buffer allocation.
Types ¶
type Buffer ¶
type Buffer[T any] []T
Buffer is used to provide a slice for re-use avoiding excessive allocation.
func (Buffer[T]) Cap ¶
Cap returns a buffer with at least capacity c and length 0. If the provided buffer has capacity, it will be used otherwise a new one is created.
func (Buffer[T]) Empty ¶
BufferEmpty returns a zero length buffer with at least capacity c. If the provided buffer has capacity, it will be used otherwise a new one is created.
func (Buffer[T]) Lener ¶
Lener returns a zero length buffer. If i fulfils Lener, the capacity of the buffer will be at least that returned by Len. If not, the buffer is used with the size set to zero.
func (Buffer[T]) ReduceCapacity ¶
ReduceCapacity sets the capacity to a lower value. This can be useful when splitting a buffer to prevent use of the first part of the buffer from overflowing into the second part.
func (Buffer[T]) Slice ¶
BufferSlice returns a buffer with length c. If the provided buffer has capacity, it will be used otherwise a new one is created.
type Iter ¶
type Iter[T any] struct { S []T I int // DoneFn determines when the iterator is done. If it does not check the // bounds, an out of bounds panic is likely. DoneFn func(*Iter[T]) bool }
Iter wraps a slice to fulfillliter.Iter.
func (*Iter[T]) Cur ¶
Cur fulfillsliter.Iter. It returns the value at the current index and the done bool. If it is done, it will return the zero value for the type.
func (*Iter[T]) Next ¶
Next fulfillsliter.Iter. It increments the index and returns the value at that index and the done bool. If it is done, it will return the zero value for the type.
type Lener ¶
type Lener interface {
Len() int
}
Lener allows an interface to show that it knows it's length.
type Less ¶
Less is used for sorting. Less does not inheirently mean "less than", only that when sorting the index should be less. For instance, when sorting from highest to lowest, the index of the greater value will be less that the value it is compared against.
func GT ¶
func GT[T constraints.Ordered]() Less[T]
LT returns an instance of Less[T] that does a greater than comparison.
func LT ¶
func LT[T constraints.Ordered]() Less[T]
LT returns an instance of Less[T] that does a less than comparison.
type Slice ¶
type Slice[T any] []T
Slice is a wrapper that provides helper methods
func Make ¶
Make a slice with the specified length and capacity. If capacity is set to 0, then ln will be used for capacity as well.
func Transform ¶
Transform one slice to another. The transformation function's second return is a bool indicating if the returned value should be included in the result. The returned Slice is sized exactly to the output.
func TransformSlice ¶
Transform one slice to another. The transformation function's second return is a bool indicating if the returned value should be included in the result. The returned Slice is sized exactly to the output.
func (Slice[T]) AppendNotZero ¶
func (s Slice[T]) AppendNotZero(ts ...T) []T
AppendNotZero will append any values from ts that are not the zero value for the type. Particularly useful for appending not nil values.
func (Slice[T]) CheckCapacity ¶
CheckCapacity ensures that Slice s has capacity c. If not, a new slice is created with capacity c and the slice is copied.
func (Slice[T]) ForAll ¶
ForAll runs a Go routine for each element in s, passing it into fn. A WaitGroup is returned that will finish when all Go routines return.
func (Slice[T]) Idx ¶
Idx provides a relative index to the slice. So a value of -1 will return the last index. The bool indicates if the index is in range.
func (Slice[T]) Pop ¶
Pop returns the last element of the slice and the slice resized to remove that element. If the size of the slice is zero, the zero value for the type is returned.
func (Slice[T]) Remove ¶
Remove values at given indicies by swapping them with values from the end and truncating the slice. Values less than zero or greater than the length of the list are ignored. Note that idxs is reordered so if that is a slice passed in and the order is important, pass in a copy.
func (Slice[T]) RemoveOrdered ¶
RemoveOrdered preserves the order of the slice while removing the values at the given indexes.
func (Slice[T]) Shift ¶
Shift returns the first element of the slice and the slice resized to remove that element. If the size of the slice is zero, the zero value for the type is returned.