{"id":20145754,"url":"https://github.com/obsius/score-heap","last_synced_at":"2026-02-06T18:09:04.339Z","repository":{"id":215728027,"uuid":"697586372","full_name":"obsius/score-heap","owner":"obsius","description":" A heap optimized for frequent updates.","archived":false,"fork":false,"pushed_at":"2024-07-23T02:12:14.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-06T11:50:24.605Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/obsius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-09-28T03:44:55.000Z","updated_at":"2024-07-23T02:12:18.000Z","dependencies_parsed_at":"2024-01-06T06:55:29.216Z","dependency_job_id":null,"html_url":"https://github.com/obsius/score-heap","commit_stats":null,"previous_names":["obsius/score-heap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/obsius/score-heap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Fscore-heap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Fscore-heap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Fscore-heap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Fscore-heap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/obsius","download_url":"https://codeload.github.com/obsius/score-heap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Fscore-heap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265553393,"owners_count":23787069,"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":[],"created_at":"2024-11-13T22:18:01.346Z","updated_at":"2026-02-06T18:08:59.313Z","avatar_url":"https://github.com/obsius.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ScoreHeap\n\n A heap optimized for frequent updates.\n Maintains a sorted list with partitions so only items within a modified partition need to be reindexed.\n Returns the highest score (int32) in the heap, else null if the heap is empty.\n\n### Working Example\n\n```js\nimport ScoreHeap from 'score-heap';\n\nlet objs = [];\nlet scores = [];\n\n// make a million entries with score = array index\nfor (let i = 0; i \u003c 1000000; ++i) {\n\n\t// this is the source array, the entries can be anything\n\tobjs.push({ i });\n\n\t// initial scores will be passed into the new ScoreHeap below (a score must always be an int32)\n\tscores.push([i, i]);\n}\n\n// construct a ScoreHeap with objs scores and a max length\nlet heap = new ScoreHeap(scores, scores.length);\n\nconsole.time();\n\n// get the next highest scoring index and remove it, then update the next entry with a random score\n// 1M next() + remove() + update() each\nfor (let i; (i = heap.next()) != null;) {\n\n\theap.remove(i, objs[i].i);\n\n\tif (i \u003c objs.length - 1) {\n\t\theap.update(i + 1, Math.floor(Math.random() * objs.length));\n\t}\n}\n\nconsole.timeEnd();\n\n// ScoreHeap does not care about your underlying data structure.\n// Its only purpose is to make retrieving, updating, and removing scored array entries as fast as possible.\n\n```\n\n## Methods\n\n### constructor(indexScores, maxLength)\n\nMake a new ScoreHeap.\n\n`indexScores` An array of [index, score] to build the heap from (score must be an int32)\n`maxLength` The length of the underlying (unpassed) source array (must never expand beyond this value)\n\nReturns a new ScoreHeap.\n\n### next()\n\nGet the highest scoring index.\n\nReturns the index with the highest score in the heap.\n\n### update(index, score)\n\nUpdate an index in the heap (index does not have to be in the heap yet).\n \n`index` Index to update (or insert)\n`score` Score of the index (must be an int32)\n\n### remove(index)\n\nRemove an index from the heap.\n \n`index` Index to remove\n\nReturns the index passed in if successful, else undefined.\n\n## Performance\n\n...\n\n## TODO\n\n...\n\n## Contributing\n\nFeel free to make changes and submit pull requests whenever.\n\n## License\n\nScoreHeap uses the [MIT](https://opensource.org/licenses/MIT) license.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobsius%2Fscore-heap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fobsius%2Fscore-heap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobsius%2Fscore-heap/lists"}