Socket
Socket
Sign inDemoInstall

flatbush

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flatbush - npm Package Compare versions

Comparing version 3.3.0 to 3.3.1

24

flatbush.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.Flatbush = factory());
}(this, (function () { 'use strict';
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Flatbush = factory());
})(this, (function () { 'use strict';

@@ -74,2 +74,3 @@ var FlatQueue = function FlatQueue() {

FlatQueue.prototype.peek = function peek () {
if (this.length === 0) { return undefined; }
return this.ids[0];

@@ -79,2 +80,3 @@ };

FlatQueue.prototype.peekValue = function peekValue () {
if (this.length === 0) { return undefined; }
return this.values[0];

@@ -202,4 +204,4 @@ };

var width = this.maxX - this.minX;
var height = this.maxY - this.minY;
var width = (this.maxX - this.minX) || 1;
var height = (this.maxY - this.minY) || 1;
var hilbertValues = new Uint32Array(this.numItems);

@@ -319,7 +321,7 @@ var hilbertMax = (1 << 16) - 1;

if (filterFn === undefined || filterFn(index)) {
// put a negative index if it's an item rather than a node, to recognize later
q.push(-index - 1, dist);
// put an odd index if it's an item rather than a node, to recognize later
q.push((index << 1) + 1, dist);
}
} else {
q.push(index, dist);
q.push(index << 1, dist);
}

@@ -329,3 +331,3 @@ }

// pop items from the queue
while (q.length && q.peek() < 0) {
while (q.length && (q.peek() & 1)) {
var dist$1 = q.peekValue();

@@ -336,3 +338,3 @@ if (dist$1 > maxDistSquared) {

}
results.push(-q.pop() - 1);
results.push(q.pop() >> 1);

@@ -345,3 +347,3 @@ if (results.length === maxResults) {

nodeIndex = q.pop();
nodeIndex = q.pop() >> 1;
}

@@ -468,2 +470,2 @@

})));
}));

@@ -1,1 +0,1 @@

