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

bimap

package
v1.3.5 Latest Latest
Warning

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

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

Documentation

Overview

Package bimap provides a bidirectional map implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BiMap

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

BiMap is a bidirectional map that allows lookups in both directions.

func New

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

New creates a new empty BiMap.

func (*BiMap[K, V]) Delete

func (b *BiMap[K, V]) Delete(key K) bool

Delete removes the key-value pair by key.

func (*BiMap[K, V]) DeleteValue

func (b *BiMap[K, V]) DeleteValue(value V) bool

DeleteValue removes the key-value pair by value.

func (*BiMap[K, V]) Get

func (b *BiMap[K, V]) Get(key K) (V, bool)

Get returns the value associated with the key.

func (*BiMap[K, V]) GetKey

func (b *BiMap[K, V]) GetKey(value V) (K, bool)

GetKey returns the key associated with the value.

func (*BiMap[K, V]) GetValue

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

GetValue is an alias for Get.

func (*BiMap[K, V]) HasKey

func (b *BiMap[K, V]) HasKey(key K) bool

HasKey returns true if the key exists.

func (*BiMap[K, V]) HasValue

func (b *BiMap[K, V]) HasValue(value V) bool

HasValue returns true if the value exists.

func (*BiMap[K, V]) Keys

func (b *BiMap[K, V]) Keys() []K

Keys returns all keys in the BiMap.

func (*BiMap[K, V]) Len

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

Len returns the number of entries in the BiMap.

func (*BiMap[K, V]) Put

func (b *BiMap[K, V]) Put(key K, value V) bool

Put inserts a key-value pair into the BiMap. Returns true if the pair was inserted, false if either key or value already exists.

func (*BiMap[K, V]) Values

func (b *BiMap[K, V]) Values() []V

Values returns all values in the BiMap.

Jump to

Keyboard shortcuts

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