Help us shape the future of Go! Take the 2026 Go Developer Survey

sparse

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

package sparse implements a generic sparse array with popcount compression.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array[T any] struct {
	bitset.BitSet
	Items []T
}

Array, a generic implementation of a sparse array with popcount compression and payload T.

func (*Array[T]) DeleteAt

func (s *Array[T]) DeleteAt(i uint) (T, bool)

DeleteAt, delete a value at i from the sparse array.

func (*Array[T]) Get

func (s *Array[T]) Get(i uint) (val T, ok bool)

Get the value at i from sparse array.

func (*Array[T]) InsertAt

func (s *Array[T]) InsertAt(i uint, val T) (exists bool)

InsertAt a value at i into the sparse array. If the value already exists, overwrite it with val and return true.

func (*Array[T]) Len added in v0.13.2

func (s *Array[T]) Len() int

Len returns the number of items in sparse array.

func (*Array[T]) MustGet

func (s *Array[T]) MustGet(i uint) T

MustGet, use it only after a successful test or the behavior is undefined, maybe it panics.

func (*Array[T]) UpdateAt

func (s *Array[T]) UpdateAt(i uint, cb func(T, bool) T) (newVal T, wasPresent bool)

UpdateAt or set the value at i via callback. The new value is returned and true if the val was already present.

Jump to

Keyboard shortcuts

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