Documentation ¶
Index ¶
- type Vector
- func (v *Vector[T]) Append(value T)
- func (v *Vector[T]) AppendAll(value ...T)
- func (v *Vector[T]) AsSlice() []T
- func (v *Vector[T]) At(idx int) T
- func (v *Vector[T]) Capacity() int
- func (v *Vector[T]) Clear()
- func (v *Vector[T]) Copy() Vector[T]
- func (v *Vector[T]) Empty() bool
- func (v *Vector[T]) Extend(vec Vector[T])
- func (v *Vector[T]) FindBy(predicate func(v T) bool) int
- func (v *Vector[T]) First() gox.Optional[T]
- func (v *Vector[T]) ForEach(f func(v T))
- func (v *Vector[T]) Insert(index int, value T)
- func (v *Vector[T]) Last() gox.Optional[T]
- func (v *Vector[T]) RemoveAt(index int)
- func (v *Vector[T]) RemoveBy(predicate func(value T) bool)
- func (v *Vector[T]) RemoveLast() gox.Optional[T]
- func (v *Vector[T]) Reserve(capacity int)
- func (v *Vector[T]) Select(predicate func(v T) bool) Vector[T]
- func (v *Vector[T]) Set(idx int, value T)
- func (v *Vector[T]) SetSlice(idx int, values []T)
- func (v *Vector[T]) ShrinkToFit()
- func (v *Vector[T]) Size() int
- func (v *Vector[T]) SortBy(less func(v1, v2 T) bool)
- func (v *Vector[T]) SortStableBy(less func(v1, v2 T) bool)
- func (v *Vector[T]) ToSlice() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Vector ¶
type Vector[T any] []T
Vector is a slice but with mutable data-pointer/len/cap.
func NewWithCap ¶
NewWithCap create a new empty Vector with give capacity
func (*Vector[T]) Append ¶
func (v *Vector[T]) Append(value T)
Append add a new value to the end of Vector
func (*Vector[T]) AppendAll ¶
func (v *Vector[T]) AppendAll(value ...T)
AppendAll add new values to the end of Vector
func (*Vector[T]) AsSlice ¶
func (v *Vector[T]) AsSlice() []T
AsSlice return the underlying slice, the slice share same data with Vector.
func (*Vector[T]) Clear ¶
func (v *Vector[T]) Clear()
Clear vector content, but do not reset capacity
func (*Vector[T]) FindBy ¶
FindBy find first value match the given predicate, return the index. If not found, return -1
func (*Vector[T]) First ¶
First returns the first element of Vector, in an Optional. If Vector is empty, return empty Optional
func (*Vector[T]) ForEach ¶
func (v *Vector[T]) ForEach(f func(v T))
ForEach travers all elements in Vector
func (*Vector[T]) Last ¶
Last returns the last element of Vector, in an Optional. If Vector is empty, return empty Optional
func (*Vector[T]) RemoveLast ¶
RemoveLast remove and returns the last element of Vector, in an Optional. If Vector is empty, return empty Optional
func (*Vector[T]) Reserve ¶
Reserve requests that the vector capacity be at least enough to contain n elements
func (*Vector[T]) ShrinkToFit ¶
func (v *Vector[T]) ShrinkToFit()
ShrinkToFit requests the Vector to reduce its capacity to fit its size.
func (*Vector[T]) SortBy ¶
SortBy sorts the vector in place, a less function is specified to compare slice values.
func (*Vector[T]) SortStableBy ¶
SortStableBy sorts the vector in place, with stable sort algorithm. A less function is specified to compare slice values.