DEV Community

Discussion on: Data Structures: Bidirectional Map

Collapse
 
pretaporter profile image
Maksim

What do you mean by no link between each other? If you will have a look to implementation of deleteKey or deleteValue methods you will see, that it removes rows from both maps. The same behaviour for adding rows. I suppose the best example is encryption, when you create dictionary during encoding and later use it for decoding.

Collapse
 
varunpappu profile image
Varun Subramanian

What I meant was, you have mentioned one-to-one mapping and I don't see any explicit mapping between both the maps. Its two separate maps and one has {key, value} and other uses inverse of {key, value} and if updation fails in one then the data between maps are not pure.

Also what happens when the value is of non primitive type, how will this hold
good?
Also on performance wise, in what way it will improve when searching with a value?

Just curious and trying to understand it better.

Thread Thread
 
pretaporter profile image
Maksim

If you go over implementation, you will see that it is not possible that updation of one map can fail.

Should not be any issue with using non primitive values.

Complexity of searching key or value will be constant O(1);

Thread Thread
 
dean profile image
dean

I think the confusion comes from how errors occur - errors do not simply happen randomly, they happen for reasons. A map update should never result in an error occurring, maybe except some kind of fatal error like an out-of-memory error, in which case the program will not be able to work properly anyway.

Updating a map is (pretty much) as safe as creating an array - we don’t need, or want, to error check it.