hmap

package
v0.0.0-...-f022186 Latest Latest
Warning

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

Go to latest
Published: May 29, 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 Funcs

type Funcs[K any] struct {
	// contains filtered or unexported fields
}

Funcs is a helper that is configured with hash and equals functions. This allows using closures which allows context.

func (Funcs[K]) Equal

func (m Funcs[K]) Equal(x, y K) bool

func (Funcs[K]) Hash

func (m Funcs[K]) Hash(k K) uint32

type Helper

type Helper[K any] interface {
	Hash(k K) uint32
	Equal(x, y K) bool
}

type Hmap

type Hmap[K any, V any, H Helper[K]] struct {
	// contains filtered or unexported fields
}

Hmap implements a hash map for SuObject based on: https://github.com/skarupke/flat_hash_map bytell_hash_map Its zero value is a valid empty table. NOTE: Hmap is not thread safe.

func NewHmapFuncs

func NewHmapFuncs[K any, V any](
	hfn func(k K) uint32,
	eqfn func(x, y K) bool) *Hmap[K, V, Funcs[K]]

func (*Hmap[K, V, H]) Clear

func (h *Hmap[K, V, H]) Clear()

Clear deletes the data but keeps the capacity

func (*Hmap[K, V, H]) Copy

func (h *Hmap[K, V, H]) Copy() *Hmap[K, V, H]

Copy returns a shallow copy of the Hmap

func (*Hmap[K, V, H]) Del

func (h *Hmap[K, V, H]) Del(key K) V

Del deletes a key and returns its old value, or nil if it didn't exist

func (*Hmap[K, V, H]) Get

func (h *Hmap[K, V, H]) Get(key K) V

Get returns the value for the key or nil if not found

func (*Hmap[K, V, H]) Get2

func (h *Hmap[K, V, H]) Get2(key K) (k K, v V, ok bool)

func (*Hmap[K, V, H]) GetPut

func (h *Hmap[K, V, H]) GetPut(key K, val V) (K, V, bool)

GetPut adds an entry if it doesn't exist, returns true if it already existed. Useful to avoid separate check and add.

func (*Hmap[K, V, H]) Has

func (h *Hmap[K, V, H]) Has(key K) bool

Get returns the value for the key or nil if not found

func (*Hmap[K, V, H]) Iter

func (h *Hmap[K, V, H]) Iter() func() (K, V)

Iter returns a function (closure) that is called to get the next item. It returns nil,nil at the end.

func (*Hmap[K, V, H]) Put

func (h *Hmap[K, V, H]) Put(key K, val V)

Put adds or updates an entry

func (*Hmap[K, V, H]) Size

func (h *Hmap[K, V, H]) Size() int

Size returns the current number of elements in the table

type Key

type Key interface {
	Hash() uint32
	Equal(any) bool
}

type Meth

type Meth[K Key] struct{}

Meth is a helper that calls Hash and Equal methods on the key

func (Meth[K]) Equal

func (m Meth[K]) Equal(x, y K) bool

func (Meth[K]) Hash

func (m Meth[K]) Hash(k K) uint32

Jump to

Keyboard shortcuts

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