{"id":17918793,"url":"https://github.com/mourner/kdbush","last_synced_at":"2025-05-14T15:09:41.659Z","repository":{"id":43673076,"uuid":"55738791","full_name":"mourner/kdbush","owner":"mourner","description":"A fast static index for 2D points","archived":false,"fork":false,"pushed_at":"2024-09-24T09:18:12.000Z","size":87,"stargazers_count":654,"open_issues_count":5,"forks_count":73,"subscribers_count":24,"default_branch":"main","last_synced_at":"2025-04-02T18:08:54.778Z","etag":null,"topics":["2d-points","algorithm","computational-geometry","fast","javascript","spatial-index"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mourner.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-08T01:01:21.000Z","updated_at":"2025-03-24T08:57:37.000Z","dependencies_parsed_at":"2024-06-18T12:15:04.807Z","dependency_job_id":"9078433e-3ccc-4e1a-9e8f-8f01f3eaff43","html_url":"https://github.com/mourner/kdbush","commit_stats":{"total_commits":47,"total_committers":7,"mean_commits":6.714285714285714,"dds":"0.12765957446808507","last_synced_commit":"ae9f3710e0e6f50f6f0235dcdc53d5caba31d77d"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mourner%2Fkdbush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mourner%2Fkdbush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mourner%2Fkdbush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mourner%2Fkdbush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mourner","download_url":"https://codeload.github.com/mourner/kdbush/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294516,"owners_count":20915340,"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":["2d-points","algorithm","computational-geometry","fast","javascript","spatial-index"],"created_at":"2024-10-28T20:12:52.145Z","updated_at":"2025-04-09T19:16:13.963Z","avatar_url":"https://github.com/mourner.png","language":"JavaScript","readme":"## KDBush\n\nA very fast static spatial index for 2D points based on a flat KD-tree.\nCompared to [RBush](https://github.com/mourner/rbush):\n\n- **Points only** — no rectangles.\n- **Static** — you can't add/remove items after initial indexing.\n- **Faster** indexing and search, with lower **memory** footprint.\n- Index is stored as a single **array buffer** (so you can [transfer](https://developer.mozilla.org/en-US/docs/Glossary/Transferable_objects) it between threads or store it as a compact file).\n\n\nIf you need a static index for rectangles, not only points, see [Flatbush](https://github.com/mourner/flatbush). When indexing points, KDBush has the advantage of taking ~2x less memory than Flatbush.\n\n[![Build Status](https://github.com/mourner/kdbush/workflows/Node/badge.svg?branch=master)](https://github.com/mourner/kdbush/actions)\n[![Simply Awesome](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects)\n\n## Usage\n\n```js\n// initialize KDBush for 1000 items\nconst index = new KDBush(1000);\n\n// fill it with 1000 points\nfor (const {x, y} of items) {\n    index.add(x, y);\n}\n\n// perform the indexing\nindex.finish();\n\n// make a bounding box query\nconst foundIds = index.range(minX, minY, maxX, maxY);\n\n// map ids to original items\nconst foundItems = foundIds.map(i =\u003e items[i]);\n\n// make a radius query\nconst neighborIds = index.within(x, y, 5);\n\n// instantly transfer the index from a worker to the main thread\npostMessage(index.data, [index.data]);\n\n// reconstruct the index from a raw array buffer\nconst index = KDBush.from(e.data);\n```\n\n## Install\n\nInstall with NPM: `npm install kdbush`, then import as a module:\n\n```js\nimport KDBush from 'kdbush';\n```\n\nOr use as a module directly in the browser with [jsDelivr](https://www.jsdelivr.com/esm):\n\n```html\n\u003cscript type=\"module\"\u003e\n    import KDBush from 'https://cdn.jsdelivr.net/npm/kdbush/+esm';\n\u003c/script\u003e\n```\n\nAlternatively, there's a browser bundle with a `KDBush` global variable:\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/kdbush\"\u003e\u003c/script\u003e\n```\n\n## API\n\n#### new KDBush(numItems[, nodeSize, ArrayType])\n\nCreates an index that will hold a given number of points (`numItems`). Additionally accepts:\n\n- `nodeSize`: Size of the KD-tree node, `64` by default. Higher means faster indexing but slower search, and vise versa.\n- `ArrayType`: Array type to use for storing coordinate values. `Float64Array` by default, but if your coordinates are integer values, `Int32Array` makes the index faster and smaller.\n\n#### index.add(x, y)\n\nAdds a given point to the index. Returns a zero-based, incremental number that represents the newly added point.\n\n#### index.range(minX, minY, maxX, maxY)\n\nFinds all items within the given bounding box and returns an array of indices that refer to the order the items were added (the values returned by `index.add(x, y)`).\n\n#### index.within(x, y, radius)\n\nFinds all items within a given radius from the query point and returns an array of indices.\n\n#### `KDBush.from(data)`\n\nRecreates a KDBush index from raw `ArrayBuffer` data\n(that's exposed as `index.data` on a previously indexed KDBush instance).\nVery useful for transferring or sharing indices between threads or storing them in a file.\n\n### Properties\n\n- `data`: array buffer that holds the index.\n- `numItems`: number of stored items.\n- `nodeSize`: number of items in a KD-tree node.\n- `ArrayType`: array type used for internal coordinates storage.\n- `IndexArrayType`: array type used for internal item indices storage.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmourner%2Fkdbush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmourner%2Fkdbush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmourner%2Fkdbush/lists"}