pr 05.d
This commit is contained in:
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub struct NameId(pub u32);
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct NameInterner {
|
||||
names: Vec<String>,
|
||||
ids: HashMap<String, NameId>,
|
||||
@@ -28,6 +28,10 @@ impl NameInterner {
|
||||
id
|
||||
}
|
||||
|
||||
pub fn get(&self, s: &str) -> Option<NameId> {
|
||||
self.ids.get(s).copied()
|
||||
}
|
||||
|
||||
pub fn resolve(&self, id: NameId) -> &str {
|
||||
&self.names[id.0 as usize]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user