@tyriar/fibonacci-heap
Advanced tools
Comparing version 1.0.3 to 1.0.5
{ | ||
"name": "@tyriar/fibonacci-heap", | ||
"version": "1.0.3", | ||
"version": "1.0.5", | ||
"description": "An implementation of the Fibonacci heap data structure", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -9,2 +9,9 @@ # js-fibonacci-heap [![NPM version](https://img.shields.io/npm/v/@tyriar/fibonacci-heap.svg?style=flat)](https://www.npmjs.org/package/@tyriar/fibonacci-heap) | ||
## Features | ||
- 100% test coverage | ||
- Supports all common heap operations | ||
- Store keys with optional associated values | ||
- Optional custom compare function that can utilize both key and value to give full control over the order of the data | ||
## Install | ||
@@ -19,14 +26,42 @@ | ||
```javascript | ||
var FibonacciHeap = require("@tyriar/fibonacci-heap"); | ||
// Import npm module | ||
var FibonacciHeap = require('@tyriar/fibonacci-heap'; | ||
// Construct FibonacciHeap | ||
var heap = new FibonacciHeap(); | ||
// Insert keys only | ||
heap.insert(3); | ||
heap.insert(7); | ||
heap.insert(8); | ||
heap.insert(1); | ||
heap.insert(2); | ||
// Insert keys and values | ||
heap.insert(8, {foo: 'bar'}); | ||
heap.insert(1, {foo: 'baz'}); | ||
// Extract all nodes in order | ||
while (!heap.isEmpty()) { | ||
console.log(heap.extractMinimum()); | ||
var node = heap.extractMinimum(); | ||
console.log('key: ' + node.key + ', value: ' + node.value); | ||
} | ||
// > key: 1, value: [object Object] | ||
// > key: 3, value: undefined | ||
// > key: 7, value: undefined | ||
// > key: 8, value: [object Object] | ||
// Construct custom compare FibonacciHeap | ||
heap = new FibonacciHeap(function (a, b) { | ||
return (a.key + a.value).localeCompare(b.key + b.value); | ||
}); | ||
heap.insert('2', 'B'); | ||
heap.insert('1', 'a'); | ||
heap.insert('1', 'A'); | ||
heap.insert('2', 'b'); | ||
// Extract all nodes in order | ||
while (!heap.isEmpty()) { | ||
var node = heap.extractMinimum(); | ||
console.log('key: ' + node.key + ', value: ' + node.value); | ||
} | ||
// > key: 1, value: a | ||
// > key: 1, value: A | ||
// > key: 2, value: b | ||
// > key: 2, value: B | ||
``` | ||
@@ -33,0 +68,0 @@ |
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
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
39890
156