Add some more methods around this

This commit is contained in:
greg 2019-10-18 09:54:56 -07:00
parent f9633ebe55
commit 7a56b6dfc0
2 changed files with 7 additions and 1 deletions

View File

@ -115,12 +115,17 @@ impl SymbolTable {
vec.push(ScopeSegment { name: local_name.clone(), kind: ScopeSegmentKind::Terminal });
let fully_qualified_name = FullyQualifiedSymbolName(vec);
let symbol = Symbol { local_name: local_name.clone(), fully_qualified_name: fully_qualified_name.clone(), spec };
self.symbol_trie.insert(&fully_qualified_name);
self.symbol_path_to_symbol.insert(fully_qualified_name, symbol);
}
pub fn lookup_by_fqsn(&self, fully_qualified_path: &FullyQualifiedSymbolName) -> Option<&Symbol> {
self.symbol_path_to_symbol.get(fully_qualified_path)
}
pub fn lookup_children_of_fqsn(&self, path: &FullyQualifiedSymbolName) -> Vec<FullyQualifiedSymbolName> {
self.symbol_trie.get_children(path)
}
}
#[derive(Debug)]

View File

@ -4,6 +4,7 @@ use super::{ScopeSegmentKind, ScopeSegment, FullyQualifiedSymbolName};
use std::hash::{Hasher, Hash};
use std::collections::hash_map::DefaultHasher;
#[derive(Debug)]
pub struct SymbolTrie(Trie<FullyQualifiedSymbolName, ()>);
impl TrieKey for FullyQualifiedSymbolName {
@ -33,7 +34,7 @@ impl SymbolTrie {
Some(s) => s,
None => return vec![]
};
let output: Vec<FullyQualifiedSymbolName> = subtrie.keys().map(|fqsn| fqsn.clone()).collect();
let output: Vec<FullyQualifiedSymbolName> = subtrie.keys().filter(|cur_key| **cur_key != *fqsn).map(|fqsn| fqsn.clone()).collect();
output
}
}