Invertable Dict structure?

Hello all. I was wondering if there is a “standard” implementation somewhere of an invertable lookup-table structure (i.e. a pair of Dicts, each the inverse of the other). Obviously this is trivial to implement using Dict, but I was wondering if there is a “standard” way of doing it. Thanks.


What you want is called a bidirectional map. I’m not aware of any Julia package for this, and google doesn’t turn up anything…

Hm, perhaps a PR to DataStructures would be welcome? I’m not personally aware whether there are any performance tricks involved in implementing this. We’d have to agree on the names for the inverseget methods. I suppose the reason this does not yet exist is because it is so trivial to do with two Dicts.

I think I would call it BiDict.

I for one would use this as well. I sometimes need to use the value of a Dict as a key (as well as the key as a key).

To be honest, when I use this I feel “dirty”; as if the only reason I am doing it is because my code is poorly designed. But I think that is just my imagination, because it definitely seems unavoidable in some circumstances.

Bah! Humbug!

I’ve used DataStructure stuff to realize I didn’t need them, to finally understand I did, to see the light that I don’t. But then I did.

1 Like