ladvoc / BijectiveDictionary

A specialized dictionary structure offering bijective mapping and bidirectional O(1) access.
https://jacobgelman.com/posts/swift-bijective-dictionary
MIT License
4 stars 1 forks source link

Add BijectiveDictionary.build() #26

Open DandyLyons opened 2 months ago

DandyLyons commented 2 months ago

This PR is another potential solution to the uniquing problem.

In this approach, we do a best effort attempt to create a BijectiveDictionary from a Collection of left-right pairs.

If there are no conflicts, we return a .success with the completed BijectiveDictionary.

If there are conflicts, we insert as many non-conflicting values as possible. We collect conflicting values as an Array. Then we return a .conflicts with the partial BijectiveDictionary and the remaining conflicting Elements so that the user can handle the conflicts themselves.