Version: v1.18.1 Latest Latest

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

Go to latest
Published: Apr 18, 2022 License: BSD-2-Clause, ISC Imports: 5 Imported by: 39



Package hashbidimap implements a bidirectional map backed by two hashmaps.

A bidirectional map, or hash bag, is an associative data structure in which the (key,value) pairs form a one-to-one correspondence. Thus the binary relation is functional in each direction: value can also act as a key to key. A pair (a,b) thus provides a unique coupling between 'a' and 'b' so that 'b' can be found when 'a' is used as a key and 'a' can be found when 'b' is used as a key.

Elements are unordered in the map.

Structure is not thread safe.

Reference: https://en.wikipedia.org/wiki/Bidirectional_map



This section is empty.


This section is empty.


This section is empty.


type Map

type Map struct {
	// contains filtered or unexported fields

Map holds the elements in two hashmaps.

func New

func New() *Map

New instantiates a bidirectional map.

func (*Map) Clear

func (m *Map) Clear()

Clear removes all elements from the map.

func (*Map) Empty

func (m *Map) Empty() bool

Empty returns true if map does not contain any elements

func (*Map) FromJSON added in v1.9.0

func (m *Map) FromJSON(data []byte) error

FromJSON populates the map from the input JSON representation.

func (*Map) Get

func (m *Map) Get(key interface{}) (value interface{}, found bool)

Get searches the element in the map by key and returns its value or nil if key is not found in map. Second return parameter is true if key was found, otherwise false.

func (*Map) GetKey

func (m *Map) GetKey(value interface{}) (key interface{}, found bool)

GetKey searches the element in the map by value and returns its key or nil if value is not found in map. Second return parameter is true if value was found, otherwise false.

func (*Map) Keys

func (m *Map) Keys() []interface{}

Keys returns all keys (random order).

func (*Map) MarshalJSON added in v1.15.0

func (m *Map) MarshalJSON() ([]byte, error)

MarshalJSON @implements json.Marshaler

func (*Map) Put

func (m *Map) Put(key interface{}, value interface{})

Put inserts element into the map.

func (*Map) Remove

func (m *Map) Remove(key interface{})

Remove removes the element from the map by key.

func (*Map) Size

func (m *Map) Size() int

Size returns number of elements in the map.

func (*Map) String

func (m *Map) String() string

String returns a string representation of container

func (*Map) ToJSON added in v1.9.0

func (m *Map) ToJSON() ([]byte, error)

ToJSON outputs the JSON representation of the map.

func (*Map) UnmarshalJSON added in v1.15.0

func (m *Map) UnmarshalJSON(bytes []byte) error

UnmarshalJSON @implements json.Unmarshaler

func (*Map) Values

func (m *Map) Values() []interface{}

Values returns all values (random order).

Jump to

Keyboard shortcuts

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