Documentation
¶
Index ¶
- func Reverse[E any](slice []E)
- func SliceContains[E comparable](slice []E, v E) bool
- func SliceContainsFn[E any](slice []E, fn func(E) bool) bool
- func SliceEq[E comparable](a, b []E) bool
- func SliceEqWith[A, B any](a []A, b []B, fn func(A, B) bool) bool
- type Heap
- func (h *Heap[T]) Build(values []T)
- func (h *Heap[T]) Pop() (value T, ok bool)
- func (h *Heap[T]) PopMany(k int) (values []T, ok bool)
- func (h *Heap[T]) Push(value T)
- func (h *Heap[T]) PushMany(values ...T)
- func (h *Heap[T]) Reset()
- func (h *Heap[T]) Size() int
- func (h *Heap[T]) Top() (value T, ok bool)
- func (h *Heap[T]) Values() []T
- type Slice
- func (s *Slice[E]) Append(vv ...E)
- func (s Slice[E]) Apply(fn func(v E) E) Slice[E]
- func (s Slice[E]) Cap() int
- func (slice Slice[E]) ContainsFn(fn func(E) bool) bool
- func (s Slice[E]) Copy() Slice[E]
- func (s Slice[E]) CopyWith(fn func(E) E) Slice[E]
- func (s Slice[E]) Count(fn func(v E) bool) int
- func (s *Slice[E]) Delete(i int)
- func (s *Slice[E]) DeleteNoOrder(i int)
- func (s Slice[E]) EqWith(other []E, fn func(E, E) bool) bool
- func (s Slice[E]) Fill(v E)
- func (s Slice[E]) FillWith(fn func() E)
- func (s Slice[E]) Filter(fn func(v E) bool) Slice[E]
- func (s Slice[E]) FilterInPlace(fn func(v E) bool)
- func (s Slice[E]) Index(i int) E
- func (s *Slice[E]) Insert(i int, v E)
- func (s Slice[E]) Len() int
- func (s *Slice[E]) Pop() (E, bool)
- func (slice Slice[E]) Reverse()
- func (s Slice[E]) Select(indexes ...int) Slice[E]
- func (s Slice[E]) Swap(i, j int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SliceContains ¶
func SliceContains[E comparable](slice []E, v E) bool
SliceContains returns true if the slice contains the specified element.
func SliceContainsFn ¶
SliceContainsFn returns true, if fn-predicate returns true for any element of slice.
func SliceEq ¶
func SliceEq[E comparable](a, b []E) bool
SliceEq compares two slices respecting element ordering. Empty slice is considered to be equal to nil slices.
func SliceEqWith ¶
SliceEq compares two slices respecting element ordering using provided equality hook. Empty slice is considered to be equal to nil slices.
Types ¶
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
Heap data structure.
func NewHeapFrom ¶
NewHeapFrom instantiates a new heap with a given size.
func (*Heap[T]) Build ¶
func (h *Heap[T]) Build(values []T)
Build pushes all items from values to the heap
type Slice ¶
type Slice[E any] []E
Slice is a sequence of values. Basically it's an utility wrapper around a plain slice.
func SliceIterFn ¶
SliceIterFn returns a new Slice[E] with results of fn(i) for i := range [0, n].
func (*Slice[E]) Append ¶
func (s *Slice[E]) Append(vv ...E)
Append new elements to the slice in place.
func (Slice[E]) ContainsFn ¶
ContainsFn returns true, if fn-predicate returns true for any element of slice.
func (*Slice[E]) Delete ¶
Delete value at i-position, shifting elements to the begining of slice. Panics if the index is out of range.
Slice{1, 2, 3}.Delete(1) -> Slice{2, 3}
func (*Slice[E]) DeleteNoOrder ¶
DeleteNoOrder exchanges the i-th and the last element of the slice and cuts the last, now duplicated, element.
func (Slice[E]) FillWith ¶
func (s Slice[E]) FillWith(fn func() E)
FillWith uses results of fn to fill the slice.
func (Slice[E]) Filter ¶
Filter returns slice of elements e, where fn(e) is true. fn can be called multiple times for each element.
func (Slice[E]) FilterInPlace ¶
func (Slice[E]) Index ¶
Index returns element by the index. If index is negative, then returns element len-index. Panics if index is out of [-len, len] range.
func (*Slice[E]) Insert ¶
Insert value at i-position, shifting elements to the end of slice. Panics if the index is out of range.
Slice{1, 2, 3}.Insert(1, 100) -> Slice{1, 100, 2, 3}
func (*Slice[E]) Pop ¶
Pop returns returns the last element and removes it from the slice. If the slice is empty, then returns false.
func (Slice[E]) Reverse ¶
func (slice Slice[E]) Reverse()
Reverse reverses the items of slice in place.