pub struct Interner<'a> {
arena: &'a Arena,
table: Vec<'a, Option<&'a str>>,
mask: usize,
occupied: usize,
last: Option<&'a str>,
pub stats: InternStats,
}Expand description
Open-addressing intern table over arena-allocated strings.
Fields§
§arena: &'a Arena§table: Vec<'a, Option<&'a str>>Slots: None = empty, Some(&'a str) = occupied.
BumpVec keeps the table itself inside the arena, so the
interner allocates exactly zero bytes outside the arena.
mask: usizecapacity - 1. capacity is always a power of two.
occupied: usizeNumber of occupied slots.
last: Option<&'a str>Inline cache: last successfully-interned string. Long runs of identical interns short-circuit on this single pointer compare.
A 2-slot LRU cache (intended to catch Ruby’s alternating
(base, reading, base, reading, …) access pattern) was tried
and reverted. Corpus dedup ratio stayed at p50 0.275 /
mean 0.308 (identical to the 1-slot baseline), throughput
moved within noise. The pattern that would benefit —
consecutive rubies sharing a base or reading
— is rarer than the design assumed; distinct rubies on
distinct words dominate.
stats: InternStatsDiagnostic counters. Updated on every intern call. Useful for benchmarks and the corpus-sweep dedup-ratio report.
Implementations§
Source§impl<'a> Interner<'a>
impl<'a> Interner<'a>
Sourcepub fn new_in(arena: &'a Arena) -> Self
pub fn new_in(arena: &'a Arena) -> Self
Empty interner backed by arena. Initial capacity is
INITIAL_CAPACITY.
Sourcepub fn with_capacity_in(capacity_hint: usize, arena: &'a Arena) -> Self
pub fn with_capacity_in(capacity_hint: usize, arena: &'a Arena) -> Self
Empty interner backed by arena, with the table pre-sized to
at least capacity_hint slots (rounded up to a power of two).
Use when the caller can estimate the unique-string count up
front (e.g. the lex driver knows the registry size).
Sourcepub fn intern(&mut self, s: &str) -> &'a str
pub fn intern(&mut self, s: &str) -> &'a str
Intern s and return a stable &'a str pointer to the arena
copy. Subsequent calls with byte-equal content return the same
pointer.
Sourcepub fn unique_strings(&self) -> usize
pub fn unique_strings(&self) -> usize
Number of unique strings currently held in the table.
Sourcepub fn avg_probe_length(&self) -> f64
pub fn avg_probe_length(&self) -> f64
Average probe length per non-cache-hit lookup. Returns 0.0
when no probed lookups have occurred. Used by benchmarks to
confirm the hash function and load-factor policy keep the
table healthy.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Interner<'a>
impl<'a> !RefUnwindSafe for Interner<'a>
impl<'a> !Send for Interner<'a>
impl<'a> !Sync for Interner<'a>
impl<'a> Unpin for Interner<'a>
impl<'a> UnsafeUnpin for Interner<'a>
impl<'a> !UnwindSafe for Interner<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more