@datastructures-js/priority-queue
Advanced tools
Comparing version
@@ -8,2 +8,6 @@ # Changelog | ||
## [Unreleased] | ||
## [6.1.0] - 2022-05-30 | ||
### Added | ||
- push & pop as alias methods for enqueue & dequeue | ||
## [6.0.0] - 2022-03-19 | ||
@@ -10,0 +14,0 @@ ### Changed |
{ | ||
"name": "@datastructures-js/priority-queue", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "A heap-based implementation of priority queue in javascript with typescript support.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,6 +17,6 @@ # @datastructures-js/priority-queue | ||
* [fromArray](#fromarray) | ||
* [enqueue](#enqueue) | ||
* [enqueue (push)](#enqueue-push) | ||
* [front](#front) | ||
* [back](#back) | ||
* [dequeue](#dequeue) | ||
* [dequeue (pop)](#dequeue-pop) | ||
* [isEmpty](#isEmpty) | ||
@@ -62,3 +62,3 @@ * [size](#size) | ||
#### PriorityQueue | ||
constructor requires a compare function that works similar to javascript sort callback, returning a number bigger than 0, means swap elemens. | ||
constructor requires a compare function that works similar to javascript sort callback, returning a number bigger than 0, means swap elements. | ||
@@ -181,3 +181,3 @@ ##### TS | ||
### enqueue | ||
### enqueue (push) | ||
adds a value based on its comparison with other values in the queue in O(log(n)) runtime. | ||
@@ -198,3 +198,3 @@ | ||
const numbers = [3, -2, 5, 0, -1, -5, 4]; | ||
numbers.forEach((num) => numbersQueue.enqueue(num)); | ||
numbers.forEach((num) => numbersQueue.push(num)); | ||
@@ -231,3 +231,3 @@ const bids = [ | ||
### dequeue | ||
### dequeue (pop) | ||
removes and returns the element with highest priority in the queue in O(log(n)) runtime. | ||
@@ -244,5 +244,5 @@ | ||
console.log(bidsQueue.dequeue()); // { id: 2, value: 20000 } | ||
console.log(bidsQueue.dequeue()); // { id: 5, value: 12000 } | ||
console.log(bidsQueue.dequeue()); // { id: 7, value: 8000 } | ||
console.log(bidsQueue.pop()); // { id: 2, value: 20000 } | ||
console.log(bidsQueue.pop()); // { id: 5, value: 12000 } | ||
console.log(bidsQueue.pop()); // { id: 7, value: 8000 } | ||
``` | ||
@@ -249,0 +249,0 @@ |
@@ -10,3 +10,5 @@ import { MaxHeap, IGetCompareValue } from '@datastructures-js/heap'; | ||
enqueue(value: T): MaxPriorityQueue<T>; | ||
push(value: T): MaxPriorityQueue<T>; | ||
dequeue(): T; | ||
pop(): T; | ||
toArray(): T[]; | ||
@@ -13,0 +15,0 @@ clear(): void; |
@@ -55,2 +55,12 @@ /** | ||
/** | ||
* Adds a value to the queue | ||
* @public | ||
* @param {number|string|object} value | ||
* @returns {MaxPriorityQueue} | ||
*/ | ||
push(value) { | ||
return this.enqueue(value); | ||
} | ||
/** | ||
* Removes and returns an element with highest priority in the queue | ||
@@ -65,2 +75,11 @@ * @public | ||
/** | ||
* Removes and returns an element with highest priority in the queue | ||
* @public | ||
* @returns {number|string|object} | ||
*/ | ||
pop() { | ||
return this.dequeue(); | ||
} | ||
/** | ||
* Returns the number of elements in the queue | ||
@@ -67,0 +86,0 @@ * @public |
@@ -10,3 +10,5 @@ import { MinHeap, IGetCompareValue } from '@datastructures-js/heap'; | ||
enqueue(value: T): MinPriorityQueue<T>; | ||
push(value: T): MinPriorityQueue<T>; | ||
dequeue(): T; | ||
pop(): T; | ||
toArray(): T[]; | ||
@@ -13,0 +15,0 @@ clear(): void; |
@@ -54,2 +54,12 @@ /** | ||
/** | ||
* Adds a value to the queue | ||
* @public | ||
* @param {number|string|object} value | ||
* @returns {MinPriorityQueue} | ||
*/ | ||
push(value) { | ||
return this.enqueue(value); | ||
} | ||
/** | ||
* Removes and returns an element with highest priority in the queue | ||
@@ -64,2 +74,11 @@ * @public | ||
/** | ||
* Removes and returns an element with highest priority in the queue | ||
* @public | ||
* @returns {number|string|object} | ||
*/ | ||
pop() { | ||
return this.dequeue(); | ||
} | ||
/** | ||
* Returns the number of elements in the queue | ||
@@ -66,0 +85,0 @@ * @public |
@@ -10,3 +10,5 @@ import { ICompare } from '@datastructures-js/heap'; | ||
enqueue(value: T): PriorityQueue<T>; | ||
push(value: T): PriorityQueue<T>; | ||
dequeue(): T; | ||
pop(): T; | ||
toArray(): T[]; | ||
@@ -13,0 +15,0 @@ clear(): void; |
@@ -55,2 +55,12 @@ /** | ||
/** | ||
* Adds a value to the queue | ||
* @public | ||
* @param {number|string|object} value | ||
* @returns {PriorityQueue} | ||
*/ | ||
push(value) { | ||
return this.enqueue(value); | ||
} | ||
/** | ||
* Removes and returns an element with highest priority in the queue | ||
@@ -65,2 +75,11 @@ * @public | ||
/** | ||
* Removes and returns an element with highest priority in the queue | ||
* @public | ||
* @returns {number|string|object} | ||
*/ | ||
pop() { | ||
return this.dequeue(); | ||
} | ||
/** | ||
* Returns the number of elements in the queue | ||
@@ -67,0 +86,0 @@ * @public |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21732
6.51%405
16.38%0
-100%