poolslice

package
v0.0.0-...-94c82f2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package poolslice supports allocating slots out of a slice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IndexGenerator

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

An IndexGenerator allocates slice indexes, allowing re-use. This lets you insert remove items within a slice dynamically, re-using empty slots when available.

func (*IndexGenerator) Alloc

func (g *IndexGenerator) Alloc() int

Alloc allocates a free index. Will use an empty slot if available.

func (*IndexGenerator) Release

func (g *IndexGenerator) Release(index int)

Release marks an index as free.

type PoolSlice

type PoolSlice[T any] struct {
	Items []T // The slice
	// contains filtered or unexported fields
}

A PoolSlice wraps a slice, adding support for tracking free vs. in-use slots and inserting new elements into free slots.

func (*PoolSlice[T]) Add

func (s *PoolSlice[T]) Add(value T) int

Add adds T to the slice, returning its index. Will use a free slot if available, otherwise will expand the slice.

func (*PoolSlice[T]) Remove

func (s *PoolSlice[T]) Remove(index int)

Remove removes the item at the index, replacing it with the zero value and marking its slot for re-use.

Jump to

Keyboard shortcuts

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