core

package module
v0.0.0-...-9a4be88 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Set

A simple type that allows bitset-like functionality.

Static Array

A simple fixed-size array. Not super useful yet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T anyInt] struct {
	Value T
}

T must be a signed or unsigned integer of any size.

The intended use is for flags:

type Flag uint

const (
	FlagNone Flag = 1 << iota
	FlagA
	FlagB
	FlagC
	FlagFoo = FlagA | FlagC
)

flags := NewSet[Flag]()
flags.Set(FlagA)   // FlagA is set
flags.Set(FlagB)   // FlagA + FlagB is set
flags.Set(FlagFoo) // FlagA + FlagB + FlagC is set

func NewSet

func NewSet[T anyInt]() Set[T]

Creates an empty Set of T.

func NewSetFrom

func NewSetFrom[T anyInt](v T) Set[T]

Create a Set of T with the value 'v'.

func (*Set[T]) Contains

func (b *Set[T]) Contains(val T) bool

Checks if 'val' is within the Set.

func (*Set[T]) Reset

func (b *Set[T]) Reset()

Resets the value of a Set.

func (*Set[T]) Set

func (b *Set[T]) Set(v T)

Sets a value within the Set.

func (*Set[T]) Toggle

func (b *Set[T]) Toggle(v T)

Toggles 'v' within the Set.

func (*Set[T]) TotalSet

func (b *Set[T]) TotalSet() int

Returns the number of set bits within a Set.

func (*Set[T]) TotalUnset

func (b *Set[T]) TotalUnset() int

Returns the number of unset bits within a Set.

func (*Set[T]) Unset

func (b *Set[T]) Unset(v T)

Unsets a value within the Set.

type StaticArray

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

func NewStaticArray

func NewStaticArray[T any](cap uint) StaticArray[T]

func (*StaticArray[T]) Append

func (a *StaticArray[T]) Append(v T) *T

Appends 'v' to the end of the array. Returns a pointer to the stored value.

func (*StaticArray[T]) Cap

func (a *StaticArray[T]) Cap() int

Capacity of the array.

func (*StaticArray[T]) Items

func (a *StaticArray[T]) Items() []T

Slice of currently occupied items.

Allows for easier iteration:

arr := NewStaticArray[int](10)
// ...
for i, v := range arr.Items() {
	// ...
}

func (*StaticArray[T]) Len

func (a *StaticArray[T]) Len() int

Number of occupied items within the array.

func (*StaticArray[T]) Pop

func (a *StaticArray[T]) Pop() T

Removes and returns the last element of the array.

func (*StaticArray[T]) Remove

func (a *StaticArray[T]) Remove(idx int)

Ordered removal of the value at index 'idx'.

func (*StaticArray[T]) Reset

func (a *StaticArray[T]) Reset()

Sets all values within the array to their zero value and resets the count.

func (*StaticArray[T]) UnorderedRemove

func (a *StaticArray[T]) UnorderedRemove(idx int)

Unordered removal of the value at index 'idx'.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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