put method

void put(
  1. K key,
  2. V value
)

Associates value with key.

If either the key or value already existed, the previous relation is replaced in both directions.

Implementation

void put(K key, V value) {
  _map.update(
    key,
    (oldValue) {
      // Key existed → remove old reverse mapping.
      _map2.remove(oldValue);
      _map2[value] = key;
      return value;
    },
    ifAbsent: () {
      // New key.
      _map2[value] = key;
      return value;
    },
  );
}