-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add with_capacity
#18
Comments
Hey, glad you like it! Good question, setting capacity at runtime would be a convenient feature. The answer is a little complicated, so bear with me on a long-ish explanation This library is
The only crate I’m aware of (there may be others) that supports runtime capacity while still being
All that said, runtime capacity could be a valuable feature. Not so much for performance/preallocation, but definitely for flexibility. Thank you for the suggestion! I’ll keep this issue open, pending on the state of safe transmutation in Rust: there seems to be working group established in RFC 2835. |
Hello! Thank you for the long-ish answer, it's really appreciated. I get that this library is geared toward embedded system. Although I think it might have applications elsewhere. Because you use This would still mean this library is Edit: Although that might be another issue altogether. |
Ah, gotcha. A The blocker is I don't know how to support the current fallible APIs (like So it is indeed another issue altogether. But open to any suggestions! |
Thinking back to your idea about type-aliasing: what about aliasing
If this sounds good, or there's a preferable alternative, would you like to take ownership of an implementation/PR? |
Hi! Wow there is loads to say!
To support those, we could indeed use the The Because the trait Although, that would mean setting the MSRV would be at least 1.57.0 to support the newly added
My idea was to have an alias like: // Bear with me for the not very original naming ;)
#[cfg(not(feature = "heap_collections"))]
type ScapegoatVec<A> = tinyvec::ArrayVec<A>;
#[cfg(feature = "heap_collections")]
type ScapegoatVec<A> = tinyvec::TinyVec<A>;
I would maybe create a new
I would, but I'm afraid it might not be right this instant as I'm quite occupied. If you want to go ahead on an implementation that'd be great, otherwise I'll come back to that later on. |
Derp, You may already know this but worth explicitly pointing out: Luckily, since use of Thanks for working through all this with me and taking the time for a detailed response. I think I understand both the requirements and a path to implementation now. Should have time to work on it later this week, so will assign to myself and keep you posted on progress! 👍 |
So unfortunate update: after starting implementation and running into unanticipated roadblocks I think it's better to not add heap support due to fallibility complications. Even though it'd open up more dynamic usescases. 😢 A good example of the problem is the internal function fn get_subtree_size<U: SmallUnsigned + Default>(&self, idx: usize) -> usize {
let mut subtree_worklist = array_vec![[U; N] => U::checked_from(idx)];
let mut subtree_size = 0;
while let Some(idx) = subtree_worklist.pop() {
let node = &self.arena[idx.usize()];
subtree_size += 1;
if let Some(left_idx) = node.left_idx() {
subtree_worklist.push(U::checked_from(left_idx));
}
if let Some(right_idx) = node.right_idx() {
subtree_worklist.push(U::checked_from(right_idx));
}
}
subtree_size
} Ignore the Now if we support the heap, Going down that path would mean changing a lot of internal signatures to return As an alternative solution, tried "pulling up" buffers like So, based on this experimentation, opting to close this issue for now. It'd be too major of a change, and the standard library currently covers dynamic usecases. But always happy to discuss further or eventually circle back, learning as I go! |
Hello!
First and foremost, thank you for this very nice crate!
Do you think it would be feasible to add a
with_capacity
to the arena allocator, and ultimatly to theSgMap
andSgSet
implementation to pre-allocate nodes at run-time ?This would be useful for cases where we know how much inserting will be done in the near future but don't want to pay the cost of frequent allocations (and/or re-allocations).
The text was updated successfully, but these errors were encountered: