vector

package
v2.0.0-beta3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2022 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Index

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 New

func New[T any](values ...T) Vector[T]

New create a new Vector. This func does defensive copy.

func NewWithCap

func NewWithCap[T any](size int) Vector[T]

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]) At

func (v *Vector[T]) At(idx int) T

At returns element at index

func (*Vector[T]) Capacity

func (v *Vector[T]) Capacity() int

Capacity returns capacity of Vector

func (*Vector[T]) Clear

func (v *Vector[T]) Clear()

Clear vector content, but do not reset capacity

func (*Vector[T]) Copy

func (v *Vector[T]) Copy() Vector[T]

Copy return a new Vector contains same values as the origin Vector

func (*Vector[T]) Empty

func (v *Vector[T]) Empty() bool

Empty returns if Vector has no element

func (*Vector[T]) Extend

func (v *Vector[T]) Extend(vec Vector[T])

Extend add new values in another Vector to the end of Vector

func (*Vector[T]) FindBy

func (v *Vector[T]) FindBy(predicate func(v T) bool) int

FindBy find first value match the given predicate, return the index. If not found, return -1

func (*Vector[T]) First

func (v *Vector[T]) First() gox.Optional[T]

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]) Insert

func (v *Vector[T]) Insert(index int, value T)

Insert inserts value at index

func (*Vector[T]) Last

func (v *Vector[T]) Last() gox.Optional[T]

Last returns the last element of Vector, in an Optional. If Vector is empty, return empty Optional

func (*Vector[T]) RemoveAt

func (v *Vector[T]) RemoveAt(index int)

RemoveAt removes value at index

func (*Vector[T]) RemoveBy

func (v *Vector[T]) RemoveBy(predicate func(value T) bool)

RemoveBy removes all value match the given predicate

func (*Vector[T]) RemoveLast

func (v *Vector[T]) RemoveLast() gox.Optional[T]

RemoveLast remove and returns the last element of Vector, in an Optional. If Vector is empty, return empty Optional

func (*Vector[T]) Reserve

func (v *Vector[T]) Reserve(capacity int)

Reserve requests that the vector capacity be at least enough to contain n elements

func (*Vector[T]) Select

func (v *Vector[T]) Select(predicate func(v T) bool) Vector[T]

Select return a new Vector contains the values match given predicate

func (*Vector[T]) Set

func (v *Vector[T]) Set(idx int, value T)

Set sets element at index

func (*Vector[T]) SetSlice

func (v *Vector[T]) SetSlice(idx int, values []T)

SetSlice sets elements begin from index

func (*Vector[T]) ShrinkToFit

func (v *Vector[T]) ShrinkToFit()

ShrinkToFit requests the Vector to reduce its capacity to fit its size.

func (*Vector[T]) Size

func (v *Vector[T]) Size() int

Size returns elements count in Vector

func (*Vector[T]) SortBy

func (v *Vector[T]) SortBy(less func(v1, v2 T) bool)

SortBy sorts the vector in place, a less function is specified to compare slice values.

func (*Vector[T]) SortStableBy

func (v *Vector[T]) SortStableBy(less func(v1, v2 T) bool)

SortStableBy sorts the vector in place, with stable sort algorithm. A less function is specified to compare slice values.

func (*Vector[T]) ToSlice

func (v *Vector[T]) ToSlice() []T

ToSlice return a new slice, the slice contains a copy of data in Vector.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL