mourner / rbush

RBush — a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

delete by id

calvinmetcalf opened this issue · comments

it would be nice to be able to delete an item based on it having some value instead of by reference.

Having to do everything by reference complicates things a bit, e.g. loading from json from a server when you also get the same objects in some other way from the server can get different objects which look the same but aren't really the same.

Yeah, I agree. The reason it is done as it is right now is the simplicity of not having to introduce the concept of ids for items, and the performance benefit of array.indexOf(item) vs loop through comparing ids.

ol3's port of rbush stores the extent of each item added in a separate object, allowing items to be removed without knowing their extents. This is also useful for updating the rbush when the extent has changed:
https://github.com/openlayers/ol3/blob/vector-api/src/ol/structs/rbush.js#L577-589

so for background I was adding a geojson wrapper around rbush and more or less doing the same thing as open layers, calculating the bbox and inserting that and using a WeakMap to connect the objects to their extent, but I realized that this makes jsonifing unworkable, I'm thinking about how to rework it in a way that makes CRUD operations on rbush doable without direct references to the object.

Being able to add a comparator functions might be a good first step, but only if we could figure out how to do it in a way that didn't piss all over performance.