diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-02-17 12:50:54 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-02-17 12:50:54 +0100 |
| commit | 91e45458e3d4c1e15660570841f0263f3d891278 (patch) | |
| tree | a0b86374c083fc758110c55c24fd4bef21ac2caa /src/eval/scope.rs | |
| parent | c7a9bac99224af9673f26ec140af48e1728fe3b5 (diff) | |
Make values hashable
Diffstat (limited to 'src/eval/scope.rs')
| -rw-r--r-- | src/eval/scope.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/eval/scope.rs b/src/eval/scope.rs index 3e79afc1..1539b4af 100644 --- a/src/eval/scope.rs +++ b/src/eval/scope.rs @@ -1,6 +1,7 @@ use std::cell::RefCell; -use std::collections::HashMap; +use std::collections::BTreeMap; use std::fmt::{self, Debug, Formatter}; +use std::hash::{Hash, Hasher}; use std::iter; use std::sync::Arc; @@ -68,7 +69,7 @@ impl<'a> Scopes<'a> { #[derive(Default, Clone)] pub struct Scope { /// The mapping from names to slots. - values: HashMap<EcoString, Slot>, + values: BTreeMap<EcoString, Slot>, } impl Scope { @@ -126,6 +127,16 @@ impl Scope { } } +impl Hash for Scope { + fn hash<H: Hasher>(&self, state: &mut H) { + self.values.len().hash(state); + for (name, value) in self.values.iter() { + name.hash(state); + value.borrow().hash(state); + } + } +} + impl Debug for Scope { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.write_str("Scope ")?; |
