operator []= method

  1. @override
void operator []= (K key, V value)
override

If key already exists, promotes it to the MRU position & assigns value.

Otherwise, adds key and value to the MRU position. If length exceeds maximumSize while adding, removes the LRU position.

Implementation

@override
void operator []=(K key, V value) {
  // Add this item to the MRU position.
  _insertMru(_createEntry(key, value));

  // Remove the LRU item if the size would be exceeded by adding this item.
  if (length > maximumSize) {
    assert(length == maximumSize + 1);
    _removeLru();
  }
}