Table of contents
- A one-to-one relationship between "left" and "right" is maintained when updating, adding and deleting.
- Quick modification and access to "left" and "right" are possible.
- Duplication is not allowed for the same "left" and "right".
There is basically no priority between "left" and "right". At the developer's discretion, they can be prioritized conceptually.
-
left: This value is used as the
left
key in the BiMap. Eachleft
can only be mapped to a singleright
. You can use theleft
to look up or delete the correspondingright
. -
right: This value is used as the
right
key in the BiMap. Eachright
can only be mapped to a singleleft
. You can use theright
to look up or delete the correspondingleft
.
- Set type of left and right with generic
<L, R>
. - Default type is any.
const myMap = new BiMap<string, number>();
- Add or update the pair.
myMap.set("a", 10);
- Delete the pair.
myMap.set("a", 10);
myMap.set("b", 5);
myMap.deleteByLeft("a"); // delete "a" & 10
myMap.deleteByRight(5); // delete "b" & 5
- Gets the value in the opposite direction.
myMap.set("a", 10);
myMap.getByLeft("a"); // 10
myMap.getByRight(10); // a
- Check if a value exists.
const myMap = new BiMap<string, number>();
myMap.set("a", 10);
myMap.hasByLeft("a"); // true
myMap.hasByRight(20); // false
- Clear all data.
myMap.clear();
- One pair size.
const myMap = new BiMap<string, number>();
myMap.set("a", 10);
myMap.set("b", 5);
myMap.size(); // 2
- Get "readonly" member variables.
- Modification may result in unexpected behavior.
myMap.getLeftToRight();
myMap.getRightToLeft();