intern

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenericIntern

type GenericIntern[T comparable] interface {
	// Deduplicate deduplicates the value by inserting it to the map & reading it back out.
	// If the value is already present, then the cached value is returned (interned value)
	// If the value is new, then a new key is added and the original value is returned after being interned.
	Deduplicate(input T) (output T)

	// Insert attempts to insert key to the map, to get the value back later call Value(id) to retrieve the interned value.
	// If the value is already present in the map, then it returns the existing unique id.
	// If the value is new, then it increments the unique id counter & returns the new unique id.
	Insert(input T) (uniqueID uint64)

	// Value returns the interned value for the given unique id
	// If the key is present in the map then the output T will be the interned value, and `ok=true`.
	// If the key is not present, then `ok=false` will be returned.
	Value(uniqueID uint64) (output T, ok bool)

	// Len returns the size of the map (number of keys)
	Len() int

	// Clear deletes the interned values & reset the counter back to 0.
	// This allows you to free the interned values & put the Intern struct back into a safe state for a sync.Pool or garbage collection.
	Clear()
}

func New

func New[T comparable]() GenericIntern[T]

New creates a new GenericIntern[T] instance

func NewSafe

func NewSafe[T comparable]() GenericIntern[T]

NewSafe creates a new GenericIntern[T] instance

Jump to

Keyboard shortcuts

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