"version": "4.0.16",
"exports": "./src/index.ts",
"publish": {
- "include": [
- "LICENSE",
- "README.md",
- "jsr.json",
- "src/**/*.ts"
- ]
+ "include": ["LICENSE", "README.md", "jsr.json", "src/**/*.ts"]
}
}
-import { defaultQueueSize, type FixedQueueNode, type IFixedQueue } from './utility-types.js'
+import {
+ defaultQueueSize,
+ type FixedQueueNode,
+ type IFixedQueue,
+} from './utility-types.js'
/**
* Fixed priority queue.
-import { defaultQueueSize, type FixedQueueNode, type IFixedQueue } from './utility-types.js'
+import {
+ defaultQueueSize,
+ type FixedQueueNode,
+ type IFixedQueue,
+} from './utility-types.js'
/**
* Fixed queue.
)
}
if (size < 0) {
- throw new RangeError(
- `Invalid fixed queue size: ${size.toString()} < 0`
- )
+ throw new RangeError(`Invalid fixed queue size: ${size.toString()} < 0`)
}
}
}
import { FixedPriorityQueue } from './fixed-priority-queue.js'
import { FixedQueue } from './fixed-queue.js'
-import { defaultBucketSize, type FixedQueueNode, type IFixedQueue, type PriorityQueueNode } from './utility-types.js'
+import {
+ defaultBucketSize,
+ type FixedQueueNode,
+ type IFixedQueue,
+ type PriorityQueueNode,
+} from './utility-types.js'
/**
* Priority queue.
this.priorityEnabled = enablePriority
let head: PriorityQueueNode<T>
let tail: PriorityQueueNode<T>
- let prevNode : PriorityQueueNode<T> | undefined
+ let prevNode: PriorityQueueNode<T> | undefined
let node: PriorityQueueNode<T> | undefined = this.tail
let buckets = 0
while (node != null) {
}
}
- private getPriorityQueueNode (nodeArray?: FixedQueueNode<T>[]): PriorityQueueNode<T> {
+ private getPriorityQueueNode (
+ nodeArray?: FixedQueueNode<T>[]
+ ): PriorityQueueNode<T> {
let fixedQueue: IFixedQueue<T>
if (this.priorityEnabled) {
fixedQueue = new FixedPriorityQueue(this.bucketSize)
* Checks if the fixed queue is empty.
* @returns `true` if the fixed queue is empty, `false` otherwise.
*/
- empty(): boolean
+ empty: () => boolean
/**
* Checks if the fixed queue is full.
* @returns `true` if the fixed queue is full, `false` otherwise.
*/
- full(): boolean
+ full: () => boolean
/**
* Enqueue data into the fixed queue.
* @param data - Data to enqueue.
* @returns The new size of the fixed queue.
* @throws If the fixed queue is full.
*/
- enqueue (data: T, priority?: number): number
+ enqueue: (data: T, priority?: number) => number
/**
* Gets data from the fixed queue.
* @param index - The index of the data to get.
* @returns The data at the index or `undefined` if the fixed queue is empty or the index is out of bounds.
*/
- get (index: number): T | undefined
+ get: (index: number) => T | undefined
/**
* Dequeue data from the fixed queue.
* @returns The dequeued data or `undefined` if the fixed queue is empty.
*/
- dequeue (): T | undefined
+ dequeue: () => T | undefined
/**
* Clears the fixed queue.
*/
- clear (): void
+ clear: () => void
/**
* Returns an iterator for the fixed queue.
* @returns An iterator for the fixed queue.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
*/
- [Symbol.iterator] (): Iterator<T>
+ [Symbol.iterator]: () => Iterator<T>
}
/**
import { expect } from 'expect'
-import {
- FixedPriorityQueue,
-} from '../lib/fixed-priority-queue.cjs'
+import { FixedPriorityQueue } from '../lib/fixed-priority-queue.cjs'
import { defaultQueueSize } from '../lib/utility-types.cjs'
describe('Fixed priority queue test suite', () => {
import { expect } from 'expect'
-import {
- FixedQueue,
-} from '../lib/fixed-queue.cjs'
+import { FixedQueue } from '../lib/fixed-queue.cjs'
import { defaultQueueSize } from '../lib/utility-types.cjs'
describe('Fixed queue test suite', () => {
expect(fixedQueue.start).toBe(0)
expect(fixedQueue.size).toBe(1)
expect(rtSize).toBe(fixedQueue.size)
- expect(fixedQueue.nodeArray).toMatchObject([
- { data: 1, priority: 0 },
- ])
+ expect(fixedQueue.nodeArray).toMatchObject([{ data: 1, priority: 0 }])
expect(fixedQueue.capacity).toBe(queueSize)
rtSize = fixedQueue.enqueue(2)
expect(fixedQueue.start).toBe(0)