trimToSize method

void trimToSize(
  1. int maxSize
)

Implementation

void trimToSize(int maxSize) {
  while (true) {
    K key;
    V value;

    assert(size >= 0 && (_map.isNotEmpty || size == 0));

    if (size <= maxSize) {
      break;
    }

    MapEntry<K, V>? toEvict;
    for (var entry in _map.entries) {
      toEvict = entry;
    }

    if (toEvict == null) {
      break;
    }

    key = toEvict.key;
    value = toEvict.value;
    _map.remove(key);
    _size -= _safeSizeOf(key, value);
  }
}