copy method

LruCache<K, V> copy()

Shallow clone; values themselves are not copied.

Implementation

LruCache<K, V> copy() {
  final clone = LruCache<K, V>(capacity: capacity, onEvict: onEvict);
  for (var link = _head.next; link != _head; link = link.next) {
    final node = link as _LruNode<K, V>;
    final copy = _LruNode<K, V>(node.key, node.value);
    clone._nodes[node.key] = copy;
    clone._linkNewest(copy);
  }
  return clone;
}