]> git.lizzy.rs Git - rust.git/commitdiff
hack for now: map uint hashes into a u32, which helps x86_64 perf.
authorNiko Matsakis <niko@alum.mit.edu>
Tue, 6 Dec 2011 23:55:11 +0000 (15:55 -0800)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 7 Dec 2011 03:55:46 +0000 (19:55 -0800)
src/libstd/map.rs

index c802b5b889ffa9c2eb77ead7e53338b8840b55ab..a4ef467401742b6a55fe635f5ab261000c3f1a62 100644 (file)
@@ -137,21 +137,25 @@ fn make_buckets<copy K, copy V>(nbkts: uint) -> [mutable bucket<K, V>] {
     // is always a power of 2), so that all buckets are probed for a
     // fixed key.
 
-    fn hashl(n: uint, _nbkts: uint) -> uint { ret (n >>> 16u) * 2u + 1u; }
-    fn hashr(n: uint, _nbkts: uint) -> uint { ret 0x0000_ffff_u & n; }
-    fn hash(h: uint, nbkts: uint, i: uint) -> uint {
-        ret (hashl(h, nbkts) * i + hashr(h, nbkts)) % nbkts;
+    fn hashl(n: u32) -> u32 { ret (n >>> 16u32) * 2u32 + 1u32; }
+    fn hashr(n: u32) -> u32 { ret 0x0000_ffff_u32 & n; }
+    fn hash(h: u32, nbkts: uint, i: uint) -> uint {
+        ret ((hashl(h) as uint) * i + (hashr(h) as uint)) % nbkts;
     }
+
+    fn to_u64(h: uint) -> u32 {
+        ret (h as u32) ^ ((h >>> 16u) as u32);
+    }
+
     /**
      * We attempt to never call this with a full table.  If we do, it
      * will fail.
      */
-
     fn insert_common<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>,
                                      bkts: [mutable bucket<K, V>],
                                      nbkts: uint, key: K, val: V) -> bool {
         let i: uint = 0u;
-        let h: uint = hasher(key);
+        let h = to_u64(hasher(key));
         while i < nbkts {
             let j: uint = hash(h, nbkts, i);
             alt bkts[j] {
@@ -171,7 +175,7 @@ fn find_common<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>,
                                    bkts: [mutable bucket<K, V>],
                                    nbkts: uint, key: K) -> option::t<V> {
         let i: uint = 0u;
-        let h: uint = hasher(key);
+        let h = to_u64(hasher(key));
         while i < nbkts {
             let j: uint = hash(h, nbkts, i);
             alt bkts[j] {
@@ -244,7 +248,7 @@ fn find(key: K) -> option::t<V> {
         }
         fn remove(key: K) -> option::t<V> {
             let i: uint = 0u;
-            let h: uint = hasher(key);
+            let h = to_u64(hasher(key));
             while i < nbkts {
                 let j: uint = hash(h, nbkts, i);
                 alt bkts[j] {