Ralith / sieve-tree

6 stars 1 forks source link

`remove` will remove the element before its successor is loaded in `unlink` #2

Closed grovesNL closed 6 days ago

grovesNL commented 1 week ago

remove starts off by removing it from elements https://github.com/Ralith/sieve-tree/blob/460fd6aa4a416a9de1614b7a0da625b29300cbb3/src/lib.rs#L223 but later calls unlink. unlink tries to load the successor of the deleted element (let successor = elements[element].next;) but this is too late.

It looks like moving let elt = self.elements.remove(id); after unlink should work fine.

grovesNL commented 1 week ago

Something like this should reproduce it

#[test]
fn remove() {
    let mut tree = SieveTree::<1, 2, Bounds<1>>::new();
    let bounds = Bounds::point([0.]);
    let id = tree.insert(bounds, bounds);
    assert_eq!(tree.remove(bounds, id), bounds);
}
Ralith commented 6 days ago

Fixed, thanks!