Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • What are you using the dictionary for? Do you even need the surjection part of your dictionary? That said, the code in my answer handles all your cases (implementing IDictonary, providing bijection and handling cases where TKey == TValue). Commented Jul 4, 2010 at 10:49
  • 2
    If you want bijection to itself for TKey == TValue, you could use SelfBijectiveDictionary<T> : BijectiveDictionary<T, T> {...} and overriding it's Add method and checking first if (base.Contains(key) || this.Reversed.Contains(value)) throw .... The classes should be named differently anyway, because one is bijective X->Y and the other S->S (bijective to itself). Commented Jul 6, 2010 at 17:54
  • Pointing out the difference between X->Y and S->S helps a lot. Sorry for all the confusion! And yes - I'm making two separately named Dictionaries for them. Thanks for your help. Commented Jul 6, 2010 at 19:11