mwchase

LC:NN upload 6: less wasteful canonicalization

Apr 9th, 2017
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.09 KB | None | 0 0
  1. @@ -2,7 +2,7 @@
  2.  extern crate void;
  3.  
  4.  use std::cmp::Ordering;
  5. -use std::collections::HashMap;
  6. +use std::collections::{HashMap, HashSet};
  7.  use std::hash::Hash;
  8.  
  9.  mod eval;
  10. @@ -30,7 +30,7 @@
  11.  }
  12.  
  13.  /// Convenience type, maps an instance of a type to an Arc containing a clone of the instance.
  14. -type SelfMap<T> = HashMap<T, Container<T>>;
  15. +type SelfMap<T> = HashSet<Container<T>>;
  16.  
  17.  /// A struct that contains canonicalization maps for every node type, as well as maps to
  18.  /// memoize partial derivatives.
  19. @@ -379,12 +379,11 @@
  20.      fn insert(&self, env: &mut Environment<T>) -> Container<Self>
  21.          where Self: Sized + Clone + Eq + Hash
  22.      {
  23. -        if !self.get_storage(env).contains_key(self) {
  24. +        if !self.get_storage(env).contains(self) {
  25.              let key = self.fancy_clone(env);
  26. -            let value = key.clone();
  27. -            self.get_storage(env).insert(key, container(value));
  28. +            self.get_storage(env).insert(container(key));
  29.          }
  30. -        self.get_storage(env)[self].clone()
  31. +        self.get_storage(env).get(self).unwrap().clone()
  32.      }
  33.  }
Advertisement
Add Comment
Please, Sign In to add comment