[improve choosing initial id guesses via hash mixing
John Meacham <john@repetae.net>**20120117130126
 Ignore-this: 1bfa4c56a8a0ea224008e447672c430f
] hunk ./src/E/Subst.hs 18
-
hunk ./src/E/Subst.hs 28
-
hunk ./src/E/Subst.hs 56
-
hunk ./src/E/Subst.hs 75
-
-
-
hunk ./src/E/Subst.hs 83
-
-
hunk ./src/E/Subst.hs 165
-
-
hunk ./src/E/Subst.hs 167
-    | allShadow = newId (Set.size xs + Set.size s + size ss) (not . scheck)
-    | isInvalidId i || scheck i = newId (Set.size xs + Set.size s + size ss) (not . check)
+    | allShadow = newId (Set.size xs `mixInt` Set.size s `mixInt` size ss) (not . scheck)
+    | isInvalidId i || scheck i = newId (Set.size xs `mixInt` Set.size s `mixInt` size ss) (not . check)
hunk ./src/E/Subst.hs 174
-
-
hunk ./src/E/Subst.hs 280
-
-
hunk ./src/Name/Id.hs 30
+    mixInt,
+    mixInt3,
hunk ./src/Name/Id.hs 42
-import Data.Word
hunk ./src/Name/Id.hs 76
-
-
hunk ./src/Name/Id.hs 79
-
-
hunk ./src/Name/Id.hs 130
-
hunk ./src/Name/Id.hs 162
-
hunk ./src/Name/Id.hs 164
-
hunk ./src/Name/Id.hs 208
-        fromIdNameT $ newNameFrom (candidateIds (size used `xor` 128 * size bound))
+        fromIdNameT $ newNameFrom (candidateIds (size used `mixInt` size bound))
hunk ./src/Name/Id.hs 244
-
-
hunk ./src/Name/Id.hs 260
-
hunk ./src/Name/Id.hs 264
-newIds (IntjectionSet ids) = [ Id i | Id i <- candidateIds (size ids' `xor` IS.findMin ids' `xor` IS.findMax ids') , i `notMember` ids ] where
-    ids' = if size ids == 0 then IS.insert 0 ids else ids
-
+newIds (IntjectionSet ids) = ans where
+    ans = if sids == 0 then candidateIds 42 else [ Id i | Id i <- candidates, i `notMember` ids ]
+    sids = size ids
+    candidates = candidateIds (mixInt3 sids (IS.findMin ids) (IS.findMax ids))
hunk ./src/Name/Id.hs 281
-hashInt :: Int -> Int
-hashInt x = fromIntegral $ f (fromIntegral x) where
-    f :: Word -> Word
-    f a = a''''' where
-        !a' = (a `xor` 61) `xor` (a `shiftR` 16)
-        !a'' = a' + (a' `shiftL` 3)
-        !a''' = a'' `xor` (a'' `shiftR` 4)
-        !a'''' = a''' * 0x27d4eb2d
-        !a''''' = a'''' `xor` (a'''' `shiftR` 15)
-
hunk ./src/Name/Id.hs 292
-
hunk ./src/Util/NameMonad.hs 1
-module Util.NameMonad(NameMonad(..), GenName(..), NameMT, runNameMT, runNameMT', freeNames) where
+module Util.NameMonad(NameMonad(..),GenName(..),NameMT,runNameMT,runNameMT',freeNames,mixInt,mixInt3,hashInt) where
hunk ./src/Util/NameMonad.hs 3
--- This may be horrid overdesign. I broke several principles I usually use to
--- prevent ones natural tendancy to overdesign.
-
-import qualified Data.Set as Set
hunk ./src/Util/NameMonad.hs 4
+import Data.Bits
+import Data.Word
+import qualified Data.Set as Set
hunk ./src/Util/NameMonad.hs 85
-        fromNameMT $ newNameFrom  (genNames (Set.size used + Set.size bound))
+        fromNameMT $ newNameFrom  (genNames (Set.size used `mixInt` Set.size bound))
+
+hashInt :: Int -> Int
+hashInt x = fromIntegral $ f (fromIntegral x) where
+    f :: Word -> Word
+    f a = a''''' where
+        !a' = (a `xor` 61) `xor` (a `shiftR` 16)
+        !a'' = a' + (a' `shiftL` 3)
+        !a''' = a'' `xor` (a'' `shiftR` 4)
+        !a'''' = a''' * 0x27d4eb2d
+        !a''''' = a'''' `xor` (a'''' `shiftR` 15)
+
+mixInt :: Int -> Int -> Int
+mixInt x y = hashInt x - hashInt y
hunk ./src/Util/NameMonad.hs 100
+mixInt3 :: Int -> Int -> Int -> Int
+mixInt3 x y z = (hashInt x - hashInt y) `xor` hashInt z