1 |
|
2 |
|
3 | import { __values } from "tslib";
|
4 | var DoubleLinkedNode = (function () {
|
5 | function DoubleLinkedNode(keyVal) {
|
6 | this.key = keyVal ? keyVal : '';
|
7 | this.prevNode = null;
|
8 | this.nextNode = null;
|
9 | }
|
10 | return DoubleLinkedNode;
|
11 | }());
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var CacheList = (function () {
|
24 | |
25 |
|
26 |
|
27 | function CacheList() {
|
28 | this.head = new DoubleLinkedNode();
|
29 | this.tail = new DoubleLinkedNode();
|
30 | this.hashtable = {};
|
31 | this.length = 0;
|
32 | this.head.nextNode = this.tail;
|
33 | this.tail.prevNode = this.head;
|
34 | }
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 | CacheList.prototype.insertNodeToHead = function (node) {
|
41 | var tmp = this.head.nextNode;
|
42 | this.head.nextNode = node;
|
43 | node.nextNode = tmp;
|
44 | node.prevNode = this.head;
|
45 | tmp.prevNode = node;
|
46 | this.length = this.length + 1;
|
47 | };
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | CacheList.prototype.removeNode = function (node) {
|
54 | node.prevNode.nextNode = node.nextNode;
|
55 | node.nextNode.prevNode = node.prevNode;
|
56 | node.prevNode = null;
|
57 | node.nextNode = null;
|
58 | this.length = this.length - 1;
|
59 | };
|
60 | |
61 |
|
62 |
|
63 | CacheList.prototype.isEmpty = function () {
|
64 | return this.length === 0;
|
65 | };
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 | CacheList.prototype.refresh = function (key) {
|
72 | var node = this.hashtable[key];
|
73 | this.removeNode(node);
|
74 | this.insertNodeToHead(node);
|
75 | };
|
76 | |
77 |
|
78 |
|
79 |
|
80 |
|
81 | CacheList.prototype.insertItem = function (key) {
|
82 | var node = new DoubleLinkedNode(key);
|
83 | this.hashtable[key] = node;
|
84 | this.insertNodeToHead(node);
|
85 | };
|
86 | |
87 |
|
88 |
|
89 | CacheList.prototype.getLastItem = function () {
|
90 | return this.tail.prevNode.key;
|
91 | };
|
92 | |
93 |
|
94 |
|
95 |
|
96 | CacheList.prototype.removeItem = function (key) {
|
97 | var removedItem = this.hashtable[key];
|
98 | this.removeNode(removedItem);
|
99 | delete this.hashtable[key];
|
100 | };
|
101 | |
102 |
|
103 |
|
104 | CacheList.prototype.getSize = function () {
|
105 | return this.length;
|
106 | };
|
107 | |
108 |
|
109 |
|
110 |
|
111 | CacheList.prototype.containsKey = function (key) {
|
112 | return key in this.hashtable;
|
113 | };
|
114 | |
115 |
|
116 |
|
117 | CacheList.prototype.clearList = function () {
|
118 | var e_1, _a;
|
119 | try {
|
120 | for (var _b = __values(Object.keys(this.hashtable)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
121 | var key = _c.value;
|
122 | if (this.hashtable.hasOwnProperty(key)) {
|
123 | delete this.hashtable[key];
|
124 | }
|
125 | }
|
126 | }
|
127 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
128 | finally {
|
129 | try {
|
130 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
131 | }
|
132 | finally { if (e_1) throw e_1.error; }
|
133 | }
|
134 | this.head.nextNode = this.tail;
|
135 | this.tail.prevNode = this.head;
|
136 | this.length = 0;
|
137 | };
|
138 | |
139 |
|
140 |
|
141 | CacheList.prototype.getKeys = function () {
|
142 | return Object.keys(this.hashtable);
|
143 | };
|
144 | |
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | CacheList.prototype.isHeadNode = function (key) {
|
151 | var node = this.hashtable[key];
|
152 | return node.prevNode === this.head;
|
153 | };
|
154 | |
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | CacheList.prototype.isTailNode = function (key) {
|
161 | var node = this.hashtable[key];
|
162 | return node.nextNode === this.tail;
|
163 | };
|
164 | return CacheList;
|
165 | }());
|
166 | export default CacheList;
|
167 |
|
\ | No newline at end of file |