swift-collections
swift-collections copied to clipboard
Bi-directional multimap?
Recently I encountered an issue where I needed a data structure that provided an efficient way of storing multiple values per key and being able to query for all keys that had a value.
A one way multi-value map can be implemented using Dictionary<Key, Set<Value>> but to get the keys that match values requires maintaining another Dictionary<Value, Set<Key>>. It would be nice if Swift had an efficient Bidirectional Multimap.