flâneur — a map of the web's best reading

Fast and Simple Rust Interner

matklad.github.io · 1,741 words · saved by 1 readers

This post describes a simple technique for writing interners in Rust which I haven't seen documented before.

This post describes a simple technique for writing interners in Rust which I haven’t seen documented before. String interning is a classical optimization when you have to deal with many equal strings. The canonical example would be a compiler: most identifiers in a program are repeated several times. Interning works by ensuring that there’s only one canonical copy of each distinct string in memory. It can give the following benefits: Less memory allocated to hold strings. If all strings are canonicalized, comparison can be done in O(1) (instead of O(n) ) by using pointer equality. Interned str

Explore this link on the map →

related reading