DEV Community

Discussion on: Data Structures: Bidirectional Map

Collapse
 
eikooc profile image
Jamie Neubert Pedersen

Hi @pretaporter , thanks for the article. I want to discuss a part of the class if you are willing to. I believe in the set(k, v) that you should not look at the union in the if statement, but rather the intersection (&& vs. ||) as having either of them being defined without the other should rather be an error in the implementation. If that is true you should rather throw an error or something to show that the bi-directional map is malformed. Cheers.

Collapse
 
pretaporter profile image
Maksim

Sure, thanks for your point. Why do you think we should use intersection instead?
If we will use intersection, then will be possible situation like this:

xx.set('a', 'b');
xx.set('c', 'b');
xx.getKey('b'); // returns c
Enter fullscreen mode Exit fullscreen mode

It is not correct