!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t=t||self).Flatbush=i()}(this,(function(){"use strict";var t=function(){this.ids=[],this.values=[],this.length=0};t.prototype.clear=function(){this.length=0},t.prototype.push=function(t,i){var s=this.length++;for(this.ids[s]=t,this.values[s]=i;s>0;){var e=s-1>>1,h=this.values[e];if(i>=h)break;this.ids[s]=this.ids[e],this.values[s]=h,s=e}this.ids[s]=t,this.values[s]=i},t.prototype.pop=function(){if(0!==this.length){var t=this.ids[0];if(this.length--,this.length>0){for(var i=this.ids[0]=this.ids[this.length],s=this.values[0]=this.values[this.length],e=this.length>>1,h=0;h<e;){var r=1+(h<<1),n=r+1,o=this.ids[r],a=this.values[r],u=this.values[n];if(n<this.length&&u<a&&(r=n,o=this.ids[n],a=u),a>=s)break;this.ids[h]=o,this.values[h]=a,h=r}this.ids[h]=i,this.values[h]=s}return t}},t.prototype.peek=function(){return this.ids[0]},t.prototype.peekValue=function(){return this.values[0]};var i=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],s=function(s,e,h,r){if(void 0===e&&(e=16),void 0===h&&(h=Float64Array),void 0===s)throw new Error("Missing required argument: numItems.");if(isNaN(s)||s<=0)throw new Error("Unpexpected numItems value: "+s+".");this.numItems=+s,this.nodeSize=Math.min(Math.max(+e,2),65535);var n=s,o=n;this._levelBounds=[4*n];do{o+=n=Math.ceil(n/this.nodeSize),this._levelBounds.push(4*o)}while(1!==n);this.ArrayType=h||Float64Array,this.IndexArrayType=o<16384?Uint16Array:Uint32Array;var a=i.indexOf(this.ArrayType),u=4*o*this.ArrayType.BYTES_PER_ELEMENT;if(a<0)throw new Error("Unexpected typed array class: "+h+".");r&&r instanceof ArrayBuffer?(this.data=r,this._boxes=new this.ArrayType(this.data,8,4*o),this._indices=new this.IndexArrayType(this.data,8+u,o),this._pos=4*o,this.minX=this._boxes[this._pos-4],this.minY=this._boxes[this._pos-3],this.maxX=this._boxes[this._pos-2],this.maxY=this._boxes[this._pos-1]):(this.data=new ArrayBuffer(8+u+o*this.IndexArrayType.BYTES_PER_ELEMENT),this._boxes=new this.ArrayType(this.data,8,4*o),this._indices=new this.IndexArrayType(this.data,8+u,o),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(this.data,0,2).set([251,48+a]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=s),this._queue=new t};function e(t,i,s){return t<i?i-t:t<=s?0:t-s}function h(t,i){for(var s=0,e=i.length-1;s<e;){var h=s+e>>1;i[h]>t?e=h:s=h+1}return i[s]}function r(t,i,s,e,h){var r=t[e];t[e]=t[h],t[h]=r;var n=4*e,o=4*h,a=i[n],u=i[n+1],d=i[n+2],p=i[n+3];i[n]=i[o],i[n+1]=i[o+1],i[n+2]=i[o+2],i[n+3]=i[o+3],i[o]=a,i[o+1]=u,i[o+2]=d,i[o+3]=p;var _=s[e];s[e]=s[h],s[h]=_}function n(t,i){var s=t^i,e=65535^s,h=65535^(t|i),r=t&(65535^i),n=s|e>>1,o=s>>1^s,a=h>>1^e&r>>1^h,u=s&h>>1^r>>1^r;o=(s=n)&(e=o)>>2^e&(s^e)>>2,a^=s&(h=a)>>2^e&(r=u)>>2,u^=e&h>>2^(s^e)&r>>2,o=(s=n=s&s>>2^e&e>>2)&(e=o)>>4^e&(s^e)>>4,a^=s&(h=a)>>4^e&(r=u)>>4,u^=e&h>>4^(s^e)&r>>4,a^=(s=n=s&s>>4^e&e>>4)&(h=a)>>8^(e=o)&(r=u)>>8;var d=t^i,p=(e=(u^=e&h>>8^(s^e)&r>>8)^u>>1)|65535^(d|(s=a^a>>1));return((p=1431655765&((p=858993459&((p=252645135&((p=16711935&(p|p<<8))|p<<4))|p<<2))|p<<1))<<1|(d=1431655765&((d=858993459&((d=252645135&((d=16711935&(d|d<<8))|d<<4))|d<<2))|d<<1)))>>>0}return s.from=function(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");var e=new Uint8Array(t,0,2),h=e[0],r=e[1];if(251!==h)throw new Error("Data does not appear to be in a Flatbush format.");if(r>>4!=3)throw new Error("Got v"+(r>>4)+" data when expected v3.");var n=new Uint16Array(t,2,1)[0],o=new Uint32Array(t,4,1)[0];return new s(o,n,i[15&r],t)},s.prototype.add=function(t,i,s,e){var h=this._pos>>2;return this._indices[h]=h,this._boxes[this._pos++]=t,this._boxes[this._pos++]=i,this._boxes[this._pos++]=s,this._boxes[this._pos++]=e,t<this.minX&&(this.minX=t),i<this.minY&&(this.minY=i),s>this.maxX&&(this.maxX=s),e>this.maxY&&(this.maxY=e),h},s.prototype.finish=function(){if(this._pos>>2!==this.numItems)throw new Error("Added "+(this._pos>>2)+" items when expected "+this.numItems+".");if(this.numItems<=this.nodeSize)return this._boxes[this._pos++]=this.minX,this._boxes[this._pos++]=this.minY,this._boxes[this._pos++]=this.maxX,void(this._boxes[this._pos++]=this.maxY);for(var t=this.maxX-this.minX,i=this.maxY-this.minY,s=new Uint32Array(this.numItems),e=0;e<this.numItems;e++){var h=4*e,o=this._boxes[h++],a=this._boxes[h++],u=this._boxes[h++],d=this._boxes[h++],p=Math.floor(65535*((o+u)/2-this.minX)/t),_=Math.floor(65535*((a+d)/2-this.minY)/i);s[e]=n(p,_)}!function t(i,s,e,h,n,o){if(!(Math.floor(h/o)>=Math.floor(n/o))){for(var a=i[h+n>>1],u=h-1,d=n+1;;){do{u++}while(i[u]<a);do{d--}while(i[d]>a);if(u>=d)break;r(i,s,e,u,d)}t(i,s,e,h,d,o),t(i,s,e,d+1,n,o)}}(s,this._boxes,this._indices,0,this.numItems-1,this.nodeSize);for(var f=0,l=0;f<this._levelBounds.length-1;f++)for(var x=this._levelBounds[f];l<x;){for(var m=l,v=1/0,y=1/0,b=-1/0,c=-1/0,w=0;w<this.nodeSize&&l<x;w++)v=Math.min(v,this._boxes[l++]),y=Math.min(y,this._boxes[l++]),b=Math.max(b,this._boxes[l++]),c=Math.max(c,this._boxes[l++]);this._indices[this._pos>>2]=m,this._boxes[this._pos++]=v,this._boxes[this._pos++]=y,this._boxes[this._pos++]=b,this._boxes[this._pos++]=c}},s.prototype.search=function(t,i,s,e,r){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");for(var n=this._boxes.length-4,o=[],a=[];void 0!==n;){for(var u=Math.min(n+4*this.nodeSize,h(n,this._levelBounds)),d=n;d<u;d+=4){var p=0|this._indices[d>>2];s<this._boxes[d]||e<this._boxes[d+1]||t>this._boxes[d+2]||i>this._boxes[d+3]||(n<4*this.numItems?(void 0===r||r(p))&&a.push(p):o.push(p))}n=o.pop()}return a},s.prototype.neighbors=function(t,i,s,r,n){if(void 0===s&&(s=1/0),void 0===r&&(r=1/0),this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");for(var o=this._boxes.length-4,a=this._queue,u=[],d=r*r;void 0!==o;){for(var p=Math.min(o+4*this.nodeSize,h(o,this._levelBounds)),_=o;_<p;_+=4){var f=0|this._indices[_>>2],l=e(t,this._boxes[_],this._boxes[_+2]),x=e(i,this._boxes[_+1],this._boxes[_+3]),m=l*l+x*x;o<4*this.numItems?(void 0===n||n(f))&&a.push(-f-1,m):a.push(f,m)}for(;a.length&&a.peek()<0;){if(a.peekValue()>d)return a.clear(),u;if(u.push(-a.pop()-1),u.length===s)return a.clear(),u}o=a.pop()}return a.clear(),u},s}));
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).Flatbush=i()}(this,(function(){"use strict";var t=function(){this.ids=[],this.values=[],this.length=0};t.prototype.clear=function(){this.length=0},t.prototype.push=function(t,i){var s=this.length++;for(this.ids[s]=t,this.values[s]=i;s>0;){var e=s-1>>1,h=this.values[e];if(i>=h)break;this.ids[s]=this.ids[e],this.values[s]=h,s=e}this.ids[s]=t,this.values[s]=i},t.prototype.pop=function(){if(0!==this.length){var t=this.ids[0];if(this.length--,this.length>0){for(var i=this.ids[0]=this.ids[this.length],s=this.values[0]=this.values[this.length],e=this.length>>1,h=0;h<e;){var r=1+(h<<1),n=r+1,o=this.ids[r],a=this.values[r],u=this.values[n];if(n<this.length&&u<a&&(r=n,o=this.ids[n],a=u),a>=s)break;this.ids[h]=o,this.values[h]=a,h=r}this.ids[h]=i,this.values[h]=s}return t}},t.prototype.peek=function(){if(0!==this.length)return this.ids[0]},t.prototype.peekValue=function(){if(0!==this.length)return this.values[0]};var i=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],s=function(s,e,h,r){if(void 0===e&&(e=16),void 0===h&&(h=Float64Array),void 0===s)throw new Error("Missing required argument: numItems.");if(isNaN(s)||s<=0)throw new Error("Unpexpected numItems value: "+s+".");this.numItems=+s,this.nodeSize=Math.min(Math.max(+e,2),65535);var n=s,o=n;this._levelBounds=[4*n];do{o+=n=Math.ceil(n/this.nodeSize),this._levelBounds.push(4*o)}while(1!==n);this.ArrayType=h||Float64Array,this.IndexArrayType=o<16384?Uint16Array:Uint32Array;var a=i.indexOf(this.ArrayType),u=4*o*this.ArrayType.BYTES_PER_ELEMENT;if(a<0)throw new Error("Unexpected typed array class: "+h+".");r&&r instanceof ArrayBuffer?(this.data=r,this._boxes=new this.ArrayType(this.data,8,4*o),this._indices=new this.IndexArrayType(this.data,8+u,o),this._pos=4*o,this.minX=this._boxes[this._pos-4],this.minY=this._boxes[this._pos-3],this.maxX=this._boxes[this._pos-2],this.maxY=this._boxes[this._pos-1]):(this.data=new ArrayBuffer(8+u+o*this.IndexArrayType.BYTES_PER_ELEMENT),this._boxes=new this.ArrayType(this.data,8,4*o),this._indices=new this.IndexArrayType(this.data,8+u,o),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(this.data,0,2).set([251,48+a]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=s),this._queue=new t};function e(t,i,s){return t<i?i-t:t<=s?0:t-s}function h(t,i){for(var s=0,e=i.length-1;s<e;){var h=s+e>>1;i[h]>t?e=h:s=h+1}return i[s]}function r(t,i,s,e,h,o){if(!(Math.floor(e/o)>=Math.floor(h/o))){for(var a=t[e+h>>1],u=e-1,d=h+1;;){do{u++}while(t[u]<a);do{d--}while(t[d]>a);if(u>=d)break;n(t,i,s,u,d)}r(t,i,s,e,d,o),r(t,i,s,d+1,h,o)}}function n(t,i,s,e,h){var r=t[e];t[e]=t[h],t[h]=r;var n=4*e,o=4*h,a=i[n],u=i[n+1],d=i[n+2],p=i[n+3];i[n]=i[o],i[n+1]=i[o+1],i[n+2]=i[o+2],i[n+3]=i[o+3],i[o]=a,i[o+1]=u,i[o+2]=d,i[o+3]=p;var f=s[e];s[e]=s[h],s[h]=f}function o(t,i){var s=t^i,e=65535^s,h=65535^(t|i),r=t&(65535^i),n=s|e>>1,o=s>>1^s,a=h>>1^e&r>>1^h,u=s&h>>1^r>>1^r;o=(s=n)&(e=o)>>2^e&(s^e)>>2,a^=s&(h=a)>>2^e&(r=u)>>2,u^=e&h>>2^(s^e)&r>>2,o=(s=n=s&s>>2^e&e>>2)&(e=o)>>4^e&(s^e)>>4,a^=s&(h=a)>>4^e&(r=u)>>4,u^=e&h>>4^(s^e)&r>>4,a^=(s=n=s&s>>4^e&e>>4)&(h=a)>>8^(e=o)&(r=u)>>8;var d=t^i,p=(e=(u^=e&h>>8^(s^e)&r>>8)^u>>1)|65535^(d|(s=a^a>>1));return((p=1431655765&((p=858993459&((p=252645135&((p=16711935&(p|p<<8))|p<<4))|p<<2))|p<<1))<<1|(d=1431655765&((d=858993459&((d=252645135&((d=16711935&(d|d<<8))|d<<4))|d<<2))|d<<1)))>>>0}return s.from=function(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");var e=new Uint8Array(t,0,2),h=e[0],r=e[1];if(251!==h)throw new Error("Data does not appear to be in a Flatbush format.");if(r>>4!=3)throw new Error("Got v"+(r>>4)+" data when expected v3.");var n=new Uint16Array(t,2,1)[0],o=new Uint32Array(t,4,1)[0];return new s(o,n,i[15&r],t)},s.prototype.add=function(t,i,s,e){var h=this._pos>>2;return this._indices[h]=h,this._boxes[this._pos++]=t,this._boxes[this._pos++]=i,this._boxes[this._pos++]=s,this._boxes[this._pos++]=e,t<this.minX&&(this.minX=t),i<this.minY&&(this.minY=i),s>this.maxX&&(this.maxX=s),e>this.maxY&&(this.maxY=e),h},s.prototype.finish=function(){if(this._pos>>2!==this.numItems)throw new Error("Added "+(this._pos>>2)+" items when expected "+this.numItems+".");if(this.numItems<=this.nodeSize)return this._boxes[this._pos++]=this.minX,this._boxes[this._pos++]=this.minY,this._boxes[this._pos++]=this.maxX,void(this._boxes[this._pos++]=this.maxY);for(var t=this.maxX-this.minX||1,i=this.maxY-this.minY||1,s=new Uint32Array(this.numItems),e=0;e<this.numItems;e++){var h=4*e,n=this._boxes[h++],a=this._boxes[h++],u=this._boxes[h++],d=this._boxes[h++],p=Math.floor(65535*((n+u)/2-this.minX)/t),f=Math.floor(65535*((a+d)/2-this.minY)/i);s[e]=o(p,f)}r(s,this._boxes,this._indices,0,this.numItems-1,this.nodeSize);for(var _=0,l=0;_<this._levelBounds.length-1;_++)for(var x=this._levelBounds[_];l<x;){for(var m=l,v=1/0,y=1/0,b=-1/0,c=-1/0,w=0;w<this.nodeSize&&l<x;w++)v=Math.min(v,this._boxes[l++]),y=Math.min(y,this._boxes[l++]),b=Math.max(b,this._boxes[l++]),c=Math.max(c,this._boxes[l++]);this._indices[this._pos>>2]=m,this._boxes[this._pos++]=v,this._boxes[this._pos++]=y,this._boxes[this._pos++]=b,this._boxes[this._pos++]=c}},s.prototype.search=function(t,i,s,e,r){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");for(var n=this._boxes.length-4,o=[],a=[];void 0!==n;){for(var u=Math.min(n+4*this.nodeSize,h(n,this._levelBounds)),d=n;d<u;d+=4){var p=0|this._indices[d>>2];s<this._boxes[d]||e<this._boxes[d+1]||t>this._boxes[d+2]||i>this._boxes[d+3]||(n<4*this.numItems?(void 0===r||r(p))&&a.push(p):o.push(p))}n=o.pop()}return a},s.prototype.neighbors=function(t,i,s,r,n){if(void 0===s&&(s=1/0),void 0===r&&(r=1/0),this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");for(var o=this._boxes.length-4,a=this._queue,u=[],d=r*r;void 0!==o;){for(var p=Math.min(o+4*this.nodeSize,h(o,this._levelBounds)),f=o;f<p;f+=4){var _=0|this._indices[f>>2],l=e(t,this._boxes[f],this._boxes[f+2]),x=e(i,this._boxes[f+1],this._boxes[f+3]),m=l*l+x*x;o<4*this.numItems?(void 0===n||n(_))&&a.push(1+(_<<1),m):a.push(_<<1,m)}for(;a.length&&1&a.peek();){if(a.peekValue()>d)return a.clear(),u;if(u.push(a.pop()>>1),u.length===s)return a.clear(),u}o=a.pop()>>1}return a.clear(),u},s}));

@@ -118,4 +118,4 @@

const width = this.maxX - this.minX;
const height = this.maxY - this.minY;
const width = (this.maxX - this.minX) || 1;
const height = (this.maxY - this.minY) || 1;
const hilbertValues = new Uint32Array(this.numItems);

@@ -232,7 +232,7 @@ const hilbertMax = (1 << 16) - 1;

if (filterFn === undefined || filterFn(index)) {
// put a negative index if it's an item rather than a node, to recognize later
q.push(-index - 1, dist);
// put an odd index if it's an item rather than a node, to recognize later
q.push((index << 1) + 1, dist);
}
} else {
q.push(index, dist);
q.push(index << 1, dist);
}

@@ -242,3 +242,3 @@ }

// pop items from the queue
while (q.length && q.peek() < 0) {
while (q.length && (q.peek() & 1)) {
const dist = q.peekValue();

@@ -249,3 +249,3 @@ if (dist > maxDistSquared) {

}
results.push(-q.pop() - 1);
results.push(q.pop() >> 1);

@@ -258,3 +258,3 @@ if (results.length === maxResults) {

nodeIndex = q.pop();
nodeIndex = q.pop() >> 1;
}

@@ -261,0 +261,0 @@

{
"name": "flatbush",
"version": "3.3.0",
"version": "3.3.1",
"description": "Fast static spatial index for rectangles",

@@ -44,5 +44,5 @@ "main": "flatbush.js",

"devDependencies": {
"@rollup/plugin-buble": "^0.21.1",
"@rollup/plugin-node-resolve": "^7.1.1",
"eslint": "^6.8.0",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-node-resolve": "^13.1.3",
"eslint": "^8.12.0",
"eslint-config-mourner": "^3.0.0",

@@ -52,9 +52,9 @@ "esm": "^3.2.25",

"rbush-knn": "^3.0.1",
"rollup": "^2.2.0",
"rollup-plugin-terser": "^5.3.0",
"tape": "^4.13.2"
"rollup": "^2.70.1",
"rollup-plugin-terser": "^7.0.2",
"tape": "^5.5.2"
},
"dependencies": {
"flatqueue": "^1.2.0"
"flatqueue": "^1.2.1"
}
}

@@ -11,3 +11,3 @@ # Flatbush

- **Faster** indexing and search, with much lower **memory** footprint.
- Index is stored as a single **array buffer** (so you can [transfer](https://developer.mozilla.org/en-US/docs/Web/API/Transferable) it between threads or store it as a compact binary file).
- 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 binary file).

@@ -87,3 +87,3 @@ Supports geographic locations with the [geoflatbush](https://github.com/mourner/geoflatbush) extension.

Returns an array of indices of items in a given bounding box. Item indices refer to the value returned by [`index.add()`](#indexaddminx-miny-maxx-maxy).
Returns an array of indices of items intersecting or touching a given bounding box. Item indices refer to the value returned by [`index.add()`](#indexaddminx-miny-maxx-maxy).

@@ -90,0 +90,0 @@ ```js

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc