atlas

package module
v0.0.0-...-bdd6fc6 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 4 Imported by: 0

README

Atlas

Atlas is a collection of useful map data structure to make things easier when working with maps in Go.

Installation

go get github.com/CaioTeixeira95/atlas

Maps

Below you find a list of data structures of this module.

BiMap

BiMap is a bidirectional map that gives you the ability to search by key or value.

biMap := atlas.NewBiMap[string, string]()
err := biMap.Set("myKey", "myValue")
if err != nil {
    log.Fatal(err)
}

value, ok := biMap.Get("myKey")
fmt.Println(value, ok) // myValue true

key, ok := biMap.GetInverse("myValue")
fmt.Println(key, ok) // myKey true
FrozenMap

FrozenMap gives you a map where the keys are immutable. It returns error when you try to overwrite a key's value.

frozenMap := atlas.NewFrozenMap[string, int64]()
err := frozenMap.Set("key", 10)
if err != nil {
    log.Fatal(err)
}
err = frozenMap.Set("key", 24)
fmt.Println(errors.Is(err, atlas.ErrKeyAlreadySet)) // true

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicatedKey   = errors.New("duplicated key")
	ErrDuplicatedValue = errors.New("duplicated value")
)
View Source
var (
	ErrKeyAlreadySet = errors.New("key already set")
)

Functions

func NewBiMap

func NewBiMap[K comparable, V comparable]() *biMap[K, V]

NewBiMap returns a new bidirectional map.

func NewDefaultMap

func NewDefaultMap[K comparable, V any](genFunc func() (V, error)) *defaultMap[K, V]

func NewFrozenMap

func NewFrozenMap[K comparable, V any]() *frozenMap[K, V]

Types

This section is empty.

Jump to

Keyboard shortcuts

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