#interning #intern #string #str

nightly tucan

A simple, fast, and multithreaded interner with loose type requirement

5 releases

0.1.5 Apr 14, 2023
0.1.4 Apr 13, 2023

#724 in Concurrency

Download history 21/week @ 2024-03-31 32/week @ 2024-04-14

73 downloads per month

0BSD license

15KB
413 lines

Tucan: a simple interner with garbage collection

Tucan is a very basic interner with garbage collection. It adds an Intern trait that allows you to intern any type that implements Hash, Send, Sync and Eq. Keys to interned elements are called Interned and are wrapper around a Arc<T>. They implement Deref for T and Clone. When calling the gc() function, tucan looks for all entries in the interner that are not referenced by any Interned and removes them.

Note

Tucan uses sip-hash for checking whether two values are the same. Therefore values with colliding hashes will be interned as the same values if they are of the same type. This means that conflicts are possible. This is a concious design decision to keep the interner simple and fast with very loose requirements on the types that can be interned.

Dependencies

~0.6–6MB
~17K SLoC