vector

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(option *Options)

Option is a function type used to set Options

func WithCapacity

func WithCapacity(capacity int) Option

WithCapacity is used to set the capacity of a Vector

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options holds the Vector's options

type T added in v1.1.0

type T any

type Vector

type Vector[T any] struct {
	// contains filtered or unexported fields
}

Vector is a linear data structure, the internal is a slice

func New

func New[T any](opts ...Option) *Vector[T]

New creates a new Vector

func NewFromVector

func NewFromVector[T any](other *Vector[T]) *Vector[T]

NewFromVector news a Vector from other Vector

func (*Vector[T]) At

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

At returns the value at position pos, returns nil if pos is out off range .

func (*Vector[T]) Back

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

Back returns the last value in the vector, returns nil if the vector is empty.

func (*Vector[T]) Begin

func (v *Vector[T]) Begin() *VectorIterator[T]

Begin returns the first iterator of the vector

func (*Vector[T]) Capacity

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

Capacity returns the capacity of the vector

func (*Vector[T]) Clear

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

Clear clears all data in the vector

func (*Vector[T]) Data

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

Data returns internal data of the vector

func (*Vector[T]) Empty

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

Empty returns true if the vector is empty, otherwise returns false

func (*Vector[T]) End

func (v *Vector[T]) End() *VectorIterator[T]

End returns the end iterator of the vector

func (*Vector[T]) Erase

func (v *Vector[T]) Erase(iter iterator.ConstIterator[T]) *VectorIterator[T]

Erase erases the element of the iterator iter point to

func (*Vector[T]) EraseAt

func (v *Vector[T]) EraseAt(pos int)

EraseAt erases the value at position pos

func (*Vector[T]) EraseIndexRange

func (v *Vector[T]) EraseIndexRange(first, last int)

EraseIndexRange erases values at range[first, last)

func (*Vector[T]) EraseRange

func (v *Vector[T]) EraseRange(first, last iterator.ConstIterator[T]) *VectorIterator[T]

EraseRange erases all elements in the range[first, last)

func (*Vector[T]) First

func (v *Vector[T]) First() *VectorIterator[T]

First returns the first iterator of the vector

func (*Vector[T]) Front

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

Front returns the first value in the vector, returns nil if the vector is empty.

func (*Vector[T]) Insert

func (v *Vector[T]) Insert(iter iterator.ConstIterator[T], val T) *VectorIterator[T]

Insert inserts a value val to the vector at the position of the iterator iter point to

func (*Vector[T]) InsertAt

func (v *Vector[T]) InsertAt(pos int, val T)

InsertAt inserts the value val to the vector at position pos

func (*Vector[T]) IterAt

func (v *Vector[T]) IterAt(pos int) *VectorIterator[T]

IterAt returns the iterator at position of the vector

func (*Vector[T]) Last

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

Last returns the last iterator of the vector

func (*Vector[T]) PopBack

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

PopBack returns the last value of the vector and erase it, returns nil if the vector is empty.

func (*Vector[T]) PushBack

func (v *Vector[T]) PushBack(val T)

PushBack pushes val to the back of the vector

func (*Vector[T]) Reserve

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

Reserve makes a new space for the vector with passed capacity

func (*Vector[T]) Resize

func (v *Vector[T]) Resize(size int)

Resize resizes the size of the vector to the passed size

func (*Vector[T]) SetAt

func (v *Vector[T]) SetAt(pos int, val T)

SetAt sets the value val to the vector at position pos

func (*Vector[T]) ShrinkToFit

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

ShrinkToFit shrinks the capacity of the vector to the fit size

func (*Vector[T]) Size

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

Size returns the size of the vector

func (*Vector[T]) String

func (v *Vector[T]) String() string

String returns a string representation of the vector

type VectorIterator

type VectorIterator[T any] struct {
	// contains filtered or unexported fields
}

VectorIterator represents a vector iterator

func (*VectorIterator[T]) Clone

func (iter *VectorIterator[T]) Clone() iterator.ConstIterator[T]

Clone clones the iterator into a new iterator

func (*VectorIterator[T]) Equal

func (iter *VectorIterator[T]) Equal(other iterator.ConstIterator[T]) bool

Equal returns true if the iterator is equal to the passed iterator

func (*VectorIterator[T]) IsValid

func (iter *VectorIterator[T]) IsValid() bool

IsValid returns true if the iterator is valid, otherwise returns false

func (*VectorIterator[T]) IteratorAt

func (iter *VectorIterator[T]) IteratorAt(position int) iterator.RandomAccessIterator[T]

IteratorAt creates an iterator with the passed position

func (*VectorIterator[T]) Next

func (iter *VectorIterator[T]) Next() iterator.ConstIterator[T]

Next moves the position of iterator to the next position and returns itself

func (*VectorIterator[T]) Position

func (iter *VectorIterator[T]) Position() int

Position return the position of the iterator point to

func (*VectorIterator[T]) Prev

func (iter *VectorIterator[T]) Prev() iterator.ConstBidIterator[T]

Prev moves the position of the iterator to the previous position and returns itself

func (*VectorIterator[T]) SetValue

func (iter *VectorIterator[T]) SetValue(val T)

SetValue sets the value of the iterator point to

func (*VectorIterator[T]) Value

func (iter *VectorIterator[T]) Value() T

Value returns the value of the iterator point to

Jump to

Keyboard shortcuts

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