Rewrite WUtils bagtree.c in Rust #4
Reference in New Issue
Block a user
Delete Branch "trurl/wmaker:refactor/wutil-rs-bagtree"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In this case, we can replace the red-black tree with a sorted Vec. That makes rewriting it pretty simple, although it is yet another thing that we actually want to get rid of at some point.
@@ -0,0 +15,4 @@};#[derive(Default)]pub struct Bag {It feels like you almost don't need this at all; you could do everything you need to do with the
Bagabstraction by just making it a newtype over aBTreeMap, and then dereferencing the newtype pointer at the FFI boundary. Something like,(And so on.)
Only putting functionality into the FFI functions makes sense. (I've done similarly in other refactors that you're looking at.) I was thinking to have most operations addressable via completely safe Rust, to reduce the amount of unsafe in unit tests, but for this module the additional lines of code may not be warranted.
I elected to use a sorted
Vecinstead of aBTreeMapbecause of the iterator interface: there isn't a proper double-endedBTreeMapiterator in Rust, and WUtils iterators are assumed to be allocation-free. I'm not super inclined to refactor the interface very much right now, so it seems simpler to use an implementation that allows use of an int as an iterator. Unless I'm overlooking a strong reason to use aBTreeMapinternally, the sortedVecseems fine.ok, I think that's fine.
a2940e44adto0097d1819e