Commit cfd4c0ca by Jeff Smits

Added fnv hashing, which sped things up quite nicely :)

parent 27943524
......@@ -3,6 +3,7 @@ name = "strs"
version = "0.1.0"
dependencies = [
"aterm 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"linked-hash-map 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -66,6 +67,11 @@ dependencies = [
]
[[package]]
name = "fnv"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -299,6 +305,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159"
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
"checksum clap 2.23.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f57e9b63057a545ad2ecd773ea61e49422ed1b1d63d74d5da5ecaee55b3396cd"
"checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf"
"checksum libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "88ee81885f9f04bff991e306fea7c1c60a5f0f9e409e99f6b40e3311a3363135"
......
......@@ -14,6 +14,7 @@ phf_codegen = "0.7.21"
[dependencies]
aterm = "0.13.0"
fnv = "1.0.5"
linked-hash-map = "0.4.2"
phf = "0.7.21"
rand = "0.3.15"
......@@ -22,5 +23,7 @@ structopt = "0.0.3"
structopt-derive = "0.0.3"
try_from = "0.2.1"
[profile]
[profile.release]
debug = true
......@@ -91,8 +91,8 @@ impl<'d, 'f : 'd> MutContext<'d, 'f> {
pub fn push_overlay(&self) {
let overlay = Scope {
term: HashMap::new(),
strategy: HashMap::new(),
term: ::fnv::FnvHashMap::default(),
strategy: ::fnv::FnvHashMap::default(),
is_overlay: true,
};
......@@ -195,8 +195,8 @@ impl fmt::Display for StackTracer {
#[derive(Debug, Default, Clone)]
pub struct Scope<'a, ATerm> {
pub term: HashMap<String, Option<ATerm>>,
pub strategy: HashMap<String, StrategyDef<'a>>,
pub term: HashMap<String, Option<ATerm>, ::fnv::FnvBuildHasher>,
pub strategy: HashMap<String, StrategyDef<'a>, ::fnv::FnvBuildHasher>,
is_overlay: bool,
}
......@@ -246,7 +246,7 @@ impl<'a, ATerm> Scope<'a, ATerm> {
Scope {
term: {
let fresh_vars = fresh_vars.into_iter();
let mut result = HashMap::with_capacity(fresh_vars.size_hint().0);
let mut result = HashMap::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);
......
......@@ -14,13 +14,13 @@ use std::fmt;
use std::rc::Rc;
use std::borrow::Borrow;
pub type HashTable = LinkedHashMap<ATermRef, ATermRef>;
pub type HashTable = LinkedHashMap<ATermRef, ATermRef, ::fnv::FnvBuildHasher>;
#[derive(Debug, Eq, Clone, Default)]
pub struct IndexedSet(HashMap<ATermRef, u16>, u16);
pub struct IndexedSet(HashMap<ATermRef, u16, ::fnv::FnvBuildHasher>, u16);
impl IndexedSet {
pub fn with_capacity(capacity: usize) -> Self {
IndexedSet(HashMap::with_capacity(capacity), 0)
IndexedSet(HashMap::with_capacity_and_hasher(capacity, ::fnv::FnvBuildHasher::default()), 0)
}
pub fn clear(&mut self) {
......
......@@ -4,6 +4,7 @@ extern crate phf;
extern crate ref_eq;
extern crate rand;
extern crate linked_hash_map;
extern crate fnv;
pub mod io;
pub mod error;
......
......@@ -7,6 +7,7 @@ extern crate phf;
extern crate ref_eq;
extern crate rand;
extern crate linked_hash_map;
extern crate fnv;
use structopt::StructOpt;
......
......@@ -20,8 +20,8 @@ pub struct HashTableState {
impl HashTableState {
pub fn new() -> Self {
HashTableState {
dynamic_rule_table: Rc::new(RefCell::new(HashTable::new())),
global_table: Rc::new(RefCell::new(HashTable::new())),
dynamic_rule_table: Rc::new(RefCell::new(HashTable::default())),
global_table: Rc::new(RefCell::new(HashTable::default())),
}
}
}
......@@ -77,7 +77,7 @@ pub fn hashtable_create<'d, 'f: 'd>(
))
} else {
Ok(context.factory.blob(
HashTable::with_capacity(capacity as usize).into(),
HashTable::with_capacity_and_hasher(capacity as usize, ::fnv::FnvBuildHasher::default()).into(),
))
}
}
......
......@@ -19,7 +19,7 @@ macro_rules! eprintln {
pub struct StringState {
new_alphacounter: u8,
new_counter: u16,
newname_counters: HashMap<String, usize>,
newname_counters: HashMap<String, usize, ::fnv::FnvBuildHasher>,
}
impl StringState {
......@@ -27,7 +27,7 @@ impl StringState {
StringState {
new_alphacounter: b'a',
new_counter: 0,
newname_counters: HashMap::new(),
newname_counters: ::fnv::FnvHashMap::default(),
}
}
}
......
......@@ -167,13 +167,13 @@ pub fn address<'d, 'f: 'd>(
) -> Result<ATermRef> {
use std::hash::Hash;
use std::hash::Hasher;
use std::collections::hash_map::DefaultHasher;
use fnv::FnvHasher;
if targs.len() < 1 {
return Err(Error::UnknownBehaviour(
"Primitive address called with wrong argument count",
));
}
let mut hasher = DefaultHasher::new();
let mut hasher = FnvHasher::default();
targs[0].hash(&mut hasher);
Ok(context.factory.int(hasher.finish() as i32))
}
......
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