Move LRUMap to browser
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { LRUMap } from './LRUMap';
|
import { LRUMap } from 'browser/renderer/atlas/LRUMap';
|
||||||
|
|
||||||
describe('LRUMap', () => {
|
describe('LRUMap', () => {
|
||||||
it('can be used to store and retrieve values', () => {
|
it('can be used to store and retrieve values', () => {
|
||||||
@@ -4,16 +4,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
interface ILinkedListNode<T> {
|
interface ILinkedListNode<T> {
|
||||||
prev: ILinkedListNode<T>;
|
prev: ILinkedListNode<T> | null;
|
||||||
next: ILinkedListNode<T>;
|
next: ILinkedListNode<T> | null;
|
||||||
key: number;
|
key: number | null;
|
||||||
value: T;
|
value: T | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LRUMap<T> {
|
export class LRUMap<T> {
|
||||||
private _map: { [key: number]: ILinkedListNode<T> } = {};
|
private _map: { [key: number]: ILinkedListNode<T> } = {};
|
||||||
private _head: ILinkedListNode<T> = null;
|
private _head: ILinkedListNode<T> | null = null;
|
||||||
private _tail: ILinkedListNode<T> = null;
|
private _tail: ILinkedListNode<T> | null = null;
|
||||||
private _nodePool: ILinkedListNode<T>[] = [];
|
private _nodePool: ILinkedListNode<T>[] = [];
|
||||||
public size: number = 0;
|
public size: number = 0;
|
||||||
|
|
||||||
@@ -106,9 +106,9 @@ export class LRUMap<T> {
|
|||||||
node.value = value;
|
node.value = value;
|
||||||
} else if (this.size >= this.capacity) {
|
} else if (this.size >= this.capacity) {
|
||||||
// we're out of space: recycle the head node, move it to the tail
|
// we're out of space: recycle the head node, move it to the tail
|
||||||
node = this._head;
|
node = this._head!;
|
||||||
this._unlinkNode(node);
|
this._unlinkNode(node);
|
||||||
delete this._map[node.key];
|
delete this._map[node.key!];
|
||||||
node.key = key;
|
node.key = key;
|
||||||
node.value = value;
|
node.value = value;
|
||||||
this._map[key] = node;
|
this._map[key] = node;
|
||||||
@@ -117,7 +117,7 @@ export class LRUMap<T> {
|
|||||||
const nodePool = this._nodePool;
|
const nodePool = this._nodePool;
|
||||||
if (nodePool.length > 0) {
|
if (nodePool.length > 0) {
|
||||||
// use a preallocated node if we can
|
// use a preallocated node if we can
|
||||||
node = nodePool.pop();
|
node = nodePool.pop()!;
|
||||||
node.key = key;
|
node.key = key;
|
||||||
node.value = value;
|
node.value = value;
|
||||||
} else {
|
} else {
|
||||||
@@ -7,7 +7,7 @@ import { IGlyphIdentifier, ICharAtlasConfig } from './Types';
|
|||||||
import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from './Constants';
|
import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from './Constants';
|
||||||
import { BaseCharAtlas } from './BaseCharAtlas';
|
import { BaseCharAtlas } from './BaseCharAtlas';
|
||||||
import { DEFAULT_ANSI_COLORS } from 'browser/ColorManager';
|
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 { isFirefox, isSafari } from 'common/Platform';
|
||||||
import { IColor } from 'browser/Types';
|
import { IColor } from 'browser/Types';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user