@@ -5,11 +5,6 @@ export class Queue<T> {
5
5
#capacityMask = 0b11 ;
6
6
#list: ( T | undefined ) [ ] = new Array ( this . #capacityMask + 1 ) ;
7
7
8
- /** Returns the capacity of the queue. That is, that of the inner buffer. */
9
- get capacity ( ) {
10
- return this . #list. length ;
11
- }
12
-
13
8
/** Returns the current number of elements in the queue. */
14
9
get length ( ) {
15
10
return this . #head <= this . #tail
@@ -22,11 +17,6 @@ export class Queue<T> {
22
17
return this . #head === this . #tail;
23
18
}
24
19
25
- /** Performs a "soft" clear. This does **not** reset capacity. */
26
- clear ( ) {
27
- this . #head = this . #tail = 0 ;
28
- }
29
-
30
20
/** Inserts item to first slot. Returns the new length of the deque. */
31
21
unshift ( item : T ) {
32
22
const len = this . #list. length ;
@@ -81,53 +71,6 @@ export class Queue<T> {
81
71
return this . #capacityMask + 1 - ( this . #head - this . #tail) ;
82
72
}
83
73
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
-
131
74
private shrinkArray ( ) {
132
75
this . #list. length >>>= 1 ;
133
76
this . #capacityMask >>>= 1 ;
0 commit comments