Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1547)

Unified Diff: analyzer/lib/src/util/lru_map.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « analyzer/lib/src/util/asserts.dart ('k') | analyzer/lib/src/util/utilities_timing.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: analyzer/lib/src/util/lru_map.dart
diff --git a/analyzer/lib/src/util/lru_map.dart b/analyzer/lib/src/util/lru_map.dart
deleted file mode 100644
index 38ef8ff9d051929fe1e802013d939c36380bd834..0000000000000000000000000000000000000000
--- a/analyzer/lib/src/util/lru_map.dart
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library engine.utilities.lru_cache;
-
-import 'dart:collection';
-
-/**
- * This handler is notified when an item is evicted from the cache.
- */
-typedef EvictionHandler<K, V>(K key, V value);
-
-/**
- * A hash-table based cache implementation.
- *
- * When it reaches the specified number of items, the item that has not been
- * accessed (both get and put) recently is evicted.
- */
-class LRUMap<K, V> {
- final LinkedHashMap<K, V> _map = new LinkedHashMap<K, V>();
- final int _maxSize;
- final EvictionHandler _handler;
-
- LRUMap(this._maxSize, [this._handler]);
-
- /**
- * Returns the value for the given [key] or null if [key] is not
- * in the cache.
- */
- V get(K key) {
- V value = _map.remove(key);
- if (value != null) {
- _map[key] = value;
- }
- return value;
- }
-
- /**
- * Associates the [key] with the given [value].
- *
- * If the cache is full, an item that has not been accessed recently is
- * evicted.
- */
- void put(K key, V value) {
- _map.remove(key);
- _map[key] = value;
- if (_map.length > _maxSize) {
- K evictedKey = _map.keys.first;
- V evictedValue = _map.remove(evictedKey);
- if (_handler != null) {
- _handler(evictedKey, evictedValue);
- }
- }
- }
-
- /**
- * Removes the association for the given [key].
- */
- void remove(K key) {
- _map.remove(key);
- }
-}
« no previous file with comments | « analyzer/lib/src/util/asserts.dart ('k') | analyzer/lib/src/util/utilities_timing.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698