fitzgen / bumpalo

A fast bump allocation arena for Rust
https://docs.rs/bumpalo
Apache License 2.0
1.36k stars 111 forks source link

Add `BTreeMap` and `BTreeSet`? #146

Closed scottjmaddox closed 2 years ago

scottjmaddox commented 2 years ago

Has anyone looked at adding BTreeMap and BTreeSet collections? I'd like to use this library in a programming language type system, but I need some form of Set and Map. BTreeMap / BTreeSet exist in the Rust's alloc crate, so I'm hoping it wouldn't be too difficult to port them to bumpalo.

fitzgen commented 2 years ago

The hashbrown crate provides hash maps and sets that work with bumpalo.

I am not interested in adding BTreeMap and BTreeSet to this crate; I'm waiting for std to support custom allocators instead (which is making progress!).

scottjmaddox commented 2 years ago

Ah, that's good to hear! It's not quite obvious to me how that works, though, any chance you can point me to an example? In particular, is there a way to allocate the hash table in a bumpalo arena?

Thanks!

fitzgen commented 2 years ago

I haven't used it myself, but the hashbrown readme says you enable the bumpalo cargo feature and then use the BumpWrapper type.

fitzgen commented 2 years ago

https://github.com/rust-lang/hashbrown/blob/21bfd9aff79ebcfec29143a14b18d8c7bb2bac5c/src/lib.rs#L134-L150