Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

heap-js

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heap-js - npm Package Compare versions

Comparing version 2.1.6 to 2.2.0

41

dist/heap-js.es5.js

@@ -44,6 +44,10 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, body) {

};
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -61,4 +65,4 @@ var toInt = function (n) { return ~~n; };

function Heap(compare) {
if (compare === void 0) { compare = Heap.minComparator; }
var _this = this;
if (compare === void 0) { compare = Heap.minComparator; }
this.compare = compare;

@@ -329,3 +333,3 @@ this.heapArray = [];

var heap = new Heap(compare);
heap.heapArray = __spreadArray([], __read(iterable));
heap.heapArray = __spreadArray([], __read(iterable), false);
heap.init();

@@ -343,3 +347,3 @@ return heap.top(n);

var heap = new Heap(compare);
heap.heapArray = __spreadArray([], __read(iterable));
heap.heapArray = __spreadArray([], __read(iterable), false);
heap.init();

@@ -371,3 +375,3 @@ return heap.bottom(n);

var i = this.length;
(_a = this.heapArray).push.apply(_a, __spreadArray([], __read(elements)));
(_a = this.heapArray).push.apply(_a, __spreadArray([], __read(elements), false));
for (var l = this.length; i < l; ++i) {

@@ -397,3 +401,3 @@ this._sortNodeUp(i);

// The whole heap
return __spreadArray([], __read(this.heapArray));
return __spreadArray([], __read(this.heapArray), false);
}

@@ -453,3 +457,3 @@ else {

if (array) {
this.heapArray = __spreadArray([], __read(array));
this.heapArray = __spreadArray([], __read(array), false);
}

@@ -629,3 +633,3 @@ for (var i = Math.floor(this.heapArray.length); i >= 0; --i) {

// The whole peek
return __spreadArray([], __read(this.heapArray));
return __spreadArray([], __read(this.heapArray), false);
}

@@ -643,3 +647,3 @@ else {

Heap.prototype.toArray = function () {
return __spreadArray([], __read(this.heapArray));
return __spreadArray([], __read(this.heapArray), false);
};

@@ -701,3 +705,3 @@ /**

Heap.prototype.iterator = function () {
return this;
return this.toArray();
};

@@ -818,7 +822,7 @@ /**

topHeap.push(arr[i]);
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i))));
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i)), false));
}
else if (this.compare(arr[i], topHeap.peek()) < 0) {
topHeap.replace(arr[i]);
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i))));
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i)), false));
}

@@ -846,3 +850,3 @@ }

for (var i = branch; i < n; ++i) {
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i).filter(function (l) { return l < heapArray.length; }))));
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i).filter(function (l) { return l < heapArray.length; })), false));
}

@@ -857,3 +861,3 @@ if ((n - 1) % 2) {

topHeap.replace(heapArray[i]);
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i))));
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i)), false));
}

@@ -914,3 +918,2 @@ }

export default Heap;
export { Heap, toInt };
export { Heap, Heap as default, toInt };

@@ -5,3 +5,3 @@ (function (global, factory) {

(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.heap = {}));
}(this, (function (exports) { 'use strict';
})(this, (function (exports) { 'use strict';

@@ -51,6 +51,10 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, body) {

};
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -68,4 +72,4 @@ var toInt = function (n) { return ~~n; };

function Heap(compare) {
if (compare === void 0) { compare = Heap.minComparator; }
var _this = this;
if (compare === void 0) { compare = Heap.minComparator; }
this.compare = compare;

@@ -336,3 +340,3 @@ this.heapArray = [];

var heap = new Heap(compare);
heap.heapArray = __spreadArray([], __read(iterable));
heap.heapArray = __spreadArray([], __read(iterable), false);
heap.init();

@@ -350,3 +354,3 @@ return heap.top(n);

var heap = new Heap(compare);
heap.heapArray = __spreadArray([], __read(iterable));
heap.heapArray = __spreadArray([], __read(iterable), false);
heap.init();

@@ -378,3 +382,3 @@ return heap.bottom(n);

var i = this.length;
(_a = this.heapArray).push.apply(_a, __spreadArray([], __read(elements)));
(_a = this.heapArray).push.apply(_a, __spreadArray([], __read(elements), false));
for (var l = this.length; i < l; ++i) {

@@ -404,3 +408,3 @@ this._sortNodeUp(i);

// The whole heap
return __spreadArray([], __read(this.heapArray));
return __spreadArray([], __read(this.heapArray), false);
}

@@ -460,3 +464,3 @@ else {

if (array) {
this.heapArray = __spreadArray([], __read(array));
this.heapArray = __spreadArray([], __read(array), false);
}

@@ -636,3 +640,3 @@ for (var i = Math.floor(this.heapArray.length); i >= 0; --i) {

// The whole peek
return __spreadArray([], __read(this.heapArray));
return __spreadArray([], __read(this.heapArray), false);
}

@@ -650,3 +654,3 @@ else {

Heap.prototype.toArray = function () {
return __spreadArray([], __read(this.heapArray));
return __spreadArray([], __read(this.heapArray), false);
};

@@ -708,3 +712,3 @@ /**

Heap.prototype.iterator = function () {
return this;
return this.toArray();
};

@@ -825,7 +829,7 @@ /**

topHeap.push(arr[i]);
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i))));
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i)), false));
}
else if (this.compare(arr[i], topHeap.peek()) < 0) {
topHeap.replace(arr[i]);
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i))));
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i)), false));
}

@@ -853,3 +857,3 @@ }

for (var i = branch; i < n; ++i) {
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i).filter(function (l) { return l < heapArray.length; }))));
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i).filter(function (l) { return l < heapArray.length; })), false));
}

@@ -864,3 +868,3 @@ if ((n - 1) % 2) {

topHeap.replace(heapArray[i]);
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i))));
indices.push.apply(indices, __spreadArray([], __read(Heap.getChildrenIndexOf(i)), false));
}

@@ -922,3 +926,3 @@ }

exports.Heap = Heap;
exports.default = Heap;
exports["default"] = Heap;
exports.toInt = toInt;

@@ -928,2 +932,2 @@

})));
}));
{
"name": "heap-js",
"version": "2.1.6",
"version": "2.2.0",
"description": "Efficient Binary heap (priority queue, binary tree) data structure for JavaScript / TypeScript. Includes JavaScript methods, Python's heapq module methods, and Java's PriorityQueue methods.",

@@ -72,31 +72,30 @@ "keywords": [

"devDependencies": {
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@types/benchmark": "^2.1.1",
"@types/jest": "^26.0.24",
"@types/node": "^16.3.1",
"@typescript-eslint/eslint-plugin": "4.28.3",
"@typescript-eslint/parser": "^4.28.3",
"@types/jest": "^27.5.0",
"@types/node": "^17.0.31",
"@typescript-eslint/eslint-plugin": "5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"benchmark": "^2.1.4",
"coveralls": "^3.1.1",
"cross-env": "^7.0.3",
"eslint": "7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-standard": "5.0.0",
"husky": "^7.0.1",
"jest": "^27.0.6",
"lint-staged": "^11.0.0",
"eslint": "8.15.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^8.0.1",
"jest": "^28.1.0",
"lint-staged": "^12.4.1",
"lodash.camelcase": "^4.3.0",
"prettier": "^2.3.2",
"prettier-eslint": "^12.0.0",
"prettier": "^2.6.2",
"prettier-eslint": "^14.0.2",
"rimraf": "^3.0.2",
"rollup": "^2.53.1",
"rollup": "^2.72.1",
"rollup-plugin-sourcemaps": "^0.6.3",
"ts-jest": "^27.0.3",
"ts-node": "^10.1.0",
"tsc-watch": "^4.4.0",
"typedoc": "^0.21.4",
"typescript": "^4.3.5"
"ts-jest": "^28.0.2",
"ts-node": "^10.7.0",
"tsc-watch": "^5.0.3",
"typedoc": "^0.22.15",
"typescript": "^4.6.4"
}
}

@@ -43,2 +43,10 @@ # ![Heap.js](assets/heap-js.png) Heap.js

### 2.2
- Fixes `.iterator()` method to follow [Java's PriorityQueue implementation:
](https://docs.oracle.com/javase/8/docs/api/java/util/PriorityQueue.html)
> The Iterator provided in method [iterator()](<https://docs.oracle.com/javase/8/docs/api/java/util/PriorityQueue.html#iterator()>) is not guaranteed to traverse the elements of the priority queue in any particular order.
Notice that _using the heap directly as an iteraror will consume the heap,_ as Python's `heapq` implementation does.
### 2.1

@@ -81,3 +89,3 @@

// Iterator
// Iterator, that will consume the heap
maxHeap.init([3, 4, 1, 12, 8]);

@@ -99,3 +107,9 @@ for (const value of maxHeap) {

// priorityQueue === priorityQueue.iterator()
// Iterator, the Java way, that will not consume the heap but does not guarantee
// to traverse the elements of the heap in any particular order. Barely useful.
for (const taks of priorityQueue.iterator()) {
// Do something
}
// Iterator, the JavaScript and Python way, that will consume the heap
for (const task of priorityQueue) {

@@ -139,2 +153,3 @@ // Do something

- `for (const value of heap)` directly usable as an Iterator, consumes the heap
- `length` of the heap

@@ -159,3 +174,3 @@ - `limit` amount of elements in the heap

- `isEmpty()`
- `iterator()` returns `this` because it is iterable
- `iterator()` returns the same as `toArray()` because it is iterable and follows Java's implementation
- _`offer(element)` alias of `add(element)`_

@@ -162,0 +177,0 @@ - `peek()`

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc