Socket
Socket
Sign inDemoInstall

@datastructures-js/priority-queue

Package Overview
Dependencies
1
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.1.4 to 6.2.0

4

CHANGELOG.md

@@ -8,2 +8,6 @@ # Changelog

## [Unreleased]
## [6.2.0] - 2023-01-16
### Added
- Symbol.iterator
## [6.1.4] - 2022-11-06

@@ -10,0 +14,0 @@ ### Fixed

4

package.json
{
"name": "@datastructures-js/priority-queue",
"version": "6.1.4",
"version": "6.2.0",
"description": "A heap-based implementation of priority queue in javascript with typescript support.",

@@ -39,4 +39,4 @@ "main": "index.js",

"dependencies": {
"@datastructures-js/heap": "^4.1.2"
"@datastructures-js/heap": "^4.3.1"
}
}

@@ -24,2 +24,3 @@ # @datastructures-js/priority-queue

* [toArray](#toarray)
* [Symbol.iterator](#symboliterator)
* [clear](#clear)

@@ -257,3 +258,2 @@ * [Build](#build)

```js

@@ -268,3 +268,2 @@ console.log(carsQueue.size()); // 4

```js

@@ -294,2 +293,31 @@ console.log(carsQueue.toArray());

### Symbol.iterator
The queues implement a Symbol.iterator that makes them iterable on `pop`.
```js
console.log([...carsQueue]);
/*
[
{ year: 2013, price: 25000 },
{ year: 2013, price: 30000 },
{ year: 2013, price: 35000 },
{ year: 2010, price: 2000 }
]
*/
console.log(carsQueue.size()); // 0
console.log([...numbersQueue]); // [ 0, 3, 4, 5 ]
console.log(numbersQueue.size()); // 0
for (const bid of bidsQueue) {
console.log(bid);
}
/*
{ id: 6, value: 4000 },
{ id: 4, value: 1500 },
{ id: 3, value: 1000 },
{ id: 1, value: 1000 }
*/
console.log(bidsHeap.size()); // 0
```
### clear

@@ -296,0 +324,0 @@ clears all elements in the queue.

@@ -5,2 +5,3 @@ import { MaxHeap, IGetCompareValue } from '@datastructures-js/heap';

constructor(getCompareValue?: IGetCompareValue<T>, heap?: MaxHeap<T>);
[Symbol.iterator](): Iterator<T, any, undefined>;
size(): number;

@@ -7,0 +8,0 @@ isEmpty(): boolean;

@@ -118,2 +118,19 @@ /**

/**
* Implements an iterable on the min priority queue
* @public
*/
[Symbol.iterator]() {
let size = this.size();
return {
next: () => {
size -= 1;
return {
value: this.pop(),
done: size === -1
};
}
};
}
/**
* Creates a priority queue from an existing array

@@ -120,0 +137,0 @@ * @public

@@ -5,2 +5,3 @@ import { MinHeap, IGetCompareValue } from '@datastructures-js/heap';

constructor(getCompareValue?: IGetCompareValue<T>, heap?: MinHeap<T>);
[Symbol.iterator](): Iterator<T, any, undefined>;
size(): number;

@@ -7,0 +8,0 @@ isEmpty(): boolean;

@@ -117,2 +117,19 @@ /**

/**
* Implements an iterable on the min priority queue
* @public
*/
[Symbol.iterator]() {
let size = this.size();
return {
next: () => {
size -= 1;
return {
value: this.pop(),
done: size === -1
};
}
};
}
/**
* Creates a priority queue from an existing array

@@ -119,0 +136,0 @@ * @public

@@ -5,2 +5,3 @@ import { ICompare } from '@datastructures-js/heap';

constructor(compare: ICompare<T>, values?: T[]);
[Symbol.iterator](): Iterator<T, any, undefined>;
size(): number;

@@ -7,0 +8,0 @@ isEmpty(): boolean;

@@ -118,2 +118,19 @@ /**

/**
* Implements an iterable on the priority queue
* @public
*/
[Symbol.iterator]() {
let size = this.size();
return {
next: () => {
size -= 1;
return {
value: this.pop(),
done: size === -1
};
}
};
}
/**
* Creates a priority queue from an existing array

@@ -120,0 +137,0 @@ * @public

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc