Skip to content

Repository files navigation

logo

A bi-directional dictionary/map for the Swift programming language.

Usage:

var biDict = BiDictionary<String, String>()
biDict[key: "foo"] = "bar"

let value = biDict[key: "foo"]
let key = biDict[value: "bar"]

Because the mapping is one-to-one in both directions, assigning a value that another key already holds displaces that key — and the same the other way round. Last write wins, as it does with Dictionary:

biDict[key: "foo"] = "bar"
biDict[key: "baz"] = "bar"   // "foo" no longer has a value; "bar" now belongs to "baz"

biDict[key: "baz"] = nil     // removes the pairing from both directions

If you need the strict behaviour instead — refuse a write that would displace an existing pairing — look the value up first and branch on the result.

About

A bi-directional dictionary/map for the Swift programming language.

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages