repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: code reformatting
[poolifier.git]
/
src
/
circular-buffer.ts
diff --git
a/src/circular-buffer.ts
b/src/circular-buffer.ts
index a56cd09d551e67cc865ac4e40950cb6988b76362..5015483b290055e1a78e961c248024625800b6d6 100644
(file)
--- a/
src/circular-buffer.ts
+++ b/
src/circular-buffer.ts
@@
-5,13
+5,12
@@
export const defaultBufferSize = 2048
/**
* Circular buffer designed for positive numbers.
/**
* Circular buffer designed for positive numbers.
- *
* @internal
*/
export class CircularBuffer {
private readIdx: number
private writeIdx: number
* @internal
*/
export class CircularBuffer {
private readIdx: number
private writeIdx: number
- private items: Float32Array
+ private
readonly
items: Float32Array
private readonly maxArrayIdx: number
public size: number
private readonly maxArrayIdx: number
public size: number
@@
-30,7
+29,6
@@
export class CircularBuffer {
/**
* Checks whether the buffer is empty.
/**
* Checks whether the buffer is empty.
- *
* @returns Whether the buffer is empty.
*/
public empty (): boolean {
* @returns Whether the buffer is empty.
*/
public empty (): boolean {
@@
-39,7
+37,6
@@
export class CircularBuffer {
/**
* Checks whether the buffer is full.
/**
* Checks whether the buffer is full.
- *
* @returns Whether the buffer is full.
*/
public full (): boolean {
* @returns Whether the buffer is full.
*/
public full (): boolean {
@@
-48,7
+45,6
@@
export class CircularBuffer {
/**
* Puts number into buffer.
/**
* Puts number into buffer.
- *
* @param number - Number to put into buffer.
*/
public put (number: number): void {
* @param number - Number to put into buffer.
*/
public put (number: number): void {
@@
-61,37
+57,41
@@
export class CircularBuffer {
/**
* Gets number from buffer.
/**
* Gets number from buffer.
- *
* @returns Number from buffer.
*/
public get (): number | undefined {
* @returns Number from buffer.
*/
public get (): number | undefined {
- const
data
= this.items[this.readIdx]
- if (
data
=== -1) {
+ const
number
= this.items[this.readIdx]
+ if (
number
=== -1) {
return
}
this.items[this.readIdx] = -1
this.readIdx = this.readIdx === this.maxArrayIdx ? 0 : this.readIdx + 1
--this.size
return
}
this.items[this.readIdx] = -1
this.readIdx = this.readIdx === this.maxArrayIdx ? 0 : this.readIdx + 1
--this.size
- return
data
+ return
number
}
/**
* Returns buffer as numbers' array.
}
/**
* Returns buffer as numbers' array.
- *
* @returns Numbers' array.
*/
public toArray (): number[] {
return Array.from(this.items.filter(item => item !== -1))
}
* @returns Numbers' array.
*/
public toArray (): number[] {
return Array.from(this.items.filter(item => item !== -1))
}
+ /**
+ * Checks the buffer size.
+ * @param size - Buffer size.
+ */
private checkSize (size: number): void {
if (!Number.isSafeInteger(size)) {
throw new TypeError(
private checkSize (size: number): void {
if (!Number.isSafeInteger(size)) {
throw new TypeError(
- `Invalid circular buffer size:
${size}
is not an integer`
+ `Invalid circular buffer size:
'${size.toString()}'
is not an integer`
)
}
if (size < 0) {
)
}
if (size < 0) {
- throw new RangeError(`Invalid circular buffer size: ${size} < 0`)
+ throw new RangeError(
+ `Invalid circular buffer size: ${size.toString()} < 0`
+ )
}
}
}
}
}
}