@algorithm.ts/circular-queue
Advanced tools
Comparing version 1.0.24 to 2.0.0-alpha.0
@@ -13,2 +13,3 @@ 'use strict'; | ||
init, | ||
free, | ||
front, | ||
@@ -32,2 +33,9 @@ end, | ||
} | ||
function free() { | ||
_MAX_SIZE = 0; | ||
_size = 0; | ||
_queue.length = 0; | ||
_startIndex = -1; | ||
_endIndex = -1; | ||
} | ||
function front() { | ||
@@ -34,0 +42,0 @@ return _size === 0 ? undefined : _queue[_startIndex]; |
@@ -9,2 +9,3 @@ function createCircularQueue() { | ||
init, | ||
free, | ||
front, | ||
@@ -28,2 +29,9 @@ end, | ||
} | ||
function free() { | ||
_MAX_SIZE = 0; | ||
_size = 0; | ||
_queue.length = 0; | ||
_startIndex = -1; | ||
_endIndex = -1; | ||
} | ||
function front() { | ||
@@ -30,0 +38,0 @@ return _size === 0 ? undefined : _queue[_startIndex]; |
@@ -1,4 +0,67 @@ | ||
import type { CircularQueue } from './types'; | ||
export * from './types'; | ||
/** | ||
* Circular queue. | ||
* | ||
* Circular queue is a queue structure, the main purpose of its design is to | ||
* reuse space as much as possible on the basis of ordinary queues. Circular | ||
* queues usually need to specify the maximum volume C of the collector. If the | ||
* number of elements in the queue exceeds C, only the most recent C elements | ||
* are kept in the queue. Other operations are the same as ordinary queues. | ||
*/ | ||
export interface ICircularQueue<T> { | ||
/** | ||
* Initialize the circular queue: Resize the array & reset the start / end index. | ||
* @param MAX_SIZE | ||
*/ | ||
init(MAX_SIZE: number): void; | ||
/** | ||
* Free memory. | ||
*/ | ||
free(): void; | ||
/** | ||
* Get the front element of the queue. | ||
*/ | ||
front(): T | undefined; | ||
/** | ||
* Get the end element of the queue. | ||
*/ | ||
end(): T | undefined; | ||
/** | ||
* Popup the front element from the queue. | ||
*/ | ||
dequeue(): T | undefined; | ||
/** | ||
* Append an element. | ||
* @param element | ||
* @returns the index assigned to the element just appended | ||
*/ | ||
enqueue(element: T): number; | ||
/** | ||
* Gets the element in the queue at the specified index. | ||
* | ||
* @param idx | ||
* @param strickCheck | ||
*/ | ||
get(idx: number, strickCheck?: boolean): T | undefined; | ||
/** | ||
* Set the element at the specified index. | ||
* | ||
* @param idx | ||
* @param element | ||
*/ | ||
set(idx: number, element: T): boolean; | ||
/** | ||
* Check if the given idx is a valid index of the circular queue. | ||
* @param idx | ||
*/ | ||
isValidIndex(idx: number): boolean; | ||
/** | ||
* Get the number of elements in the queue. | ||
*/ | ||
size(): number; | ||
/** | ||
* Whether the queue is empty. | ||
*/ | ||
isEmpty(): boolean; | ||
} | ||
/** | ||
* Create a circular queue. | ||
@@ -8,2 +71,2 @@ * @param MAX_SIZE | ||
*/ | ||
export declare function createCircularQueue<T>(): CircularQueue<T>; | ||
export declare function createCircularQueue<T>(): ICircularQueue<T>; |
{ | ||
"name": "@algorithm.ts/circular-queue", | ||
"version": "1.0.24", | ||
"version": "2.0.0-alpha.0", | ||
"description": "Circular queue in Typescript", | ||
@@ -42,3 +42,3 @@ "author": { | ||
}, | ||
"gitHead": "be5ff5ef055a514bd2f9113b541e9f49ad6008b4" | ||
"gitHead": "f48a558ad6decd6c5eee4b9a999ac085c9e19a22" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12516
261
6
2