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
saved by
related reading
- A half-hour to learn Rustfasterthanli.me
- Working with strings in Rustfasterthanli.me
- (Re)writing an interpreter in Rust – Danny van Kootendannyvankooten.com
- Storing UTF-8 Encoded Text with Strings - The Rust Programming Languagedoc.rust-lang.org
- References and Borrowing - The Rust Programming Languagedoc.rust-lang.org
- Index 1,600,000,000 Keys with Automata and Rust - Andrew Gallant's Blogburntsushi.net
- Rust Optimization.md · GitHubgist.github.com
- Beating the fastest lexer generator in Rustalic.dev
- The Slice Type - The Rust Programming Languagedoc.rust-lang.org
- Patterns for Defensive Programming in Rust | corrode Rust Consultingcorrode.dev
- HashMap in std::collections - Rustdoc.rust-lang.org
- What is Ownership? - The Rust Programming Languagedoc.rust-lang.org