Commit b840180e authored by Jeff Smits's avatar Jeff Smits

Changed to better use of typedefs from fnv

parent 3390e65c
......@@ -4,7 +4,8 @@ use preprocess::{Def, StrategyDef};
use primitives::{Primitives, eval_prim_ref};
use primitives::ssl::State;
use std::collections::HashMap;
use fnv::FnvHashMap;
use std::fmt;
use std::borrow::Borrow;
use std::cell::RefCell;
......@@ -91,8 +92,8 @@ impl<'d, 'f : 'd> MutContext<'d, 'f> {
pub fn push_overlay(&self) {
let overlay = Scope {
term: ::fnv::FnvHashMap::default(),
strategy: ::fnv::FnvHashMap::default(),
term: FnvHashMap::default(),
strategy: FnvHashMap::default(),
is_overlay: true,
};
......@@ -207,8 +208,8 @@ impl fmt::Display for StackTracer {
#[derive(Debug, Default, Clone)]
pub struct Scope<'a, ATerm> {
pub term: HashMap<String, Option<ATerm>, ::fnv::FnvBuildHasher>,
pub strategy: HashMap<String, StrategyDef<'a>, ::fnv::FnvBuildHasher>,
pub term: FnvHashMap<String, Option<ATerm>>,
pub strategy: FnvHashMap<String, StrategyDef<'a>>,
is_overlay: bool,
}
......@@ -230,7 +231,7 @@ impl<'a, ATerm> Scope<'a, ATerm> {
I: IntoIterator<Item = &'a Def>,
{
Scope {
term: HashMap::default(),
term: FnvHashMap::default(),
strategy: defs.into_iter()
.map(|def| (def.name.clone(), StrategyDef::from_def(def)))
.collect(),
......@@ -243,7 +244,7 @@ impl<'a, ATerm> Scope<'a, ATerm> {
I: IntoIterator<Item=&'a Def>,
{
Scope {
term: HashMap::default(),
term: FnvHashMap::default(),
strategy: defs.into_iter()
.map(|def| (def.name.clone(), StrategyDef::from_let_def(def, no_of_scopes)))
.collect(),
......@@ -258,14 +259,14 @@ impl<'a, ATerm> Scope<'a, ATerm> {
Scope {
term: {
let fresh_vars = fresh_vars.into_iter();
let mut result = HashMap::with_capacity_and_hasher(fresh_vars.size_hint().0, ::fnv::FnvBuildHasher::default());
let mut result = FnvHashMap::with_capacity_and_hasher(fresh_vars.size_hint().0, ::fnv::FnvBuildHasher::default());
// trying to use zip + iter::repeat will require ATerm: Clone, which is unnecessary
for fresh_var in fresh_vars {
result.insert(fresh_var, None);
}
result
},
strategy: HashMap::default(),
strategy: FnvHashMap::default(),
is_overlay: false,
}
}
......
......@@ -4,9 +4,10 @@ use linked_hash_map::LinkedHashMap;
use try_from::TryInto;
use fnv::FnvHashMap;
use fnv::FnvHasher;
use std::collections::hash_map;
use std::collections::hash_map::HashMap;
use std::collections::hash_map::DefaultHasher;
use std::cell::RefCell;
use std::hash::Hash;
use std::hash::Hasher;
......@@ -16,11 +17,11 @@ use std::borrow::Borrow;
pub type HashTable = LinkedHashMap<ATermRef, ATermRef, ::fnv::FnvBuildHasher>;
#[derive(Debug, Eq, Clone, Default)]
pub struct IndexedSet(HashMap<ATermRef, u16, ::fnv::FnvBuildHasher>, u16);
pub struct IndexedSet(FnvHashMap<ATermRef, u16>, u16);
impl IndexedSet {
pub fn with_capacity(capacity: usize) -> Self {
IndexedSet(HashMap::with_capacity_and_hasher(capacity, ::fnv::FnvBuildHasher::default()), 0)
IndexedSet(FnvHashMap::with_capacity_and_hasher(capacity, ::fnv::FnvBuildHasher::default()), 0)
}
pub fn clear(&mut self) {
......@@ -136,7 +137,7 @@ pub type ATermRef = Rc<aterm::rc::ATerm<Blob>>;
impl aterm::print::ATermWrite for Blob {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
let mut hasher = DefaultHasher::new();
let mut hasher = FnvHasher::default();
self.hash(&mut hasher);
writer.write_str(&hasher.finish().to_string())
}
......
......@@ -7,7 +7,7 @@ use aterm::{ATermFactory as ATF, ATerm as A};
use aterm::print::ATermWrite;
use aterm::parse::ATermRead;
use std::collections::HashMap;
use fnv::FnvHashMap;
macro_rules! eprintln {
($($tt:tt)*) => {{
......@@ -19,7 +19,7 @@ macro_rules! eprintln {
pub struct StringState {
new_alphacounter: u8,
new_counter: u16,
newname_counters: HashMap<String, usize, ::fnv::FnvBuildHasher>,
newname_counters: FnvHashMap<String, usize>,
}
impl StringState {
......@@ -27,7 +27,7 @@ impl StringState {
StringState {
new_alphacounter: b'a',
new_counter: 0,
newname_counters: ::fnv::FnvHashMap::default(),
newname_counters: FnvHashMap::default(),
}
}
}
......@@ -190,22 +190,17 @@ pub fn new<'d, 'f: 'd>(
) -> Result<ATermRef> {
let mut ssl_state = context.ssl_state.borrow_mut();
ssl_state.string.new_alphacounter += 1;
if ssl_state.string.new_alphacounter > (b'z') {
if ssl_state.string.new_alphacounter > b'z' {
ssl_state.string.new_alphacounter = b'a';
if ssl_state.string.new_counter == u16::max_value() {
panic!(
"new (SSL): Generated 26 * {} unique names, no idea what to generate any more!",
u16::max_value()
);
}
ssl_state.string.new_counter += 1;
}
// TODO: extend factory to provide unique_string which fails if the string was built before.
Ok(context.factory.string(format!(
let new_name = format!(
"{}_{}",
ssl_state.string.new_alphacounter as char,
ssl_state.string.new_counter
)))
);
// TODO: extend factory to provide unique_string which fails if the string was built before.
Ok(context.factory.string(new_name))
}
pub fn newname<'d, 'f: 'd>(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment