Rename _ol_structs_LRUCache_ to LRUCache
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @module ol/TileCache
|
||||
*/
|
||||
import {inherits} from './index.js';
|
||||
import _ol_structs_LRUCache_ from './structs/LRUCache.js';
|
||||
import LRUCache from './structs/LRUCache.js';
|
||||
import _ol_tilecoord_ from './tilecoord.js';
|
||||
|
||||
/**
|
||||
@@ -13,11 +13,11 @@ import _ol_tilecoord_ from './tilecoord.js';
|
||||
*/
|
||||
var _ol_TileCache_ = function(opt_highWaterMark) {
|
||||
|
||||
_ol_structs_LRUCache_.call(this, opt_highWaterMark);
|
||||
LRUCache.call(this, opt_highWaterMark);
|
||||
|
||||
};
|
||||
|
||||
inherits(_ol_TileCache_, _ol_structs_LRUCache_);
|
||||
inherits(_ol_TileCache_, LRUCache);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import _ol_css_ from '../css.js';
|
||||
import {createCanvasContext2D} from '../dom.js';
|
||||
import _ol_obj_ from '../obj.js';
|
||||
import _ol_structs_LRUCache_ from '../structs/LRUCache.js';
|
||||
import LRUCache from '../structs/LRUCache.js';
|
||||
import _ol_transform_ from '../transform.js';
|
||||
var _ol_render_canvas_ = {};
|
||||
|
||||
@@ -96,7 +96,7 @@ _ol_render_canvas_.defaultLineWidth = 1;
|
||||
/**
|
||||
* @type {ol.structs.LRUCache.<HTMLCanvasElement>}
|
||||
*/
|
||||
_ol_render_canvas_.labelCache = new _ol_structs_LRUCache_();
|
||||
_ol_render_canvas_.labelCache = new LRUCache();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ import _ol_render_webgl_Immediate_ from '../../render/webgl/Immediate.js';
|
||||
import _ol_renderer_Map_ from '../Map.js';
|
||||
import _ol_renderer_Type_ from '../Type.js';
|
||||
import _ol_source_State_ from '../../source/State.js';
|
||||
import _ol_structs_LRUCache_ from '../../structs/LRUCache.js';
|
||||
import LRUCache from '../../structs/LRUCache.js';
|
||||
import _ol_structs_PriorityQueue_ from '../../structs/PriorityQueue.js';
|
||||
import _ol_webgl_ from '../../webgl.js';
|
||||
import _ol_webgl_Context_ from '../../webgl/Context.js';
|
||||
@@ -101,7 +101,7 @@ var _ol_renderer_webgl_Map_ = function(container, map) {
|
||||
* @private
|
||||
* @type {ol.structs.LRUCache.<ol.WebglTextureCacheEntry|null>}
|
||||
*/
|
||||
this.textureCache_ = new _ol_structs_LRUCache_();
|
||||
this.textureCache_ = new LRUCache();
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
||||
@@ -17,7 +17,7 @@ import EventType from '../events/EventType.js';
|
||||
* @template T
|
||||
* @param {number=} opt_highWaterMark High water mark.
|
||||
*/
|
||||
var _ol_structs_LRUCache_ = function(opt_highWaterMark) {
|
||||
var LRUCache = function(opt_highWaterMark) {
|
||||
|
||||
EventTarget.call(this);
|
||||
|
||||
@@ -52,13 +52,13 @@ var _ol_structs_LRUCache_ = function(opt_highWaterMark) {
|
||||
|
||||
};
|
||||
|
||||
inherits(_ol_structs_LRUCache_, EventTarget);
|
||||
inherits(LRUCache, EventTarget);
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Can expire cache.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.canExpireCache = function() {
|
||||
LRUCache.prototype.canExpireCache = function() {
|
||||
return this.getCount() > this.highWaterMark;
|
||||
};
|
||||
|
||||
@@ -66,7 +66,7 @@ _ol_structs_LRUCache_.prototype.canExpireCache = function() {
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.clear = function() {
|
||||
LRUCache.prototype.clear = function() {
|
||||
this.count_ = 0;
|
||||
this.entries_ = {};
|
||||
this.oldest_ = null;
|
||||
@@ -79,7 +79,7 @@ _ol_structs_LRUCache_.prototype.clear = function() {
|
||||
* @param {string} key Key.
|
||||
* @return {boolean} Contains key.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.containsKey = function(key) {
|
||||
LRUCache.prototype.containsKey = function(key) {
|
||||
return this.entries_.hasOwnProperty(key);
|
||||
};
|
||||
|
||||
@@ -92,7 +92,7 @@ _ol_structs_LRUCache_.prototype.containsKey = function(key) {
|
||||
* @param {S=} opt_this The object to use as `this` in `f`.
|
||||
* @template S
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.forEach = function(f, opt_this) {
|
||||
LRUCache.prototype.forEach = function(f, opt_this) {
|
||||
var entry = this.oldest_;
|
||||
while (entry) {
|
||||
f.call(opt_this, entry.value_, entry.key_, this);
|
||||
@@ -105,7 +105,7 @@ _ol_structs_LRUCache_.prototype.forEach = function(f, opt_this) {
|
||||
* @param {string} key Key.
|
||||
* @return {T} Value.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.get = function(key) {
|
||||
LRUCache.prototype.get = function(key) {
|
||||
var entry = this.entries_[key];
|
||||
_ol_asserts_.assert(entry !== undefined,
|
||||
15); // Tried to get a value for a key that does not exist in the cache
|
||||
@@ -131,7 +131,7 @@ _ol_structs_LRUCache_.prototype.get = function(key) {
|
||||
* @param {string} key The entry key.
|
||||
* @return {T} The removed entry.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.remove = function(key) {
|
||||
LRUCache.prototype.remove = function(key) {
|
||||
var entry = this.entries_[key];
|
||||
_ol_asserts_.assert(entry !== undefined, 15); // Tried to get a value for a key that does not exist in the cache
|
||||
if (entry === this.newest_) {
|
||||
@@ -157,7 +157,7 @@ _ol_structs_LRUCache_.prototype.remove = function(key) {
|
||||
/**
|
||||
* @return {number} Count.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.getCount = function() {
|
||||
LRUCache.prototype.getCount = function() {
|
||||
return this.count_;
|
||||
};
|
||||
|
||||
@@ -165,7 +165,7 @@ _ol_structs_LRUCache_.prototype.getCount = function() {
|
||||
/**
|
||||
* @return {Array.<string>} Keys.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.getKeys = function() {
|
||||
LRUCache.prototype.getKeys = function() {
|
||||
var keys = new Array(this.count_);
|
||||
var i = 0;
|
||||
var entry;
|
||||
@@ -179,7 +179,7 @@ _ol_structs_LRUCache_.prototype.getKeys = function() {
|
||||
/**
|
||||
* @return {Array.<T>} Values.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.getValues = function() {
|
||||
LRUCache.prototype.getValues = function() {
|
||||
var values = new Array(this.count_);
|
||||
var i = 0;
|
||||
var entry;
|
||||
@@ -193,7 +193,7 @@ _ol_structs_LRUCache_.prototype.getValues = function() {
|
||||
/**
|
||||
* @return {T} Last value.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.peekLast = function() {
|
||||
LRUCache.prototype.peekLast = function() {
|
||||
return this.oldest_.value_;
|
||||
};
|
||||
|
||||
@@ -201,7 +201,7 @@ _ol_structs_LRUCache_.prototype.peekLast = function() {
|
||||
/**
|
||||
* @return {string} Last key.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.peekLastKey = function() {
|
||||
LRUCache.prototype.peekLastKey = function() {
|
||||
return this.oldest_.key_;
|
||||
};
|
||||
|
||||
@@ -210,7 +210,7 @@ _ol_structs_LRUCache_.prototype.peekLastKey = function() {
|
||||
* Get the key of the newest item in the cache. Throws if the cache is empty.
|
||||
* @return {string} The newest key.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.peekFirstKey = function() {
|
||||
LRUCache.prototype.peekFirstKey = function() {
|
||||
return this.newest_.key_;
|
||||
};
|
||||
|
||||
@@ -218,7 +218,7 @@ _ol_structs_LRUCache_.prototype.peekFirstKey = function() {
|
||||
/**
|
||||
* @return {T} value Value.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.pop = function() {
|
||||
LRUCache.prototype.pop = function() {
|
||||
var entry = this.oldest_;
|
||||
delete this.entries_[entry.key_];
|
||||
if (entry.newer) {
|
||||
@@ -237,7 +237,7 @@ _ol_structs_LRUCache_.prototype.pop = function() {
|
||||
* @param {string} key Key.
|
||||
* @param {T} value Value.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.replace = function(key, value) {
|
||||
LRUCache.prototype.replace = function(key, value) {
|
||||
this.get(key); // update `newest_`
|
||||
this.entries_[key].value_ = value;
|
||||
};
|
||||
@@ -247,7 +247,7 @@ _ol_structs_LRUCache_.prototype.replace = function(key, value) {
|
||||
* @param {string} key Key.
|
||||
* @param {T} value Value.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.set = function(key, value) {
|
||||
LRUCache.prototype.set = function(key, value) {
|
||||
_ol_asserts_.assert(!(key in this.entries_),
|
||||
16); // Tried to set a value for a key that is used already
|
||||
var entry = /** @type {ol.LRUCacheEntry} */ ({
|
||||
@@ -270,9 +270,9 @@ _ol_structs_LRUCache_.prototype.set = function(key, value) {
|
||||
/**
|
||||
* Prune the cache.
|
||||
*/
|
||||
_ol_structs_LRUCache_.prototype.prune = function() {
|
||||
LRUCache.prototype.prune = function() {
|
||||
while (this.canExpireCache()) {
|
||||
this.pop();
|
||||
}
|
||||
};
|
||||
export default _ol_structs_LRUCache_;
|
||||
export default LRUCache;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import _ol_structs_LRUCache_ from '../../../../src/ol/structs/LRUCache.js';
|
||||
import LRUCache from '../../../../src/ol/structs/LRUCache.js';
|
||||
|
||||
|
||||
describe('ol.structs.LRUCache', function() {
|
||||
@@ -13,7 +13,7 @@ describe('ol.structs.LRUCache', function() {
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
lruCache = new _ol_structs_LRUCache_();
|
||||
lruCache = new LRUCache();
|
||||
});
|
||||
|
||||
describe('empty cache', function() {
|
||||
@@ -164,7 +164,7 @@ describe('ol.structs.LRUCache', function() {
|
||||
|
||||
describe('#peekFirstKey()', function() {
|
||||
it('returns the newest key in the cache', function() {
|
||||
var cache = new _ol_structs_LRUCache_();
|
||||
var cache = new LRUCache();
|
||||
cache.set('oldest', 'oldest');
|
||||
cache.set('oldish', 'oldish');
|
||||
cache.set('newish', 'newish');
|
||||
@@ -173,13 +173,13 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
|
||||
it('works if the cache has one item', function() {
|
||||
var cache = new _ol_structs_LRUCache_();
|
||||
var cache = new LRUCache();
|
||||
cache.set('key', 'value');
|
||||
expect(cache.peekFirstKey()).to.eql('key');
|
||||
});
|
||||
|
||||
it('throws if the cache is empty', function() {
|
||||
var cache = new _ol_structs_LRUCache_();
|
||||
var cache = new LRUCache();
|
||||
expect(function() {
|
||||
cache.peekFirstKey();
|
||||
}).to.throwException();
|
||||
@@ -212,7 +212,7 @@ describe('ol.structs.LRUCache', function() {
|
||||
|
||||
describe('#remove()', function() {
|
||||
it('removes an item from the cache', function() {
|
||||
var cache = new _ol_structs_LRUCache_();
|
||||
var cache = new LRUCache();
|
||||
cache.set('oldest', 'oldest');
|
||||
cache.set('oldish', 'oldish');
|
||||
cache.set('newish', 'newish');
|
||||
@@ -224,7 +224,7 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
|
||||
it('works when removing the oldest item', function() {
|
||||
var cache = new _ol_structs_LRUCache_();
|
||||
var cache = new LRUCache();
|
||||
cache.set('oldest', 'oldest');
|
||||
cache.set('oldish', 'oldish');
|
||||
cache.set('newish', 'newish');
|
||||
@@ -237,7 +237,7 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
|
||||
it('works when removing the newest item', function() {
|
||||
var cache = new _ol_structs_LRUCache_();
|
||||
var cache = new LRUCache();
|
||||
cache.set('oldest', 'oldest');
|
||||
cache.set('oldish', 'oldish');
|
||||
cache.set('newish', 'newish');
|
||||
@@ -250,7 +250,7 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
|
||||
it('returns the removed item', function() {
|
||||
var cache = new _ol_structs_LRUCache_();
|
||||
var cache = new LRUCache();
|
||||
var item = {};
|
||||
cache.set('key', item);
|
||||
|
||||
@@ -259,7 +259,7 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
|
||||
it('throws if the key does not exist', function() {
|
||||
var cache = new _ol_structs_LRUCache_();
|
||||
var cache = new LRUCache();
|
||||
cache.set('foo', 'foo');
|
||||
cache.set('bar', 'bar');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user