https://github.com/cad97/simple-interner
https://github.com/cad97/simple-interner
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/cad97/simple-interner
- Owner: CAD97
- Created: 2018-04-07T09:11:36.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2023-10-05T21:49:03.000Z (almost 3 years ago)
- Last Synced: 2025-03-01T13:37:01.289Z (over 1 year ago)
- Language: Rust
- Size: 26.4 KB
- Stars: 7
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# simple-interner
A very simplistic interner based around giving out references rather than
some placeholder symbol. This means that you can mostly transparently add
interning into a system without requiring rewriting all of the code to work
on a new `Symbol` type, asking the interener to concretize the symbols.
The typical use case for something like this is text processing chunks,
where chunks are very likely to be repeated. For example, when parsing
source code, identifiers are likely to come up multiple times. Rather than
have a `String` allocated for every occurrence of the identifier separately,
interners allow you to store `Symbol`. This additionally allows comparing
symbols to be much quicker than comparing the full interned string.
This crate exists to give the option of using the simplest interface. For
a more featureful interner, consider using a different crate, such as
| crate | global | local | `'static` opt[^1] | `str`-only | symbol size | symbols deref |
| ----------------: | :---------: | :----: | :---------------: | :--------: | :-----------: | :-----------: |
| simple-interner | manual[^2] | yes | no | no | `&T` | yes |
| [intaglio] | no | yes | yes | yes | `u32` | no |
| [internment] | rc[^3] | yes | no | no | `&T` | yes |
| [lasso] | no | yes | yes | yes | `u8`–`usize` | no |
| [string-interner] | no | yes | optionally | yes | `u16`–`usize` | no |
| [string_cache] | static only | rc[^3] | buildscript | yes | `u64` | yes |
| [symbol_table] | yes | yes | no | yes | `u32` | global only |
| [ustr] | yes | no | no | yes | `usize` | yes |
(PRs to this table are welcome!)
[^1]: The interner stores `&'static` references without copying the pointee
into the store, e.g. storing `Cow<'static, str>` instead of `Box`.
[^2]: At the moment, creating the `Interner` inside a `static`, using
`Interner::with_hasher`, requires the `hashbrown` feature to be enabled.
[^3]: Uses reference counting to collect globally unused symbols.
[intaglio]: https://lib.rs/crates/intaglio
[lasso]: https://lib.rs/crates/lasso
[internment]: https://lib.rs/crates/internment
[string-interner]: https://lib.rs/crates/string-interner
[string_cache]: https://lib.rs/crates/string_cache
[symbol_table]: https://lib.rs/crates/symbol_table
[ustr]: https://lib.rs/crates/ustr