The design of the hash-based half is taken from the arc-interner
crate, with the addition of another half based on BTreeMap
.
Local benchmarks have shown that hashing is faster for objects below 1kB while tree traversal
and comparisons are faster above 1kB (very roughly and broadly speaking).
The main functions exist in three variants:
intern_hash
and friends for when you want to use hashing (or have no Ord
instance at hand)intern_tree
and friends for when you want to use tree map (or have no Hash
instance at hand)intern
and friends to automatically choose based on object sizeWithin each of these classes, four function exist to ingest data in various forms:
```rust use std::sync::Arc; use internarc::{intern, internunsized, internboxed, internarc};
// for sized types
let a1: Arc
// for unsized non-owned types
let a2: Arc
// for unsized owned types
let a3: Arc
// for types with shared ownership
let a4: Arc
This library offers some utilities for checking how well it works for a given use-case:
```rust use std::sync::Arc; use internarc::{inspecthash, numobjectsinternedhash, typesinterned};
println!("str: {} objects", numobjectsinterned_hash::
let (hash, tree) = types_interned(); println!("types interned: {} with hashing, {} with trees", hash, tree);
inspecthash::<[u8], _, _>(|iter| { for arc in iter { println!("{} x {:?}", Arc::strongcount(&arc), arc); } }); ```
All function exist also with tree
suffix instead of hash
.