{"name":"kdbush","version":"4.0.0","description":"A very fast static 2D index for points based on kd-tree.","type":"module","main":"kdbush.js","module":"index.js","exports":"./index.js","types":"index.d.ts","sideEffects":false,"repository":{"type":"git","url":"git://github.com/mourner/kdbush.git"},"devDependencies":{"@rollup/plugin-terser":"^0.4.1","eslint":"^8.38.0","eslint-config-mourner":"^3.0.0","rollup":"^3.20.6","typescript":"^5.0.4"},"scripts":{"pretest":"eslint index.js test.js bench.js rollup.config.js","test":"tsc && node test.js","bench":"node bench.js","build":"rollup -c","prepublishOnly":"npm run test && npm run build"},"eslintConfig":{"extends":"mourner"},"keywords":["index","points","kd-tree","data structures","algorithms","spatial","geometry"],"author":{"name":"Vladimir Agafonkin"},"license":"ISC","gitHead":"04767a26c203927fc6cd22845c0cbd96f51634a3","bugs":{"url":"https://github.com/mourner/kdbush/issues"},"homepage":"https://github.com/mourner/kdbush#readme","_id":"kdbush@4.0.0","_nodeVersion":"18.16.0","_npmVersion":"9.6.4","dist":{"integrity":"sha512-5K6IvqkwyjbcBvJBXAhVlT3DvWLdt4YR3xN8KUvqQuf7dQ9BNT54hAdSZJ9BWc2+7ZrUcmjlhYB5ILbeGN4/Eg==","shasum":"2491f246b6ded6d93440fc4f5c58d1c04bca44bf","tarball":"http://registry-npm.ywwl.com/kdbush/download/kdbush-4.0.0.tgz","fileCount":6,"unpackedSize":23046,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAiFhZxtqU4oI8cLv15Fddbk1JdYuLytNG+PJ5Q+4fm3AiAQ/e/T1ANYJkc+37O9i61YDPsoXKE2hTtM1ymmEJHMcg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQZZ/ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqOyA//XJmPDEZAc0kh/oRIwakFP6C7ML2b9yIuGVCV4es5ADDtDZ/d\r\niLussQx/+s7+mzHDZb6D2GoimFyj4bRKi/SREEjqP11CptPCxmNUjTbRFdSV\r\ni33nalhWl3bOjRFhw7zEb0n6iAaUbSslW1gq3VLT0yt8OsFg0BTVl2s8dm3e\r\nTrhpJGvzajq4z2n6zuKhl7LQld0ohCd47EnGa5eeT2zSL/8iZB7sy+kB4Hg2\r\nujFdbd+mzylu0oWO4D6msnG5QRoKBadB00zIu3sUuvaHhpykTQRC5qAZ1PSM\r\nb7LCBj3e1WckEJ4r/rrwCBG0eGWSVw7tFh2HLQ20Ef250YdRG91Z971AaWDi\r\nmzuHjjXT2jt/fiNu96VR28kEx0S3V1FHaL+nFCLj2XPBRBWkSmsMjqq3JM8s\r\n1nrCc8FCGO0AYtYezdljGjr32vM5PKerEEKVm7fR9A8dooMwpZ6Da7AiyNZQ\r\nkz2B7DuWkITJIkmEnY+bRkHDG135erSe/SxC73madaxJxK3Bjvxx6PmNIuUq\r\ni95DpTRlkvmPuJUj1DuYa2BdItLhP/rTdTtISH4xbsm1lf+MFJAgV59Dja9d\r\nmCUDtxotBB0uwJaZqshcO06VPXIiANtMnTLuJWKf4dZtELD0F/SqwlBekcE4\r\n3qPaBRLrEuWaVjHHlOP1fI0DEa8uIjmuBm0=\r\n=8TOL\r\n-----END PGP SIGNATURE-----\r\n","size":7002,"noattachment":false,"key":"/kdbush/-/kdbush-4.0.0.tgz"},"_npmUser":{"name":"mourner","email":"agafonkin@gmail.com"},"directories":{},"maintainers":[{"name":"mourner","email":"agafonkin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/kdbush_4.0.0_1682019967151_0.4591961560630047"},"_hasShrinkwrap":false,"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 => 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<script type=\"module\">\n    import KDBush from 'https://cdn.jsdelivr.net/npm/kdbush/+esm';\n</script>\n```\n\nAlternatively, there's a browser bundle with a `KDBush` global variable:\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/kdbush\"></script>\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","publish_time":1682019967322,"_cnpm_publish_time":1682019967322,"dist-tags":{"latest":"4.1.0"}}