Documentation ¶
Index ¶
- func Alloc[T any]() *T
- func Free[T any](v *T)
- func New[T any]() *T
- func WithCleanup[T any](d *ErrCleanup, p *T) *T
- type ErrCleanup
- type Vec
- func (v *Vec[T]) Append(elems ...T)
- func (v *Vec[T]) Cap() int
- func (v *Vec[T]) ExpandBy(n int)
- func (v *Vec[T]) Free()
- func (v *Vec[T]) Get(i int) T
- func (v *Vec[T]) GoSlice() []T
- func (v *Vec[T]) Len() int
- func (v *Vec[T]) Push(elem T)
- func (v *Vec[T]) Resize(capcity int)
- func (v *Vec[T]) Set(i int, elem T)
- func (v *Vec[T]) Slice() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alloc ¶
func Alloc[T any]() *T
Alloc returns a pointer to a newly allocated T. It does not zero the memory.
func Free ¶
func Free[T any](v *T)
Free returns the memory for a pointer allocated by this package to the operating system.
func WithCleanup ¶
func WithCleanup[T any](d *ErrCleanup, p *T) *T
WithCleanup adds the pointer p to the list of pointers that might need cleanup on d and returns it.
Types ¶
type ErrCleanup ¶
type ErrCleanup struct {
// contains filtered or unexported fields
}
ErrCleanup allows to free several pointers when an error occurs.
func Cleanup ¶
func Cleanup(err *error) (*ErrCleanup, func())
Cleanup returns an initialised *ErrCleanup and the function that does the cleanup.
type Vec ¶
type Vec[T any] struct { // contains filtered or unexported fields }
Vec is a generic vector.
func NewVecWithCap ¶
func (*Vec[T]) Append ¶
func (v *Vec[T]) Append(elems ...T)
Append items to the end of the vector, resizing if necessary.
func (*Vec[T]) Cap ¶
Cap returns the maximum possible lenght of the vector before needing to reallocate the underlying memory.
func (*Vec[T]) ExpandBy ¶
ExpandBy increases the capacity of the vector such that it will be able to hold an extra s.Len()+n items.
func (*Vec[T]) Free ¶
func (v *Vec[T]) Free()
Free frees the memory that the vector uses and the vector struct itself.
func (*Vec[T]) GoSlice ¶
func (v *Vec[T]) GoSlice() []T
GoSlice turns the Vec[T] into a Go slice whose memory is managed by the Go runtime.
func (*Vec[T]) Push ¶
func (v *Vec[T]) Push(elem T)
Push an element to the end of the vector, resizing if necessary.