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