Expand description
This module helps you efficiently store and retrieve values using interning.
Interning is a neat trick that keeps only one copy of identical values, saving memory
and making comparisons super fast. Here, we provide the Interned<T>
struct and the Internable
trait
to make interning easy for different data types.
The Interner
struct handles caching for common types like String
, PathBuf
, and Vec<String>
,
while the Cache
struct acts as a write-once storage for linking computation steps with their results.
§Thread Safety
We use Mutex
to make sure interning and retrieval are thread-safe. But keep in mind—once a value is
interned, it sticks around for the entire lifetime of the program.
Structs§
- Cache
- This is essentially a
HashMap
which allows storing any type in its input and any type in its output. It is a write-once cache; values are never evicted, which means that references to the value can safely be returned from theget()
method. - Interned
- Represents an interned value of type
T
, allowing for efficient comparisons and retrieval. - Interner
- A global interner for managing interned values of common types.
- TyIntern 🔒
- A structure for managing the interning of values of type
T
.
Statics§
- INTERNER
- A global instance of
Interner
that caches common interned values.
Traits§
- Internable 🔒
- Defines the behavior required for a type to be internable.