Help us shape the future of Go! Take the 2026 Go Developer Survey

bimap

package
v1.36.186 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package bimap is an in-memory bi-directional map. Serialization is the caller's concern — this type is generic over comparable K/V, and the internal Lux wire format is ZAP, which is element-typed. Use a typed ZAP schema (or a typed snapshot struct) at the call site to persist a bimap; do not bolt a generic marshaler onto BiMap itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BiMap

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

BiMap is a bi-directional map.

func New

func New[K, V comparable]() *BiMap[K, V]

New creates a new empty bimap.

func (*BiMap[K, V]) DeleteKey

func (m *BiMap[K, V]) DeleteKey(key K) (V, bool)

DeleteKey removes [key] from the map and returns the value it mapped to.

func (*BiMap[K, V]) DeleteValue

func (m *BiMap[K, V]) DeleteValue(val V) (K, bool)

DeleteValue removes [val] from the map and returns the key that mapped to it.

func (*BiMap[K, V]) GetKey

func (m *BiMap[K, V]) GetKey(val V) (K, bool)

GetKey that maps to the provided value.

func (*BiMap[K, V]) GetValue

func (m *BiMap[K, V]) GetValue(key K) (V, bool)

GetValue that is mapped to the provided key.

func (*BiMap[K, _]) HasKey

func (m *BiMap[K, _]) HasKey(key K) bool

HasKey returns true if [key] is in the map.

func (*BiMap[_, V]) HasValue

func (m *BiMap[_, V]) HasValue(val V) bool

HasValue returns true if [val] is in the map.

func (*BiMap[K, _]) Keys

func (m *BiMap[K, _]) Keys() []K

Keys returns the keys of the map. The keys will be in an indeterminate order.

func (*BiMap[K, V]) Len

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

Len return the number of entries in this map.

func (*BiMap[K, V]) Put

func (m *BiMap[K, V]) Put(key K, val V) []Entry[K, V]

Put the key value pair into the map. If either [key] or [val] was previously in the map, the previous entries will be removed and returned.

Note: Unlike normal maps, it's possible that Put removes 0, 1, or 2 existing entries to ensure that mappings are one-to-one.

func (*BiMap[_, V]) Values

func (m *BiMap[_, V]) Values() []V

Values returns the values of the map. The values will be in an indeterminate order.

type Entry

type Entry[K, V any] struct {
	Key   K
	Value V
}

Jump to

Keyboard shortcuts

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