๐Ÿ“ฆ DaniPopes / inturn

Efficient, performant, thread-safe bytes/string interning in Rust.

โ˜… 17 stars โ‘‚ 1 forks ๐Ÿ‘ 17 watching โš–๏ธ Apache License 2.0
๐Ÿ“ฅ Clone https://github.com/DaniPopes/inturn.git
HTTPS git clone https://github.com/DaniPopes/inturn.git
SSH git clone git@github.com:DaniPopes/inturn.git
CLI gh repo clone DaniPopes/inturn
DaniPopes DaniPopes chore: Release inturn version 0.1.2 83bc129 5 months ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ src
๐Ÿ“„ .gitignore
๐Ÿ“„ Cargo.toml
๐Ÿ“„ clippy.toml
๐Ÿ“„ LICENSE-APACHE
๐Ÿ“„ LICENSE-MIT
๐Ÿ“„ README.md
๐Ÿ“„ rustfmt.toml
๐Ÿ“„ README.md

inturn

github crates.io docs.rs build status

Efficient, performant, thread-safe bytes/string interning.

This crate was designed to have a lock-free mapping of symbols back to their original string.

It currently uses dashmap for deduplicating strings, and a lock-free stack to map the string index (symbol) back to the string bytes.

It supports interning any &str/&[u8] by allocating it internally in an efficient arena when encountered for the first time, or &'static str/&'static [u8] without allocation.

A *_mut variant of each API is provided which side-step any locks, for e.g. initializing the interner with a static set of strings to pre-intern.

Examples

Basic str interning (the same API is available with BytesInterner for [u8]):

use inturn::Interner;

let interner = Interner::new();
let hello = interner.intern("hello");
assert_eq!(hello.get(), 0);
assert_eq!(interner.resolve(hello), "hello");

let world = interner.intern("world");
assert_eq!(world.get(), 1);
assert_eq!(interner.resolve(world), "world");

let hello2 = interner.intern("hello");
assert_eq!(hello, hello2);

assert_eq!(interner.len(), 2);