about summary refs log tree commit diff
path: root/src/librustsyntax
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-05-23 00:38:39 -0700
committerBrian Anderson <banderson@mozilla.com>2012-05-23 00:43:02 -0700
commit4756556748fe7fa247c02f36dc481c8eeae9908d (patch)
treea914d555843f7325f8d3120e262cedc914b17a81 /src/librustsyntax
parent8ec467d521e6e39f80a0c74c049a5aa719a01dde (diff)
downloadrust-4756556748fe7fa247c02f36dc481c8eeae9908d.tar.gz
rust-4756556748fe7fa247c02f36dc481c8eeae9908d.zip
rustc: Move new_def_hash to ast_util
Diffstat (limited to 'src/librustsyntax')
-rw-r--r--src/librustsyntax/ast_util.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/librustsyntax/ast_util.rs b/src/librustsyntax/ast_util.rs
index 55743f91713..0357b5dbf87 100644
--- a/src/librustsyntax/ast_util.rs
+++ b/src/librustsyntax/ast_util.rs
@@ -225,6 +225,23 @@ fn hash_ty(&&t: @ty) -> uint {
     ret res;
 }
 
+fn def_eq(a: ast::def_id, b: ast::def_id) -> bool {
+    ret a.crate == b.crate && a.node == b.node;
+}
+
+fn hash_def(d: ast::def_id) -> uint {
+    let mut h = 5381u;
+    h = (h << 5u) + h ^ (d.crate as uint);
+    h = (h << 5u) + h ^ (d.node as uint);
+    ret h;
+}
+
+fn new_def_hash<V: copy>() -> std::map::hashmap<ast::def_id, V> {
+    let hasher: std::map::hashfn<ast::def_id> = hash_def;
+    let eqer: std::map::eqfn<ast::def_id> = def_eq;
+    ret std::map::hashmap::<ast::def_id, V>(hasher, eqer);
+}
+
 fn hash_def_id(&&id: def_id) -> uint {
     (id.crate as uint << 16u) + (id.node as uint)
 }