Last Updated: February 25, 2016
·
810
· passcod

DoubleMap: a value<—>value data structure

I couldn't find anything of the sort, so I rolled my own. DoubleMap is a value<—>value data structure, and here is a first implementation in Go. Usage:

import "github.com/passcod/double-map"

Creation

dm := doublemap.New()

Add / Set

dm.Add("abcde", -0.456)

Access

dm.GetFromA("abcde") //=> -0.456
dm.GetFromB(-0.456)  //=> "abcde"

dm.GetFromEither("abcde") //=> -0.456
dm.GetFromEither(-0.456)  //=> "abcde"

In case of pairs with common members:

dm.Add("I", "me")
dm.Add("I", "myself")

dm.GetFromA("I")      //=> "me"
dm.GetFromB("me")     //=> "I"
dm.GetFromB("myself") //=> "I"

Delete

Not implemented (yet?)

Dump

dm.Dump() // Prints structure to STDOUT