3 ms·
Here's the implementation of "remove a value" [1] from the popular Rust crate that implements this pattern. It completely sidesteps the issue you are describin
by davidatbu 3y ago
Here's the implementation of "remove a value" [1] from the popular Rust crate that implements this pattern.
It completely sidesteps the issue you are describing because "deleting from array" does not mean "adjust every greater index by one".
However, I'll grant you that using this crate means you have to extend _some_ trust (even if very small) to the crate maintainer to maintain safety invariants, in addition to Rust's compiler maintainers.
But the fact that I could dive into its code (that I've never seen before) in 2 minutes and verify that it is not susceptible to the issue you describe gives me more confidence that auditing+trusting this crate will not be an undue burden.
[1] https://docs.rs/slotmap/latest/src/slotmap/basic.rs.html#395 https://docs.rs/slotmap/latest/src/slotmap/basic.rs.html#395