![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
binaryheap-array
Advanced tools
Binary Heap Data Structure using an array like implementation, super fast and easy to use
Binary Heap Data Structure using an array implementation
var BinaryHeap = require("binaryheap-array");
var ch = new BinaryHeap();
ch.insert('T');
ch.insert('S');
// You can also chain inserts :)
ch.insert('R').insert('P');
// Removes the largest element first
ch.remove(); // 'T'
// You can also peak before you remove
ch.peak(); // 'S'
ch.remove(); // 'S'
// Use the 'comparable' property to choose what you need to compare ahead of time
// In our example we want to compare the age
var list = new BinaryHeap({ comparable: function(elm) { return elm.age; } });
list.insert({ 'name': 'John', 'age': 25 });
list.insert({ 'name': 'Mike', 'age': 21 });
list.insert({ 'name': 'Aisha', 'age': 33 });
list.insert({ 'name': 'Sarah', 'age': 20 });
list.remove(); // { name: 'Aisha', age: 33 }
list.size(); // 3
list.remove(); // { name: 'John', age: 25 }
Create a maximum or minimum priority queue on the fly
// Choose the order of the binaryheap ascending, or descending
var maximumPQ = new BinaryHeap({ order:'asc' });
var minimumPQ = new BinaryHeap({ order:'dec' });
Method | Returns Type | Description |
---|---|---|
size | number | The size of the heap |
insert | object | Adds an element to the heap |
remove | object | Removes the root element (could be the max or min based on the configuration setting) |
undefined | Prints the tree structure of the binary heap | |
peak | object | Peak on the root element, or the element that will get remove first |
Object | Type | Description |
---|---|---|
order | string | The order of the BinaryHeap either 'ascending' or 'descending' |
comparable | function | Choose what you need to compare, default to the inserted value see object example |
data | array | Pass in the data as an array ahead of time and we will handle the insertion for you |
Type | Worst | Average |
---|---|---|
insert | O(log n) | O(log n) |
remove | O(log n) | O(log n) |
peak | O(1) | O(1) |
This graph is a representation of the algorithm used in this module
*-( (2 * i) + 1 )-˅
*-( 2 * i )-˅ ˅
[ 'ø', 'T', 'S', 'R', 'P', 'N', 'O', 'A', ...]
Empty *------^ ^
(2 * i) ^
*------------^
(2 * i) + 1
Feel free to reach out with feedback via github: issue
, feature
, bug
, or enhancement
inputs are greatly appreciated
© MIT
FAQs
Binary Heap Data Structure using an array like implementation, super fast and easy to use
The npm package binaryheap-array receives a total of 5 weekly downloads. As such, binaryheap-array popularity was classified as not popular.
We found that binaryheap-array demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.