Comparing version 0.3.0 to 0.4.0
# Changelog | ||
## 0.4.0 | ||
* Adding `Queue`. | ||
* Adding possibility to pass custom comparator to `Heap` & `FibonacciHeap`. | ||
## 0.3.0 | ||
@@ -4,0 +9,0 @@ |
@@ -12,2 +12,14 @@ # Fibonacci Heap | ||
var MaxFibonacciHeap = require('mnemonist/fibonacci-heap').MaxFibonacciHeap; | ||
// To create a heap: | ||
var heap = new FibonacciHeap(); | ||
// With a custom comparator: | ||
var heap = new FibonacciHeap(function(a, b) { | ||
if (a.value < b.value) | ||
return -1; | ||
if (a.value > b.value) | ||
return 1; | ||
return 0; | ||
}); | ||
``` | ||
@@ -14,0 +26,0 @@ |
@@ -12,2 +12,14 @@ # Heap | ||
var MaxHeap = require('mnemonist/heap').MaxHeap; | ||
// To create a heap: | ||
var heap = new Heap(); | ||
// With a custom comparator: | ||
var heap = new Heap(function(a, b) { | ||
if (a.value < b.value) | ||
return -1; | ||
if (a.value > b.value) | ||
return 1; | ||
return 0; | ||
}); | ||
``` | ||
@@ -14,0 +26,0 @@ |
@@ -67,3 +67,3 @@ # Stack | ||
stack.unshift(1); | ||
stack.push(1); | ||
stack.clear(); | ||
@@ -70,0 +70,0 @@ stack.toArray(); |
@@ -11,3 +11,3 @@ /* eslint no-constant-condition: 0 */ | ||
var DEFAULT_COMPARATOR = comparators.DEFAULT_COMPARATOR, | ||
DEFAULT_REVERSED_COMPARATOR = comparators.DEFAULT_REVERSED_COMPARATOR; | ||
reverseComparator = comparators.reverseComparator; | ||
@@ -19,5 +19,8 @@ /** | ||
*/ | ||
function FibonacciHeap() { | ||
function FibonacciHeap(comparator) { | ||
this.clear(); | ||
this.comparator = DEFAULT_COMPARATOR; | ||
this.comparator = comparator || DEFAULT_COMPARATOR; | ||
if (typeof this.comparator !== 'function') | ||
throw new Error('mnemonist/FibonacciHeap.constructor: given comparator should be a function.'); | ||
} | ||
@@ -250,5 +253,10 @@ | ||
*/ | ||
function MaxFibonacciHeap() { | ||
function MaxFibonacciHeap(comparator) { | ||
this.clear(); | ||
this.comparator = DEFAULT_REVERSED_COMPARATOR; | ||
this.comparator = comparator || DEFAULT_COMPARATOR; | ||
if (typeof this.comparator !== 'function') | ||
throw new Error('mnemonist/FibonacciHeap.constructor: given comparator should be a function.'); | ||
this.comparator = reverseComparator(this.comparator); | ||
} | ||
@@ -255,0 +263,0 @@ |
18
heap.js
@@ -10,3 +10,3 @@ /** | ||
var DEFAULT_COMPARATOR = comparators.DEFAULT_COMPARATOR, | ||
DEFAULT_REVERSED_COMPARATOR = comparators.DEFAULT_REVERSED_COMPARATOR; | ||
reverseComparator = comparators.reverseComparator; | ||
@@ -18,5 +18,8 @@ /** | ||
*/ | ||
function Heap() { | ||
function Heap(comparator) { | ||
this.clear(); | ||
this.comparator = DEFAULT_COMPARATOR; | ||
this.comparator = comparator || DEFAULT_COMPARATOR; | ||
if (typeof this.comparator !== 'function') | ||
throw new Error('mnemonist/Heap.constructor: given comparator should be a function.'); | ||
} | ||
@@ -155,5 +158,10 @@ | ||
*/ | ||
function MaxHeap() { | ||
function MaxHeap(comparator) { | ||
this.clear(); | ||
this.comparator = DEFAULT_REVERSED_COMPARATOR; | ||
this.comparator = comparator || DEFAULT_COMPARATOR; | ||
if (typeof this.comparator !== 'function') | ||
throw new Error('mnemonist/Heap.constructor: given comparator should be a function.'); | ||
this.comparator = reverseComparator(this.comparator); | ||
} | ||
@@ -160,0 +168,0 @@ |
@@ -9,6 +9,8 @@ /** | ||
module.exports = { | ||
FibonacciHeap: require('./fibonacci-heap.js'), | ||
Heap: require('./heap.js'), | ||
LinkedList: require('./linked-list.js'), | ||
Queue: require('./queue.js'), | ||
Stack: require('./stack.js'), | ||
Trie: require('./trie.js') | ||
}; |
{ | ||
"name": "mnemonist", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Collection of classic data structures for JavaScript.", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "eslint ./*.js ./benchmark ./test", | ||
"lint": "eslint ./*.js ./utils ./test", | ||
"prepublish": "npm test", | ||
@@ -18,2 +18,3 @@ "test": "mocha" | ||
"linked-list.js", | ||
"queue.js", | ||
"stack.js", | ||
@@ -20,0 +21,0 @@ "trie.js" |
@@ -25,2 +25,3 @@ [![Build Status](https://travis-ci.org/Yomguithereal/mnemonist.svg)](https://travis-ci.org/Yomguithereal/mnemonist) | ||
* [Linked List](docs/linked-list.md) | ||
* [Queue](docs/queue.md) | ||
* [Stack](docs/stack.md) | ||
@@ -27,0 +28,0 @@ * [Trie](docs/trie.md) |
@@ -25,4 +25,2 @@ /** | ||
var DEFAULT_REVERSED_COMPARATOR = reverseComparator(DEFAULT_COMPARATOR); | ||
/** | ||
@@ -32,2 +30,2 @@ * Exporting. | ||
exports.DEFAULT_COMPARATOR = DEFAULT_COMPARATOR; | ||
exports.DEFAULT_REVERSED_COMPARATOR = DEFAULT_REVERSED_COMPARATOR; | ||
exports.reverseComparator = reverseComparator; |
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
35665
19
1022
49