154
throw new Error('not supported');
155
}
157
>
this._size = 1;
158
>
this.head = this.tail = this.cursor = {
159
>
value: history[0],
160
>
previous: undefined,
161
>
next: undefined
162
>
};
163
>
164
>
this.valueSet = new SetWithKey<T>([history[0]], identityFn);
165
>
for (let i = 1; i < history.length; i++) {
166
>
this.add(history[i]);
167
>
}
168
}
169
170
add(value: T): void {
172
>
value,
173
>
previous: this.tail,
174
>
next: undefined
175
>
};
176
>
177
>
this.tail.next = node;
178
>
this.tail = node;
179
>
this.cursor = this.tail;
180
>
this._size++;
181
>
182
>
if (this.valueSet.has(value)) {
183
this._deleteFromList(value);
185
>
this.valueSet.add(value);
186
>
}
187
>
188
>
while (this._size > this.capacity) {
189
this.valueSet.delete(this.head.value);
190