Skip to content

Instantly share code, notes, and snippets.

@glaebhoerl
glaebhoerl / scopemap.rs
Last active July 3, 2022 12:59
Rust hash table with efficient support for nested scopes (save/restore)
// Based on idea: https://twitter.com/pkhuong/status/1287510400372748290
use hashbrown::raw::RawTable;
pub struct ScopeMap<K, V> {
last_scope_id: ScopeId,
scopes: Vec<ScopeId>, // values are zeroed instead of popped to save a check in get() / is_fresh()
current_scope: ScopeDepth, // index of innermost valid scope
values: RawTable<Entry<K, V>>,
shadowed: Vec<Shadowed<K, V>>,