{"id":16126794,"url":"https://github.com/mikolalysenko/static-range-query","last_synced_at":"2025-03-18T13:31:46.082Z","repository":{"id":8139793,"uuid":"9558465","full_name":"mikolalysenko/static-range-query","owner":"mikolalysenko","description":"Static range trees in JavaScript","archived":false,"fork":false,"pushed_at":"2013-05-14T00:13:53.000Z","size":140,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T10:01:36.855Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikolalysenko.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":"2013-04-20T03:05:43.000Z","updated_at":"2021-06-14T03:30:26.000Z","dependencies_parsed_at":"2022-08-24T03:30:19.096Z","dependency_job_id":null,"html_url":"https://github.com/mikolalysenko/static-range-query","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Fstatic-range-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Fstatic-range-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Fstatic-range-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Fstatic-range-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikolalysenko","download_url":"https://codeload.github.com/mikolalysenko/static-range-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243933378,"owners_count":20370989,"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-10-09T21:40:24.941Z","updated_at":"2025-03-18T13:31:45.802Z","avatar_url":"https://github.com/mikolalysenko.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"static-range-query\n==================\nGiven a collection of points in n-dimensional space, preprocesses these points so that orthogonal range queries can be computed efficiently.  Internally, this library is built using range trees.\n\n# Example\n\n```javascript\nvar preprocess = require(\"static-range-query\")\n\n//Generate 10000 3D points\nvar D = 3, N = 10000\nvar points = new Array(N)\nfor(var i=0; i\u003cN; ++i) {\n  var p = new Array(D)\n  for(var j=0; j\u003cN; ++j) {\n    p[j] = Math.random() * 1000\n  }\n  points[i] = p\n}\n\n//Construct query data structure\nvar rangeQuery = preprocess(points)\n\n//Now execute a range query!\nrangeQuery([2, 5, 0.25, -10], [10, 50, 5, 30], function(i) {\n  console.log(\"In range: \", i , points[i])\n})\n```\n\n# Install\n\n    npm install static-range-query\n    \n# API\n\n### `var rangeQuery = require(\"static-range-query\")(points)`\nPreprocesses the point set so that orthogonal range queries can be evaluated efficiently.\n\n* `points` is an array of points (each point is represented as a tuple of D numbers)\n\n**Returns** A `rangeSearch()` function (see below) which evaluates range queries on the point set.\n\n**Time Complexity** `O(points.length * log(points.length)^points[0].length)`\n\n**Space Complexity** `O(points.length * log(points.length)^points[0].length)`\n\n**Notes** Internally, this function builds a range tree and binds it to the query method\n\n### `rangeQuery(lo, hi, cb(index))`\nEvaluates a range query on the point set.\n\n* `lo` is a lower bound on the bounding rectangle to query\n* `hi` is an upper bound on the bounding rectangle to query\n* `cb` is a callback which gets called once per each point in the range with the index of a point.\n\n\n**Time Complexity** `O(log(points.length)^points[0].length + k)` where `k` is the number of points processed in the range.\n\n**Note** The points are visited in lexicographic order\n\n**Other Note** You can terminate the search early by returning `true` from `cb`, for example:\n\n```javascript\nrangeQuery([0, 0, 0], [100, 100, 100], function(i) {\n\n  if(i === 100) {\n    console.log(\"found it!\")\n    return true\n  }\n\n  //Continue processing ....\n  return false\n})\n```\n\n## When should I use this library?\n\nPreprocessing the point set is relatively slow, mostly due to the creation of many typed arrays.  On the other hand, queries are pretty fast with this library.  If you are only going to do a few queries, you are better off using brute force.  On the other hand, if you have a big data set and are willing to wait for preprocessing to finish, then this library may be a good choice for you.\n\n# Credits\n(c) 2013 Mikola Lysenko. MIT License","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikolalysenko%2Fstatic-range-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikolalysenko%2Fstatic-range-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikolalysenko%2Fstatic-range-query/lists"}