vector

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: MIT 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] struct {
	// contains filtered or unexported fields
}

Vector a contiguous growable array type

func Init

func Init[T any](values ...T) *Vector[T]

Init initializes a new vector with the T elements provided and sets it's len and cap to len(values)

func New

func New[T any](args ...int) *Vector[T]

New creates a new empty vector, if args not provided it will create an empty vector, if only one arg is provided it will init a vector with len and cap equal to the provided arg, if two args are provided it will init a vector with len = args[0] cap = args[1]

func (*Vector[T]) At

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

At gets element T at specified index

func (*Vector[T]) AtPtr

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

AtPtr gets element a pointer of T at specified index

func (*Vector[T]) Cap

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

Cap gets vector capacity (underling memory length).

func (*Vector[T]) Free

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

Free deallocats the vector

func (*Vector[T]) Last

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

Last gets the last element from a vector

func (*Vector[T]) Len

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

Len gets vector length

func (*Vector[T]) Pop

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

Pop pops value T from the vector and returns it

func (*Vector[T]) Push

func (v *Vector[T]) Push(value T)

Push pushes value T to the vector, grows if needed.

func (*Vector[T]) Set

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

Set sets element T at specified index

func (*Vector[T]) Slice

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

Slice gets a slice representing the vector CAUTION: don't append to this slice, this is only used if you want to loop on the vec elements

Jump to

Keyboard shortcuts

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