hashmap

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 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 Hashable

type Hashable interface {
	comparable
	Hash() uint32
}

Hashable keys must implement this interface or use type hashmap.String and hashmap.Int which implements the interface

type Hashmap

type Hashmap[K Hashable, V any] struct {
	// contains filtered or unexported fields
}

Hashmap Manually managed hashmap, keys can be hashmap.String, hashmap.Int or any type that implements the hashmap.Hashable interface

func New

func New[K Hashable, V any]() *Hashmap[K, V]

New creates a new Hashmap with key of type K and value of type V

func (*Hashmap[K, V]) Delete added in v0.7.0

func (hm *Hashmap[K, V]) Delete(key K)

Delete delete value with key K

func (*Hashmap[K, V]) ForEach added in v0.7.0

func (hm *Hashmap[K, V]) ForEach(f func(key K, value V))

ForEach iterates through all key/value pairs

func (*Hashmap[K, V]) Free

func (hm *Hashmap[K, V]) Free()

Free frees the Hashmap

func (*Hashmap[K, V]) Get

func (hm *Hashmap[K, V]) Get(key K) (value V, exists bool)

Get takes key K and return value V

func (*Hashmap[K, V]) GetPtr

func (hm *Hashmap[K, V]) GetPtr(key K) (value *V, exists bool)

GetPtr takes key K and return a pointer to value V

func (*Hashmap[K, V]) Insert

func (hm *Hashmap[K, V]) Insert(key K, value V)

Insert inserts a new value V if key K doesn't exist, Otherwise update the key K with value V

func (*Hashmap[K, V]) Keys added in v0.7.0

func (hm *Hashmap[K, V]) Keys() []K

Keys returns all keys as a slice

func (*Hashmap[K, V]) Values added in v0.7.0

func (hm *Hashmap[K, V]) Values() []V

Values returns all values as a slice

type Int

type Int int

Int an int type that implements Hashable Interface

func (Int) Hash

func (i Int) Hash() uint32

type String

type String string

String a string type that implements Hashable Interface

func (String) Hash

func (s String) Hash() uint32

Jump to

Keyboard shortcuts

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