{"id":20745330,"url":"https://github.com/klaudiosinani/binoheap","last_synced_at":"2025-06-12T01:10:18.714Z","repository":{"id":112528971,"uuid":"197672440","full_name":"klaudiosinani/binoheap","owner":"klaudiosinani","description":"Binomial heaps for ES6","archived":false,"fork":false,"pushed_at":"2019-10-30T20:27:04.000Z","size":122,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-04T05:04:39.103Z","etag":null,"topics":["binomial","data","es6","heap","structure","typescript"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klaudiosinani.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"license.md","code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"klaudiosinani","buy_me_a_coffee":"klaudiosinani","custom":"https://klaudiosinani.com/thanks"}},"created_at":"2019-07-19T00:04:49.000Z","updated_at":"2022-10-20T12:59:57.000Z","dependencies_parsed_at":"2023-05-15T16:45:29.239Z","dependency_job_id":null,"html_url":"https://github.com/klaudiosinani/binoheap","commit_stats":null,"previous_names":["klaussinani/binoheap"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/klaudiosinani/binoheap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaudiosinani%2Fbinoheap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaudiosinani%2Fbinoheap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaudiosinani%2Fbinoheap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaudiosinani%2Fbinoheap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klaudiosinani","download_url":"https://codeload.github.com/klaudiosinani/binoheap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaudiosinani%2Fbinoheap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259374947,"owners_count":22847873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binomial","data","es6","heap","structure","typescript"],"created_at":"2024-11-17T07:19:43.960Z","updated_at":"2025-06-12T01:10:18.702Z","avatar_url":"https://github.com/klaudiosinani.png","language":"JavaScript","funding_links":["https://github.com/sponsors/klaudiosinani","https://buymeacoffee.com/klaudiosinani","https://klaudiosinani.com/thanks"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  Binoheap\n\u003c/h1\u003e\n\n\u003ch4 align=\"center\"\u003e\n  Binomial heaps for ES6\n\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.com/klaussinani/binoheap\"\u003e\n    \u003cimg alt=\"Build Status\" src=\"https://travis-ci.com/klaussinani/binoheap.svg?branch=master\"\u003e\n  \u003c/a\u003e\n  \u003ca href='https://coveralls.io/github/klaussinani/binoheap?branch=master'\u003e\n    \u003cimg alt=\"Coverage Status\" src=\"https://coveralls.io/repos/github/klaussinani/binoheap/badge.svg?branch=master\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Description\n\nES6 implementation of the binomial heap data structure with TypeScript support.\n\nVisit the [contributing guidelines](https://github.com/klaussinani/binoheap/blob/master/contributing.md#translating-documentation) to learn more on how to translate this document into more languages.\n\n## Contents\n\n- [Description](#description)\n- [Install](#install)\n- [In Depth](#in-depth)\n- [Usage](#usage)\n- [API](#api)\n- [Development](#development)\n- [Related](#related)\n- [Team](#team)\n- [License](#license)\n\n## Install\n\n### Yarn\n\n```bash\nyarn add binoheap\n```\n\n### NPM\n\n```bash\nnpm install binoheap\n```\n\n## In Depth\n\nA binomial heap data structure, is a specific implementation of the heap data structure, comprised of collections of binomial trees that are linearly linked together, where each tree is a minimum or maximum ordered heap. Binomial heaps are similar to binary heaps but they have a more specific structure and allow for efficient `O(log n)` heap merging.\n\nA binomial heap is implemented as a set of binomial trees, compared to a binary heap that has the shape of a single binary tree, which are defined recursively as follows:\n\n- A binomial tree of order `0` is a single node.\n- A binomial tree of order `k` has a root node whose children are roots of binomial trees of orders `k−1`, `k−2`, ..., `2`, `1`, `0`.\n\nA binomial tree of order `k` has `2^k` nodes and height `k`. Because of its unique structure, a binomial tree of order `k` can be constructed from two trees of order `k−1` by attaching one of them as the leftmost child of the root of the other. This feature is central to the merge operation of a binomial heap, which is its major advantage over other conventional heaps.\n\nAdditionally, each tree in the binomial heap should satisfy the binomial heap properties:\n\n- There can only be either one or zero binomial trees for each order, including zero order.\n- Each binomial tree in a heap obeys the minimum-heap property or the maximum-heap property, if the heap is either minimum or maximum ordered:\n  - Minimum-Heap Property: the key of a node is greater than or equal to the key of its parent.\n  - Maximum-Heap Property: the key of a node is smaller than or equal to the key of its parent.\n\nThe first property implies that a binomial heap with `n` nodes consists of at most `1 + log2 n` binomial trees. The second property ensures that the root of each binomial tree contains the smallest or the largest key in the tree, which applies to the entire heap.\n\nBinoheap binomial heaps are implemented using doubly linear linked lists for storing nodes, thus parent nodes point directly to their children and the child nodes point back to their parent. Each node contains a `parent`, `sibling` \u0026 `child` pointer, as well as a `key`, a `value` and a `degree` property.\n\n## Usage\n\nBinoheap exposes a chainable API, that can be utilized through a simple and minimal syntax, allowing you to combine methods effectively.\n\nTo create a **min-ordered binomial heap**, where the nodes of each binomial tree obey the **min-heap property**, according to which the parent node is always smaller than or equal to its children nodes, we provide as argument to the `Heap` class, on instantiation, a binary comparator function `compareMin(x, y)`, which returns a positive number when the node `x` is greater than node `y`, zero when equal and a negative number when less than.\n\nAdditionally, to create a **max-ordered binomial heap**, where the nodes of each binomial tree obey the **max-heap property**, according to which the parent node is always greater than or equal to its children nodes, we provide as argument to the `Heap` class, on instantiation, a binary comparator function `compareMax(x, y)`, which returns a negative number when the node `x` is greater than the node `y`, zero when equal and a positive number when less than.\n\nBy default, if no comparator function is provided on instantiation, a **min-ordered binomial heap** instance is returned, where the `key` value of each node is used for maintaining the **min-heap property** by the comparator function.\n\nUsage examples can be also found at the [`test`](https://github.com/klaussinani/binoheap/tree/master/test) directory.\n\n```js\n'use strict';\nconst {Heap, Node} = require('binoheap');\n\n// Create a max-ordered binomial heap\nconst heap = new Heap((x, y) =\u003e y.key - x.key);\n\nheap.isEmpty();\n//=\u003e true\n\nheap.insert(1, 'A');\n//=\u003e Heap {\n// size: 1,\n// head: Node { key: 1, value: 'A', degree: 0, parent: null, child: null, sibling: null } }\n\nheap.isEmpty();\n//=\u003e false\n\nheap.size;\n//=\u003e 1\n\nheap.head;\n//=\u003e Node { key: 1, value: 'A', degree: 0, parent: null, child: null, sibling: null }\n\nheap.head.toPair();\n//=\u003e [1, 'A']\n\nconst node = new Node(1, 'A');\n//=\u003e Node { key: 1, value: 'A', degree: 0, parent: null, child: null, sibling: null }\n\nheap.head.key === node.key;\n//=\u003e true\n\nheap.head.value === node.value;\n//=\u003e true\n\nheap.head.degree === node.degree;\n//=\u003e true\n\nheap\n  .insert(2, 'B')\n  .insert(3, 'C')\n  .insert(4, 'D')\n  .insert(5, 'E')\n  .insert(6, 'F')\n  .insert(7, 'G');\n//=\u003e Heap {\n// size: 7,\n// head: Node { key: 7, value: 'G', degree: 0, parent: null, child: null, sibling: [Node] } }\n\nheap.head.siblings();\n//=\u003e [\n//  Node { key: 6, value: 'F', degree: 1, parent: null, child: [Node], sibling: [Node] },\n//  Node { key: 4, value: 'D', degree: 2, parent: null, child: [Node], sibling: null }\n// ]\n\n// Returns the node with the maximum key value\nheap.extremum();\n//=\u003e Node { key: 7, value: 'G', degree: 0, parent: null, child: null, sibling: [Node] }\n\nheap.extremumKey();\n//=\u003e 7\n\nheap.extremumValue();\n//=\u003e 'G'\n\nheap.roots();\n//=\u003e [\n//  Node { key: 7, value: 'G', degree: 0, parent: null, child: null, sibling: [Node] },\n//  Node { key: 6, value: 'F', degree: 1, parent: null, child: [Node], sibling: [Node] },\n//  Node { key: 4, value: 'D', degree: 2, parent: null, child: [Node], sibling: null }\n// ]\n\nheap.includes(100);\n//=\u003e false\n\nheap.includes(2);\n//=\u003e true\n\nheap.search(1);\n//=\u003e Node { key: 1, value: 'A', degree: 0, parent: [Node], child: null, sibling: null }\n\nheap.search(20);\n//=\u003e undefined\n\n// Remove and return the node with the maximum key value\nheap.removeExtremum();\n//=\u003e Node { key: 7, value: 'G', degree: 0, parent: null, child: null, sibling: [Node] }\n\nheap.head;\n//=\u003e Node { key: 6, value: 'F', degree: 1, parent: null, child: [Node], sibling: [Node] }\n\nheap.size;\n//=\u003e 6\n\nconst heap2 = new Heap((x, y) =\u003e y.key - x.key));\n\nheap2\n  .insert(8, 'H')\n  .insert(9, 'I');\n//=\u003e Heap {\n// size: 2,\n// head: Node { key: 9, value: 'I', degree: 1, parent: null, child: [Node], sibling: null } }\n\nheap2.updateKey(8, 15);\n//=\u003e Heap {\n// size: 2,\n// head: Node { key: 15, value: 'H', degree: 1, parent: null, child: [Node], sibling: null } }\n\nheap.merge(heap2);\n//=\u003e Heap {\n// size: 8,\n// head: Node { key: 15, value: 'H', degree: 3, parent: null, child: [Node], sibling: null } }\n\nheap.head.descendants();\n//=\u003e [\n//  Node { key: 4, value: 'D', degree: 2, parent: [Node], child: [Node], sibling: [Node] }\n//  Node { key: 2, value: 'B', degree: 1, parent: [Node], child: [Node], sibling: [Node] },\n//  Node { key: 1, value: 'A', degree: 0, parent: [Node], child: null, sibling: null },\n// ]\n```\n\n## API\n\n#### heap.`head`\n\n- Return Type: `Node | null`\n\nReturns the head node of the heap. If the heap is empty then `null` is returned.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n\nheap.insert(10, 'A');\n//=\u003e Heap {\n// size: 1,\n// head: Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: null } }\nheap.head;\n// =\u003e Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: null }\n```\n\n#### heap.`size`\n\n- Return Type: `Number`\n\nReturns the total number of nodes residing in the heap.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n\nheap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nheap.size;\n// =\u003e 3\n```\n\n#### heap.`clear()`\n\n- Return Type: `Heap`\n\nMutates the heap by removing all residing nodes and returns it empty.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n\nheap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nheap.size;\n// =\u003e 3\nheap.clear();\n//=\u003e Heap {\n// size: 0,\n// head: null }\nheap.size;\n//=\u003e 0\n```\n\n#### heap.`extremum()`\n\n- Return Type: `Node | undefined`\n\nReturns the node corresponding to the minimum `key` value, if the heap is minimum-ordered or the node corresponding to the maximum `key`, if the heap is maximum-ordered. If the heap is empty then `undefined` is returned.\n\n```js\nconst {Heap} = require('binoheap');\n\n// Create a minimum-ordered heap\nconst minHeap = new Heap((x, y) =\u003e x.key - y.key);\n\nminHeap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nminHeap.extremum();\n//=\u003e Node { key: 10, value: 'A', degree: 1, parent: null, child: [Node], sibling: null }\n\n// Create a maximum-ordered heap\nconst maxHeap = new Heap((x, y) =\u003e y.key - x.key);\n\nmaxHeap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nmaxHeap.extremum();\n//=\u003e Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] }\n```\n\n#### heap.`extremumKey()`\n\n- Return Type: `Number | undefined`\n\nReturns the minimum `key` value, if the heap is minimum-ordered or the maximum `key` value, if the heap is maximum-ordered. If the heap is empty then `undefined` is returned.\n\n```js\nconst {Heap} = require('binoheap');\n\n// Create a minimum-ordered heap\nconst minHeap = new Heap((x, y) =\u003e x.key - y.key);\n\nminHeap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nminHeap.extremumKey();\n//=\u003e 10\n\n// Create a maximum-ordered heap\nconst maxHeap = new Heap((x, y) =\u003e y.key - x.key);\n\nmaxHeap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nmaxHeap.extremumKey();\n//=\u003e 30\n```\n\n#### heap.`extremumValue()`\n\n- Return Type: `Any | undefined`\n\nReturns the `value` corresponding to the node with the minimum `key` in the heap, if the heap is minimum-ordered or the `value` corresponding to the node with the maximum `key`, if the heap is maximum-ordered.  If the heap is empty then `undefined` is returned.\n\n```js\nconst {Heap} = require('binoheap');\n\n// Create a minimum-ordered heap\nconst minHeap = new Heap((x, y) =\u003e x.key - y.key);\n\nminHeap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nminHeap.extremumValue();\n//=\u003e 'A'\n\n// Create a maximum-ordered heap\nconst maxHeap = new Heap((x, y) =\u003e y.key - x.key);\n\nmaxHeap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nmaxHeap.extremumKey();\n//=\u003e 'C'\n```\n\n#### heap.`heapTrees()`\n\n- Return Type: `Number`\n\nReturns the number of binomial trees that the heap is comprised of.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n\nheap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nheap.heapTrees();\n//=\u003e 2\n```\n\n#### heap.`includes(key)`\n\n- Return Type: `Boolean`\n\nTraverses the nodes in the binomial heap level by level, from left to right \u0026 from top to bottom, and determines whether the heap includes a node with the given `key` value, returning `true` or `false` as appropriate.\n\n##### **`key`**\n\n- Type: `Number`\n\nNode `key` to search for.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n\nheap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nheap.includes(20);\n//=\u003e true\nheap.includes(5);\n//=\u003e false\n```\n\n#### heap.`insert(key, value)`\n\n- Return Type: `Heap`\n\nMutates the heap by inserting a new node at the appropriate location. Returns the heap itself.\n\n##### **`key`**\n\n- Type: `Number`\n\nCan be any number that will correspond to the `key` of the created node.\n\n##### **`value`**\n\n- Type: `Any`\n\nCan be any value that will stored in the created node.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n\nheap.insert(10, 'A');\n//=\u003e Heap {\n// size: 1,\n// head: Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: null } }\nheap\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\n```\n\n#### heap.`isEmpty()`\n\n- Return Type: `Boolean`\n\nDetermines whether the heap is empty, returning `true` or `false` as appropriate.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n\nheap.isEmpty();\n// =\u003e true\nheap.insert(10, 'A');\n//=\u003e Heap {\n// size: 1,\n// head: Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: null } }\nheap.isEmpty();\n// =\u003e false\n```\n\n#### heap.`merge(heap)`\n\n- Return Type: `Heap`\n\nMutates the `Heap` instance by merging it with the given binomial heap. Returns the resulting merged heap.\n\n##### **`heap`**\n\n- Type: `Heap`\n\nHeap to merge with the `Heap` instance.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap1 = new Heap();\n\nheap1\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\n\nconst heap2 = new Heap();\n\nheap2\n  .insert(40, 'D')\n  .insert(50, 'E')\n  .insert(60, 'F');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 60, value: 'F', degree: 0, parent: null, child: null, sibling: [Node] } }\n\nheap1.merge(heap2);\n//=\u003e Heap {\n// size: 6,\n// head: Node { key: 30, value: 'C', degree: 1, parent: null, child: [Node], sibling: [Node] } }\n```\n\n#### heap.`removeExtremum()`\n\n- Return Type: `Node | undefined`\n\nMutates the heap by removing the node corresponding to the minimum `key` value, if the heap is minimum-ordered or the node corresponding to the maximum `key` if the heap is maximum-ordered. \nThe removed node is returned by the method if the heap is not empty. If the heap is empty then `undefined` is returned instead.\n\n```js\nconst {Heap} = require('binoheap');\n\n// Create a minimum-ordered heap\nconst minHeap = new Heap((x, y) =\u003e x.key - y.key);\n\nminHeap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nminHeap.removeExtremum();\n//=\u003e Node { key: 10, value: 'A', degree: 1, parent: null, child: [Node], sibling: null }\nminHeap;\n//=\u003e Heap {\n// size: 2,\n// head: Node { key: 20, value: 'B', degree: 1, parent: null, child: [Node], sibling: null } }\n\n// Create a maximum-ordered heap\nconst maxHeap = new Heap((x, y) =\u003e y.key - x.key);\n\nmaxHeap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nmaxHeap.removeExtremum();\n//=\u003e Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] }\nmaxHeap;\n//=\u003e Heap {\n// size: 2,\n// head: Node { key: 20, value: 'B', degree: 1, parent: null, child: [Node], sibling: null } }\n```\n\n#### heap.`roots()`\n\n- Return Type: `Array\u003cNode\u003e`\n\nTraverses the root nodes of the binomial trees residing in the heap and stores of each traversed root node in an array. At the end of the traversal, the method returns the array which will contain all tree root nodes in ascending `degree` order.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n\nheap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nheap.roots();\n//=\u003e [\n//  Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] },\n//  Node { key: 10, value: 'A', degree: 1, parent: null, child: [Node], sibling: null }\n// ]\n```\n\n#### heap.`search(key)`\n\n- Return Type: `Node | undefined`\n\nTraverses the nodes in the binomial heap level by level, from left to right \u0026 from top to bottom, and determines whether the heap includes a node with the given `key` value, returning node itself, without mutating the heap, or `undefined` as appropriate.\n\n##### **`key`**\n\n- Type: `Number`\n\nNode `key` to search for.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n\nheap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C');\n//=\u003e Heap {\n// size: 3,\n// head: Node { key: 30, value: 'C', degree: 0, parent: null, child: null, sibling: [Node] } }\nheap.search(10);\n//=\u003e  Node { key: 10, value: 'A', degree: 1, parent: null, child: [Node], sibling: null }\nheap.includes(5);\n//=\u003e undefined\n```\n\n#### heap.`updateKey(key, newKey)`\n\n- Return Type: `Heap`\n\nTraverses the nodes in the binomial heap level by level, from left to right \u0026 from top to bottom, and determines whether the heap includes a node with the given `key` value. If the node is found then, its `key` value is mutated by replacing it with the new `newKey` one. Returns the heap itself.\n\nThe method can be used to **only decrease or increase** the key value of targeted nodes if the binomial heap is either **minimum** or **maximum** ordered.\n\n##### **`key`**\n\n- Type: `Number`\n\nCan be any number that corresponds to the `key` of an existing node.\n\n##### **`newKey`**\n\n- Type: `Number`\n\nNew number value to be used as node key.\n\n```js\nconst {Heap} = require('binoheap');\n\n// Create a minimum-ordered heap\nconst minHeap = new Heap((x, y) =\u003e x.key - y.key);\n\nminHeap\n  .insert(10, 'A')\n  .insert(20, 'B');\n//=\u003e Heap {\n// size: 2,\n// head: Node { key: 10, value: 'A', degree: 1, parent: null, child: [Node], sibling: null } }\nminHeap.head;\n//=\u003e Node { key: 10, value: 'A', degree: 1, parent: null, child: [Node], sibling: null }\nminHeap.head.child;\n//=\u003e Node { key: 20, value: 'B', degree: 0, parent: [Node], child: null, sibling: null }\n\nminHeap.updateKey(20, 5);\n//=\u003e Heap {\n// size: 2,\n// head: Node { key: 5, value: 'B', degree: 1, parent: null, child: [Node], sibling: null } }\nminHeap.head;\n//=\u003e Node { key: 5, value: 'B', degree: 1, parent: null, child: [Node], sibling: null }\nminHeap.head.child;\n//=\u003e Node { key: 10, value: 'A', degree: 0, parent: [Node], child: null, sibling: null }\n\n\n// Create a maximum-ordered heap\nconst maxHeap = new Heap((x, y) =\u003e y.key - x.key);\n\nmaxHeap\n  .insert(10, 'A')\n  .insert(20, 'B');\n//=\u003e Heap {\n// size: 2,\n// head: Node { key: 20, value: 'B', degree: 1, parent: null, child: [Node], sibling: null } }\nmaxHeap.head;\n//=\u003e Node { key: 20, value: 'B', degree: 1, parent: null, child: [Node], sibling: null }\nmaxHeap.head.child;\n//=\u003e Node { key: 10, value: 'A', degree: 0, parent: [Node], child: null, sibling: null }\n\nmaxHeap.update(10, 25);\n//=\u003e Heap {\n// size: 2,\n// head: Node { key: 25, value: 'A', degree: 1, parent: null, child: [Node], sibling: null } }\nmaxHeap.head;\n//=\u003e Node { key: 25, value: 'A', degree: 1, parent: null, child: [Node], sibling: null }\nmaxHeap.head.child;\n//=\u003e Node { key: 20, value: 'B', degree: 0, parent: [Node], child: null, sibling: null }\n```\n\nAvailable, along with the `Heap` exposed class, is the `Node` class, mainly useful for testing purposes, since it can be utilized to compare heap nodes. The class has a binary constructor method, with a `key` and a `value` parameter, corresponding to the key and the value stored in the created instance, respectively.\n\n#### node.`key`\n\n- Return Type: `Number`\n\nThe `key` corresponding to the node instance.\n\n```js\nconst {Node} = require('binoheap');\n\nconst node = new Node(10, 'A');\n// =\u003e Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: null }\nnode.key;\n//=\u003e 10\n```\n\n#### node.`value`\n\n- Return Type: `Any`\n\nThe value that the node contains.\n\n```js\nconst {Node} = require('binoheap');\n\nconst node = new Node(10, 'A');\n//=\u003e Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: null }\nnode.value;\n//=\u003e 'A'\nnode.value = 'B'\n//=\u003e Node { key: 10, value: 'B', degree: 0, parent: null, child: null, sibling: null }\nnode.value;\n//=\u003e 'B'\n```\n\n#### node.`degree`\n\n- Return Type: `Number`\n\nDegree of the node.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n//=\u003e Heap {\n// size: 0,\n// head: null }\nheap.insert(10, 'A').head;\n//=\u003e Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: null } }\nheap.head.degree;\n//=\u003e 1\nheap.insert(20, 'B').head;\n//=\u003e Node { key: 10, value: 'A', degree: 1, parent: null, child: [Node], sibling: null } }\nheap.head.degree;\n//=\u003e 1\n```\n\n#### node.`parent`\n\n- Return Type: `Node | null`\n\nThe parent node of the node instance.\n\n```js\nconst {Node} = require('binoheap');\n\nconst node1 = new Node(10, 'A');\n// =\u003e Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: null }\nnode1.parent;\n//=\u003e null\nconst node2 = new Node(20, 'B');\n// =\u003e Node { key: 20, value: 'B', degree: 0, parent: null, child: null, sibling: null }\nnode1.parent = node2;\n// =\u003e Node { key: 10, value: 'A', degree: 0, parent: [Node], child: null, sibling: null }\n```\n\n#### node.`child`\n\n- Return Type: `Node | null`\n\nThe child node of the node instance.\n\n```js\nconst {Node} = require('binoheap');\n\nconst node1 = new Node(10, 'A');\n// =\u003e Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: null }\nnode1.child;\n//=\u003e null\nconst node2 = new Node(20, 'B');\n// =\u003e Node { key: 20, value: 'B', degree: 0, parent: null, child: null, sibling: null }\nnode1.child = node2;\n// =\u003e Node { key: 10, value: 'A', degree: 0, parent: null, child: [Node], sibling: null }\n```\n\n#### node.`sibling`\n\n- Return Type: `Node | null`\n\nThe sibling node of the node instance.\n\n```js\nconst {Node} = require('binoheap');\n\nconst node1 = new Node(10, 'A');\n// =\u003e Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: null }\nnode1.sibling;\n//=\u003e null\nconst node2 = new Node(20, 'B');\n// =\u003e Node { key: 20, value: 'B', degree: 0, parent: null, child: null, sibling: null }\nnode1.sibling = node2;\n// =\u003e Node { key: 10, value: 'A', degree: 0, parent: null, child: null, sibling: [Node] }\n```\n\n#### node.`siblings()`\n\n- Return Type: `Array\u003cNode\u003e`\n\nTraverses all sibling nodes of the `Node` instance and stores them in an array. The array is returned at the end of the traversal.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n//=\u003e Heap {\n// size: 0,\n// head: null } }\nheap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C')\n  .insert(40, 'D')\n  .insert(50, 'E')\n  .insert(60, 'F')\n  .insert(70, 'G');\n//=\u003e Heap {\n// size: 7,\n// head: Node { key: 70, value: 'G', degree: 0, parent: null, child: [Node], sibling: null } }\nheap.head.siblings();\n//=\u003e [\n// Node { key: 50, value: 'E', degree: 1, parent: null, child: [Node], sibling: [Node] },\n// Node { key: 10, value: 'A', degree: 2, parent: null, child: [Node], sibling: null }\n// ]\n```\n\n#### node.`descendants()`\n\n- Return Type: `Array\u003cNode\u003e`\n\nTraverses all the descendant nodes of the `Node` instance, through the `Node#child` pointer, and stores each one of them in an array. The array is returned at the end of the traversal.\n\n```js\nconst {Heap} = require('binoheap');\n\nconst heap = new Heap();\n//=\u003e Heap {\n// size: 0,\n// head: null } }\nheap\n  .insert(10, 'A')\n  .insert(20, 'B')\n  .insert(30, 'C')\n  .insert(40, 'D');\n//=\u003e Heap {\n// size: 7,\n// head: Node { key: 10, value: 'A', degree: 2, parent: null, child: [Node], sibling: null } }\nheap.head.descendants();\n//=\u003e [\n// Node { key: 30, value: 'C', degree: 1, parent: [Node], child: [Node], sibling: [Node] },\n// Node { key: 40, value: 'D', degree: 0, parent: [Node], child: , sibling: null }\n// ]\n```\n\n#### node.`toPair()`\n\n- Return Type: `[Number, Any]`\n\nReturns an ordered-pair/2-tuple, where the first element is a number corresponding to the `key` of the node, and the last one is a value, that can be of any type, corresponding to the `value` stored in the node.\n\n```js\nconst {Heap, Node} = require('binoheap');\n\nconst heap = new Heap();\nconst node = new Node(5, 'B');\n\nnode.toPair();\n//=\u003e [5, 'B']\nheap.insert(10, 'A').head.toPair();\n//=\u003e [10, 'A']\n```\n\n## Development\n\nFor more info on how to contribute to the project, please read the [contributing guidelines](https://github.com/klaussinani/binoheap/blob/master/contributing.md).\n\n- Fork the repository and clone it to your machine\n- Navigate to your local fork: `cd binoheap`\n- Install the project dependencies: `npm install` or `yarn install`\n- Lint the code and run the tests: `npm test` or `yarn test`\n\n## Related\n\n- [avlbinstree](https://github.com/klaussinani/avlbinstree) - AVL self-balancing binary search trees for ES6\n- [binstree](https://github.com/klaussinani/binstree) - Binary search trees for ES6\n- [doublie](https://github.com/klaussinani/doublie) - Doubly circular \u0026 linear linked lists for ES6\n- [dsforest](https://github.com/klaussinani/dsforest) - Disjoint-set forests for ES6\n- [kiu](https://github.com/klaussinani/kiu) - FIFO Queues for ES6\n- [mheap](https://github.com/klaussinani/mheap) - Binary min \u0026 max heaps for ES6\n- [prioqueue](https://github.com/klaussinani/prioqueue) - Priority queues for ES6\n- [singlie](https://github.com/klaussinani/singlie) - Singly circular \u0026 linear linked lists for ES6\n\n## Team\n\n- Klaus Sinani [(@klaussinani)](https://github.com/klaussinani)\n\n## License\n\n[MIT](https://github.com/klaussinani/binoheap/blob/master/license.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklaudiosinani%2Fbinoheap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklaudiosinani%2Fbinoheap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklaudiosinani%2Fbinoheap/lists"}