I have rstar::RTree and try to check if objects should be updated there, by comparing the old ones in the index and the new ones.
The problem is that RTree requires that the geometry has Float inside, but this forbids Hash
& Eq
, which are required to compare sets of geoms (with HashSet). I thought of BTreeSet, but that requires Ord
which is weirder for geometries.
Geo-types docs say that Hash, PartialEq and Eq are supported for T's that support these traits -- and that's not floats, right?
I wrote just a check if old_geoms entriy is in new_geoms vector, and vice versa. But this must be slow, or not? (Apart from being O(n^2))
Is there a light way to check the difference of sets of geoms? Or we're doomed, and I have just to put a warning that such index update is a very costy operation? (I assume that "remove all & insert all new" strategy is costier, given that the update is 1..3 elements, while the rtree is big (100K objects).)
[#derive(... Hash, PartialEq, Eq)]
struct MyRTreeEntry { geom: Point, id: MyId }
impl RTreeObject for MyRTreeEntry {
type Envelope = AABB<Point>;
fn envelope(&self) -> AABB<Point> { self.geom.envelope() }
}
let mut tree: RTree<MyRTreeEntry> = ...
let old_entries = vec![entry1, entry2, entry3]; // this should be HashMap ideally
let new_entries = vec![entry3, entry2, entry4]; // this should be HashMap ideally
for e in old_entries.iter() {
if !new_entries.contains(e) {
tree.remove(e);
}
}
for e in new_entries.iter() {
if !old_entries.contains(e) (
tree.insert(e);
}
}