{"id":19557339,"url":"https://github.com/andrefs/avl-promise","last_synced_at":"2026-06-15T15:32:02.921Z","repository":{"id":57187857,"uuid":"130925233","full_name":"andrefs/avl-promise","owner":"andrefs","description":"Largely copied from avl (https://www.npmjs.com/package/avl), but with a Promise-based comparator!","archived":false,"fork":false,"pushed_at":"2018-06-22T09:07:17.000Z","size":140,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-09T01:54:13.235Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/avl-promise","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/andrefs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-24T23:35:29.000Z","updated_at":"2018-06-22T09:07:18.000Z","dependencies_parsed_at":"2022-08-28T10:51:31.623Z","dependency_job_id":null,"html_url":"https://github.com/andrefs/avl-promise","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andrefs/avl-promise","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrefs%2Favl-promise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrefs%2Favl-promise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrefs%2Favl-promise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrefs%2Favl-promise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrefs","download_url":"https://codeload.github.com/andrefs/avl-promise/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrefs%2Favl-promise/sbom","scorecard":{"id":192600,"data":{"date":"2025-08-11","repo":{"name":"github.com/andrefs/avl-promise","commit":"7e12a4eff189d947cf5ec18b463b59d6bd78dd09"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"58 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx","Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-hr2v-3952-633q","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-r9q4-w3fm-wrm2","Warn: Project is vulnerable to: GHSA-vh5w-fg69-rc8m","Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97","Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq","Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq","Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm","Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546","Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm","Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574","Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-g6ww-v8xp-vmwg","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-jv35-xqg7-f92r","Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3","Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7","Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-332q-7ff2-57h2"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-16T21:06:30.897Z","repository_id":57187857,"created_at":"2025-08-16T21:06:30.897Z","updated_at":"2025-08-16T21:06:30.897Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34369840,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-11T04:41:50.843Z","updated_at":"2026-06-15T15:32:02.882Z","avatar_url":"https://github.com/andrefs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AVL tree \n\nPromise-based [AVL-tree](https://en.wikipedia.org/wiki/AVL_tree):\nLargely copied from [avl](https://www.npmjs.com/package/avl), but the\ncomparator function returns a Promise!\n\nExisting AVL modules perform all operations synchronously. But what if\nyour custom `comparator` function is asynchronous? -- for example, if\nyou need to perform a database query, a network request or wait\nfor a user's input.\n\n[avl-promise](https://www.npmjs.com/package/avl-promise) to the\nrescue! However, the performance takes a hit -- even if your async\ncomparator immediatly resolves to a numeric value. So, **use with\ncaution and at your own risk**.\n\n| Operation     | Average       | Worst case   |\n| ------------- | ------------- | ------------ |\n| Space         | **O(n)**      | **O(n)**     |\n| Search        | **O(log n)**  | **O(log n)** |\n| Insert        | **O(log n)**  | **O(log n)** |\n| Delete        | **O(log n)**  | **O(log n)** |\n\n## Install\n\n```shell\nnpm i -S avl-promise\n```\n\n```js\nimport AVLTree from 'avl-promise';\nconst tree = new AVLTree();\n```\n\nOr use the compiled version 'dist/avl-promise.js'.\n\n[Try it in your browser](https://npm.runkit.com/avl-promise)\n\n## API\n\n### Synchronous methods\n\n* `new AVLTree([compare], [noDuplicates:Boolean])`, where `compare` is optional comparison Promise-returning function\n* `tree.at(index:Number):Node|Null` - Return node by its index in sorted order of keys\n* `tree.forEach(function(node) {...}):Tree` In-order traversal\n* `tree.keys():Array\u003ckey\u003e` - Returns the array of keys in order\n* `tree.values():Array\u003c*\u003e` - Returns the array of data fields in order\n* `tree.pop():Node` - Removes smallest node\n* `tree.min():key` - Returns min key\n* `tree.max():key` - Returns max key\n* `tree.minNode():Node` - Returns the node with smallest key\n* `tree.maxNode():Node` - Returns the node with highest key\n* `tree.prev(node):Node` - Predecessor node\n* `tree.next(node):Node` - Successor node\n\n### Promise methods\n\nThe following methods are dependent on the `compare` function and, as\nsuch, return Promises.\n\n* `tree.insert(key:any, [data:any])` - Insert item\n* `tree.find(key):Node|Null` - Return node by its key\n* `tree.contains(key):Boolean` - Whether a node with the given key is in the tree\n* `tree.load(keys:Array\u003c*\u003e, [values:Array\u003c*\u003e]):Tree` - Bulk-load items\n* `tree.remove(key:any)` - Remove item\n* `tree.range(lo, high, function(node) {} [, context]):Tree` - Walks the range of keys in order. Stops, if the visitor function returns a non-zero value.\n\n**Comparator**\n\n`function(a:key,b:key):Promise(Number)` - Comparator function between two keys, it resolves to:\n * `0` if the keys are equal\n * `\u003c0` if `a \u003c b`\n * `\u003e0` if `a \u003e b`\n\n The comparator function is extremely important, in case of errors you might end\n up with a wrongly constructed tree or would not be able to retrieve your items.\n It is crucial to test the return values of your `comparator(a,b)` and `comparator(b,a)`\n to make sure it's working correctly, otherwise you may have bugs that are very\n unpredictable and hard to catch.\n\n **Duplicate keys**\n\n By default, tree allows duplicate keys. You can disable that by passing `true`\n as a second parameter to the tree constructor. In that case if you would try to\n instert an item with the key, that is already present in the tree, it will not\n be inserted.\n However, the default behavior allows for duplicate keys, cause there are cases\n where you cannot predict that the keys would be unique (example: overlapping\n points in 2D).\n\n## Example\n\n```js\nimport Tree from 'avl';\n\nconst t = new Tree();\nt.insert(5)\n  .then(t.insert(-10))\n  .then(t.insert(0))\n  .then(t.insert(33))\n  .then(t.insert(2))\n  .then(() =\u003e {\n    console.log(t.keys()); // [-10, 0, 2, 5, 33]\n    console.log(t.size);   // 5\n    console.log(t.min());  // -10\n    console.log(t.max());  // -33\n\n    return t.remove(0);\n  })\n  .then(() =\u003e console.log(t.size));   // 4\n```\n\n**Custom comparator (reverse sort)**\n\n```js\nimport Tree from 'avl';\n\nconst t = new Tree((a, b) =\u003e b - a);\nt.insert(5)\n  .then(() =\u003e t.insert(-10))\n  .then(() =\u003e t.insert(0))\n  .then(() =\u003e t.insert(33))\n  .then(() =\u003e t.insert(2))\n  .then(() =\u003e console.log(t.keys())); // [33, 5, 2, 0, -10]\n```\n\n**Bulk insert**\n\n```js\nimport Tree from 'avl';\n\nconst t = new Tree();\nt.load([3,2,-10,20], ['C', 'B', 'A', 'D'])\n  .then(() =\u003e {\n    console.log(t.keys());   // [-10, 2, 3, 20]\n    console.log(t.values()); // ['A', 'B', 'C', 'D']\n  });\n```\n\n## Benchmarks\n\n```shell\nnpm run benchmark\n```\n\n```\nInsert (x1000)\nBintrees x 3,276 ops/sec ±5.03% (71 runs sampled)\nFunctional red black tree x 1,648 ops/sec ±9.58% (70 runs sampled)\nGoogle Closure library AVL x 564 ops/sec ±8.28% (76 runs sampled)\nAVL (sync version) x 5,585 ops/sec ±2.74% (83 runs sampled)\nAVL Promise (current) x 2.98 ops/sec ±11.09% (19 runs sampled)\n- Fastest is AVL (sync version)\n\nRandom read (x1000)\nBintrees x 17,922 ops/sec ±4.22% (82 runs sampled)\nFunctional red black tree x 12,898 ops/sec ±6.93% (81 runs sampled)\nGoogle Closure library AVL x 21.69 ops/sec ±11.76% (41 runs sampled)\nAVL (sync version) x 9,884 ops/sec ±14.96% (65 runs sampled)\nAVL Promise (current) x 33.90 ops/sec ±24.63% (48 runs sampled)\n- Fastest is Bintrees\n\nRemove (x1000)\nBintrees x 169,381 ops/sec ±5.63% (73 runs sampled)\nFunctional red black tree x 20,195 ops/sec ±28.25% (62 runs sampled)\nGoogle Closure library AVL x 25,000 ops/sec ±11.19% (77 runs sampled)\nAVL (sync version) x 108,944 ops/sec ±1.17% (86 runs sampled)\nAVL Promise (current) x 122 ops/sec ±3.17% (70 runs sampled)\n- Fastest is Bintrees\n```\n\nAdding google closure library to the benchmark is, of course, unfair, cause the\nnode.js version of it is not optimised by the compiler, but in this case it\nplays the role of straight-forward robust implementation.\n\n## Develop\n\n```shell\nnpm i\nnpm t\nnpm run build\n```\n## Acknowledgements\n\nMany thanks to [Alexander\nMilevski](https://github.com/w8r), whoose module\n[avl](https://www.npmjs.com/package/avl) was adapted (both the code\nand the docs), with just the minimum changes needed to make it work\nasynchronously, to create\n[avl-promise](https://www.npmjs.com/package/avl-promise).\n\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2018 André Santos \u003candrefs@andrefs.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrefs%2Favl-promise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrefs%2Favl-promise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrefs%2Favl-promise/lists"}