bimap

package module
v0.0.0-...-12c6dd5 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: MIT Imports: 1 Imported by: 0

README

bimap

GoDoc

A bidirectional map written in Go

Installation

go get github.com/vishalkuo/bimap

Usage

import "github.com/vishalkuo/bimap"

biMap := bimap.NewBiMap()
biMap.Insert("key", "value")
val, ok := biMap.GetInverse("value") // val should be "key", ok should be true
biMap.Delete("key")
biMap.Size() // == 0

biMap2 := bimap.NewBiMap()
biMap2.Insert("key", 1) // Notice different types
val, ok := biMap2.Get("key") // Returns 1
val, ok = biMap2.GetInverse(1) // Returns "key"

Documentation

Overview

Package bimap provides a threadsafe bidirectional map

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BiMap

type BiMap struct {
	Value
	// contains filtered or unexported fields
}

BiMapSafe is a BiMap, is thread safe and supports immutability

func NewBiMap

func NewBiMap() *BiMap

NewBiMap returns a an empty, mutable, biMap

func (*BiMap) Delete

func (b *BiMap) Delete(k interface{})

Delete removes a key-value pair from the BiMap for a given key. Returns if the key doesn't exist

func (*BiMap) DeleteInverse

func (b *BiMap) DeleteInverse(v interface{})

DeleteInverse emoves a key-value pair from the BiMap for a given value. Returns if the value doesn't exist

func (*BiMap) Exists

func (b *BiMap) Exists(k interface{}) bool

Exists checks whether or not a key exists in the BiMap

func (*BiMap) ExistsInverse

func (b *BiMap) ExistsInverse(k interface{}) bool

ExistsInverse checks whether or not a value exists in the BiMap

func (*BiMap) Get

func (b *BiMap) Get(k interface{}) (interface{}, bool)

Get returns the value for a given key in the BiMap and whether or not the element was present.

func (*BiMap) GetForwardMap

func (b *BiMap) GetForwardMap() map[interface{}]interface{}

GetForwardMap returns a regular go map mapping from the BiMap's keys to its values

func (*BiMap) GetInverse

func (b *BiMap) GetInverse(v interface{}) (interface{}, bool)

GetInverse returns the key for a given value in the BiMap and whether or not the element was present.

func (*BiMap) GetInverseMap

func (b *BiMap) GetInverseMap() map[interface{}]interface{}

GetInverseMap returns a regular go map mapping from the BiMap's values to its keys

func (*BiMap) Insert

func (b *BiMap) Insert(k interface{}, v interface{})

Insert puts a key and value into the BiMap, provided its mutable. Also creates the reverse mapping from value to key.

func (*BiMap) Lock

func (b *BiMap) Lock()

Lock manually locks the BiMap's mutex

func (*BiMap) MakeImmutable

func (b *BiMap) MakeImmutable()

MakeImmutable freezes the BiMap preventing any further write actions from taking place

func (*BiMap) Size

func (b *BiMap) Size() int

Size returns the number of elements in the bimap

func (*BiMap) Unlock

func (b *BiMap) Unlock()

Unlock manually unlocks the BiMap's mutex

type Value

type Value struct {
	// contains filtered or unexported fields
}

BiMap is a bi-directional hashmap.

Jump to

Keyboard shortcuts

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