Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"github.com/joetifa2003/mm-go/allocator"
"github.com/joetifa2003/mm-go/vector"
)
func main() {
alloc := allocator.NewC()
v := vector.New[int](alloc)
v.Push(1)
v.Push(2)
v.Push(3)
fmt.Println("Length:", v.Len())
for i := 0; i < v.Len(); i++ {
fmt.Println(v.At(i))
}
for _, k := range v.Iter() {
fmt.Println(k)
}
}
Output: Length: 3 1 2 3 1 2 3
Index ¶
- type Vector
- func (v *Vector[T]) At(idx int) T
- func (v *Vector[T]) AtPtr(idx int) *T
- func (v *Vector[T]) Cap() int
- func (v *Vector[T]) Free()
- func (v *Vector[T]) Iter() iter.Seq2[int, T]
- func (v *Vector[T]) Last() T
- func (v *Vector[T]) Len() int
- func (v *Vector[T]) Pop() T
- func (v *Vector[T]) Push(value T)
- func (v *Vector[T]) RemoveAt(idx int) T
- func (v *Vector[T]) Set(idx int, value T)
- func (v *Vector[T]) Slice() []T
- func (v *Vector[T]) UnsafeAt(idx int) T
Examples ¶
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 ¶
Init initializes a new vector with the T elements provided and sets it's len and cap to len(values)
func New ¶
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]) Push ¶
func (v *Vector[T]) Push(value T)
Push pushes value T to the vector, grows if needed.
Click to show internal directories.
Click to hide internal directories.