Skip to content

Commit e8a5e07

Browse files
committed
Avoid private fields in Queue
1 parent fab12be commit e8a5e07

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

src/queue.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* A fixed-size queue, backed by a circular buffer.
33
*/
44
export class Queue<T> {
5-
#buffer: (T | undefined)[] = []
6-
#head = 0
7-
#tail = 0
8-
#size = 0
5+
private buffer: (T | undefined)[] = []
6+
private head = 0
7+
private tail = 0
8+
private _size = 0
99

1010
constructor({initialItems = [], size}: { initialItems?: T[], size: number}) {
1111
if (size <= 0) {
@@ -16,47 +16,47 @@ export class Queue<T> {
1616
throw new Error('Initial items exceed queue capacity')
1717
}
1818

19-
this.#buffer = new Array(size).fill(undefined)
19+
this.buffer = new Array(size).fill(undefined)
2020

2121
for (let i = 0; i< initialItems.length; i++) {
22-
this.#buffer[i] = initialItems[i]
22+
this.buffer[i] = initialItems[i]
2323
}
2424

25-
this.#size = initialItems.length
26-
this.#tail = initialItems.length
25+
this._size = initialItems.length
26+
this.tail = initialItems.length
2727
}
2828

29-
get size() {
30-
return this.#size
29+
get size(): number {
30+
return this._size
3131
}
3232

3333
push(value: T) {
34-
if (this.#size === this.#buffer.length) {
34+
if (this._size === this.buffer.length) {
3535
throw new Error('Queue is full')
3636
}
3737

38-
this.#buffer[this.#tail] = value
39-
this.#tail = (this.#tail + 1) % this.#buffer.length
40-
this.#size++
38+
this.buffer[this.tail] = value
39+
this.tail = (this.tail + 1) % this.buffer.length
40+
this._size++
4141
}
4242

4343
shift(): T {
44-
if (this.#size === 0) {
44+
if (this._size === 0) {
4545
throw new Error('Queue is empty')
4646
}
4747

48-
const value = this.#buffer[this.#head]!
49-
this.#buffer[this.#head] = undefined
48+
const value = this.buffer[this.head]!
49+
this.buffer[this.head] = undefined
5050

51-
this.#head = (this.#head + 1) % this.#buffer.length
52-
this.#size--
51+
this.head = (this.head + 1) % this.buffer.length
52+
this._size--
5353

5454
return value
5555
}
5656

5757
clear() {
58-
this.#head = 0
59-
this.#tail = 0
60-
this.#size = 0
58+
this.head = 0
59+
this.tail = 0
60+
this._size = 0
6161
}
6262
}

vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ import { defineConfig } from 'vite'
55
export default defineConfig({
66
base: '/screens/',
77
plugins: [react()],
8+
build: {
9+
// minify: false
10+
}
811
})

0 commit comments

Comments
 (0)