Blazinterner: efficient and concurrent interning of generic data
Here are the main features offered by this crate.
- Generic: You can intern any data type that implements
HashandEq, not just strings. The interned type doesn't even have to beSized(for examplestr), as long as you provide aSizedstorage type (such asBox<str>) that can be borrowed as the interned type. - Efficient: Each
Internedvalue contains only a 32-bit index. The correspondingArenastores each value directly in anAppendVec, plus the 32-bit index in a raw hash table (DashTable). To intern a value of typeTusing storage typeS, you can pass any type that implementsBorrow<T>andInto<S>, which allows avoiding unnecessary copies. For example, in anArena<str, Box<str>>you can intern many string types:&str,String,Box<str>,Cow<'_, str>, etc. - Concurrent: The
ArenaisSync, and allows simultaneous reads and writes. More specifically, retrieving values viaInterned::lookup()andInterned::lookup_ref()is always wait-free, even when a write happens concurrently! This is thanks to the underlyingAppendVecimplementation. However, only one write (usingInterned::from()) can happen at a time on a given arena, due to an exclusive write lock.