hashmap

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Example
alloc := batchallocator.New(allocator.NewC())
defer alloc.Destroy()

hm := New[int, int](alloc)
defer hm.Free() // can be removed

hm.Set(1, 10)
hm.Set(2, 20)
hm.Set(3, 30)

sumKeys := 0
sumValues := 0
for k, v := range hm.Iter() {
	sumKeys += k
	sumValues += v
}

fmt.Println(sumKeys)
fmt.Println(sumValues)
Output:

6
60

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hashmap

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

Hashmap Manually managed hashmap,

func New

func New[K comparable, V any](alloc allocator.Allocator) *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]) 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]) Iter added in v0.8.0

func (hm *Hashmap[K, V]) Iter() iter.Seq2[K, V]

Iter returns an iterator over all key/value pairs

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]) Set added in v0.8.0

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

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

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

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

Values returns all values as a slice

Jump to

Keyboard shortcuts

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