Move LRUMap to browser

This commit is contained in:
Daniel Imms
2019-06-15 23:51:36 -07:00
parent b5093e0c29
commit c0e27b98e8
3 changed files with 11 additions and 11 deletions
@@ -4,7 +4,7 @@
*/
import { assert } from 'chai';
import { LRUMap } from './LRUMap';
import { LRUMap } from 'browser/renderer/atlas/LRUMap';
describe('LRUMap', () => {
it('can be used to store and retrieve values', () => {
@@ -4,16 +4,16 @@
*/
interface ILinkedListNode<T> {
prev: ILinkedListNode<T>;
next: ILinkedListNode<T>;
key: number;
value: T;
prev: ILinkedListNode<T> | null;
next: ILinkedListNode<T> | null;
key: number | null;
value: T | null;
}
export class LRUMap<T> {
private _map: { [key: number]: ILinkedListNode<T> } = {};
private _head: ILinkedListNode<T> = null;
private _tail: ILinkedListNode<T> = null;
private _head: ILinkedListNode<T> | null = null;
private _tail: ILinkedListNode<T> | null = null;
private _nodePool: ILinkedListNode<T>[] = [];
public size: number = 0;
@@ -106,9 +106,9 @@ export class LRUMap<T> {
node.value = value;
} else if (this.size >= this.capacity) {
// we're out of space: recycle the head node, move it to the tail
node = this._head;
node = this._head!;
this._unlinkNode(node);
delete this._map[node.key];
delete this._map[node.key!];
node.key = key;
node.value = value;
this._map[key] = node;
@@ -117,7 +117,7 @@ export class LRUMap<T> {
const nodePool = this._nodePool;
if (nodePool.length > 0) {
// use a preallocated node if we can
node = nodePool.pop();
node = nodePool.pop()!;
node.key = key;
node.value = value;
} else {
+1 -1
View File
@@ -7,7 +7,7 @@ import { IGlyphIdentifier, ICharAtlasConfig } from './Types';
import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from './Constants';
import { BaseCharAtlas } from './BaseCharAtlas';
import { DEFAULT_ANSI_COLORS } from 'browser/ColorManager';
import { LRUMap } from './LRUMap';
import { LRUMap } from '../../browser/renderer/atlas/LRUMap';
import { isFirefox, isSafari } from 'common/Platform';
import { IColor } from 'browser/Types';