hashmap

package
v0.0.0-...-1edb6db Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 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 Map

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

Map is a hashmap. Like map[string]interface{}

func New

func New[K comparable, V any](cap int) *Map[K, V]

New returns a new Map. Like map[string]interface{}

func (*Map[K, V]) All

func (m *Map[K, V]) All() iter.Seq2[K, V]

All returns an iterator over all key/values. This is a replacement for Scan using the new iter package. It's not safe to call or Set or Delete while scanning.

func (*Map[K, V]) Copy

func (m *Map[K, V]) Copy() *Map[K, V]

Copy the hashmap.

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K) (prev V, deleted bool)

Delete deletes a value for a key. Returns the deleted value, or false when no value was assigned.

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) (value V, ok bool)

Get returns a value for a key. Returns false when no value has been assign for key.

func (*Map[K, V]) GetPos

func (m *Map[K, V]) GetPos(pos uint64) (key K, value V, ok bool)

GetPos gets a single keys/value nearby a position. The pos param can be any valid uint64. Useful for grabbing a random item from the map.

func (*Map[K, V]) Keys

func (m *Map[K, V]) Keys() []K

Keys returns all keys as a slice

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

Len returns the number of values in map.

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(key K, value V) (V, bool)

Set assigns a value to a key. Returns the previous value, or false when no value was assigned.

func (*Map[K, V]) Values

func (m *Map[K, V]) Values() []V

Values returns all values as a slice

type Set

type Set[K comparable] struct {
	// contains filtered or unexported fields
}

func (*Set[K]) All

func (tr *Set[K]) All() iter.Seq[K]

All returns all items in the st.

func (*Set[K]) Contains

func (tr *Set[K]) Contains(key K) bool

Get a value for key

func (*Set[K]) Copy

func (tr *Set[K]) Copy() *Set[K]

Copy the set. This is a copy-on-write operation and is very fast because it only performs a shadow copy.

func (*Set[K]) Delete

func (tr *Set[K]) Delete(key K)

Delete an item.

func (*Set[K]) GetPos

func (s *Set[K]) GetPos(pos uint64) (key K, ok bool)

GetPos gets a single keys/value nearby a position. The pos param can be any valid uint64. Useful for grabbing a random item from the Set.

func (*Set[K]) Insert

func (tr *Set[K]) Insert(key K)

Insert an item

func (*Set[K]) Keys

func (tr *Set[K]) Keys() []K

Keys returns all keys as a slice

func (*Set[K]) Len

func (tr *Set[K]) Len() int

Len returns the number of items in the tree.

Jump to

Keyboard shortcuts

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