Crates.io | arc-interner |
lib.rs | arc-interner |
version | 0.7.0 |
source | src |
created_at | 2020-04-24 20:15:12.982729 |
updated_at | 2021-12-01 19:08:57.16526 |
description | An interner that deallocates unused values |
homepage | https://github.com/ryzhyk/arc-interner |
repository | https://github.com/ryzhyk/arc-interner |
max_upload_size | |
id | 233777 |
size | 18,279 |
This crate is a fork of David Roundy's
internment
crate.
It provides an alternative implementation of the internment::ArcIntern
type. It inherits David's high-level design and API; however it is built
completely on Rust's standard Arc
type and the
dashmap
crate and does not contain
any unsafe code.
Interning reduces the memory footprint of an application by storing a unique copy of each distinct value. It speeds up equality comparison and hashing operations, as only pointers rather than actual values need to be compared. On the flip side, object creation is slower, as it involves lookup in the interned object pool.
Interning is most commonly applied to strings; however it can also be useful for other object types. This library supports interning of arbitrary objects.
There exist several interning libraries for Rust, each with its own set of tradeoffs. This library makes the following design choices:
DashMap
for
safe concurrent access and low contention.Eq + Hash + Send + Sync
trait bound.Arc
and DashMap
types
and does not contain any unsafe code.use arc_interner::ArcIntern;
let x = ArcIntern::new("hello");
let y = ArcIntern::new("world");
assert_ne!(x, y);
assert_eq!(x, ArcIntern::new("hello"));
assert_eq!(*x, "hello"); // dereference an ArcIntern like a pointer