unique

package
v0.0.0-...-617be64 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Unique

type Unique[K comparable, V number.Number] struct {
	// contains filtered or unexported fields
}

Unique generates numerical IDs in constant time within a given capacity. Note that we use a normal sync.Mutex for synchronization instead of a sync.RWMutex, because the synchronized code is many times faster than the additional overhead incurred by sync.RWMutex.

func New

func New[K comparable, V number.Number]() *Unique[K, V]

func (*Unique[K, V]) Delete

func (u *Unique[K, V]) Delete(k K)

func (*Unique[K, V]) Ensure

func (u *Unique[K, V]) Ensure(k K) V

func (*Unique[K, V]) Exists

func (u *Unique[K, V]) Exists(k K) bool

func (*Unique[K, V]) Length

func (u *Unique[K, V]) Length() V

Length provides the amount of currently allocated IDs. Since ID allocation is strictly sequential, all IDs can be iterated in an idomatic range loop. The iterated order does not reflect the order of creation nor deletion.

for x := range u.Length() {
  ...
}

Jump to

Keyboard shortcuts

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