bmap

package
v0.0.0-...-9e081f2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package bmap implements basic map with []byte key type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BMap

type BMap[T any] struct {
	// contains filtered or unexported fields
}

BMap implements generic hashmap with []byte key type. It is intended to store a small fixed set of keys and it has some limitations: keys cannot be deleted, number of keys cannot exceed defined limit. Added keys are copied into internal byte slice for safety. Implementation is intended to be as simple (and bug-free) as possible. Uses custom implementation of hashmap, collisions are resolved by chaining.

func New

func New[T any](size int) *BMap[T]

New create bytes map. size defines maximum number of stored keys (not counting empty key).

func (*BMap[T]) Get

func (m *BMap[T]) Get(key []byte) (T, bool)

Get returns stored value by key and a flag telling whether this key is stored in the map. Returns zero value if the key is not present.

func (*BMap[T]) Set

func (m *BMap[T]) Set(key []byte, value T)

Set adds or rewrites value for given key. Panics if trying to add a new key to the map containing maximum number of keys.

Jump to

Keyboard shortcuts

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