Skip to content

Commit b548fd0

Browse files
committed
Remove unused queue methods
1 parent 55310e1 commit b548fd0

File tree

1 file changed

+0
-57
lines changed

1 file changed

+0
-57
lines changed

src/queue.ts

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ export class Queue<T> {
55
#capacityMask = 0b11;
66
#list: (T | undefined)[] = new Array(this.#capacityMask + 1);
77

8-
/** Returns the capacity of the queue. That is, that of the inner buffer. */
9-
get capacity() {
10-
return this.#list.length;
11-
}
12-
138
/** Returns the current number of elements in the queue. */
149
get length() {
1510
return this.#head <= this.#tail
@@ -22,11 +17,6 @@ export class Queue<T> {
2217
return this.#head === this.#tail;
2318
}
2419

25-
/** Performs a "soft" clear. This does **not** reset capacity. */
26-
clear() {
27-
this.#head = this.#tail = 0;
28-
}
29-
3020
/** Inserts item to first slot. Returns the new length of the deque. */
3121
unshift(item: T) {
3222
const len = this.#list.length;
@@ -81,53 +71,6 @@ export class Queue<T> {
8171
return this.#capacityMask + 1 - (this.#head - this.#tail);
8272
}
8373

84-
/** Removes and returns the last element. */
85-
pop() {
86-
if (this.empty) return;
87-
88-
const tail = this.#tail;
89-
const len = this.#list.length;
90-
this.#tail = (tail - 1 + len) & this.#capacityMask;
91-
92-
const item = this.#list[this.#tail];
93-
this.#list[this.#tail] = undefined;
94-
95-
if (this.#head < 2 && tail > 10000 && tail <= len >>> 2) this.shrinkArray();
96-
97-
return item;
98-
}
99-
100-
/** View the item at the specific index (without removing). */
101-
at(index: number) {
102-
// Disallow out of bounds access
103-
const len = this.length;
104-
if (index >= len || index < -len) return;
105-
106-
// Wrap-around index
107-
if (index < 0) index += len;
108-
index = (this.#head + index) & this.#capacityMask;
109-
110-
return this.#list[index];
111-
}
112-
113-
*[Symbol.iterator]() {
114-
const head = this.#head;
115-
const tail = this.#tail;
116-
117-
// Simply yield elements from left to right
118-
if (head <= tail) {
119-
for (let i = head; i < tail; ++i) yield this.#list[i];
120-
return;
121-
}
122-
123-
// Yield elements from the head to the end
124-
const capacity = this.capacity;
125-
for (let i = head; i < capacity; ++i) yield this.#list[i];
126-
127-
// Then, wrap around and yield elements from start to tail
128-
for (let i = 0; i < tail; ++i) yield this.#list[i];
129-
}
130-
13174
private shrinkArray() {
13275
this.#list.length >>>= 1;
13376
this.#capacityMask >>>= 1;

0 commit comments

Comments
 (0)