summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-06-16 18:37:41 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-06-16 18:37:41 -0400
commite3da28295e11972bcb14749ef294d1f39fb03efa (patch)
tree3d30dde99abd43c739395f8ef943ad6129693a9c
parent87ba1abc7cd1b199b0f7d778d9f27375b50de709 (diff)
instance Hashable Key for bloomfilter
-rw-r--r--Annex/BloomFilter.hs10
-rw-r--r--Command/Unused.hs2
-rw-r--r--Types/Key.hs5
-rw-r--r--Utility/Bloom.hs4
4 files changed, 13 insertions, 8 deletions
diff --git a/Annex/BloomFilter.hs b/Annex/BloomFilter.hs
index 3dcd8140b..3ac81fa58 100644
--- a/Annex/BloomFilter.hs
+++ b/Annex/BloomFilter.hs
@@ -40,14 +40,14 @@ bloomBitsHashes = do
- Once the action completes, the mutable filter is frozen
- for later use.
-}
-genBloomFilter :: Hashable t => (v -> t) -> ((v -> Annex ()) -> Annex b) -> Annex (Bloom t)
-genBloomFilter convert populate = do
+genBloomFilter :: Hashable v => ((v -> Annex ()) -> Annex b) -> Annex (Bloom v)
+genBloomFilter populate = do
(numbits, numhashes) <- bloomBitsHashes
bloom <- lift $ newMB (cheapHashes numhashes) numbits
- _ <- populate $ \v -> lift $ insertMB bloom (convert v)
+ _ <- populate $ \v -> lift $ insertMB bloom v
lift $ unsafeFreezeMB bloom
where
lift = liftIO . stToIO
-bloomFilter :: Hashable t => (v -> t) -> [v] -> Bloom t -> [v]
-bloomFilter convert l bloom = filter (\k -> convert k `notElemB` bloom) l
+bloomFilter :: Hashable v => [v] -> Bloom v -> [v]
+bloomFilter l bloom = filter (\v -> v `notElemB` bloom) l
diff --git a/Command/Unused.hs b/Command/Unused.hs
index 82a605290..7bf252243 100644
--- a/Command/Unused.hs
+++ b/Command/Unused.hs
@@ -167,7 +167,7 @@ excludeReferenced :: RefSpec -> [Key] -> Annex [Key]
excludeReferenced refspec ks = runfilter firstlevel ks >>= runfilter secondlevel
where
runfilter _ [] = return [] -- optimisation
- runfilter a l = bloomFilter show l <$> genBloomFilter show a
+ runfilter a l = bloomFilter l <$> genBloomFilter a
firstlevel = withKeysReferencedM
secondlevel = withKeysReferencedInGit refspec
diff --git a/Types/Key.hs b/Types/Key.hs
index 553fd8f3d..7f9f514c7 100644
--- a/Types/Key.hs
+++ b/Types/Key.hs
@@ -26,6 +26,7 @@ import System.Posix.Types
import Common
import Utility.QuickCheck
+import Utility.Bloom
{- A Key has a unique name, which is derived from a particular backend,
- and may contain other optional metadata. -}
@@ -130,6 +131,10 @@ instance Arbitrary Key where
<*> ((abs <$>) <$> arbitrary) -- chunksize cannot be negative
<*> ((succ . abs <$>) <$> arbitrary) -- chunknum cannot be 0 or negative
+instance Hashable Key where
+ hashIO32 = hashIO32 . show
+ hashIO64 = hashIO64 . show
+
prop_idempotent_key_encode :: Key -> Bool
prop_idempotent_key_encode k = Just k == (file2key . key2file) k
diff --git a/Utility/Bloom.hs b/Utility/Bloom.hs
index 95ade6d32..9076abddb 100644
--- a/Utility/Bloom.hs
+++ b/Utility/Bloom.hs
@@ -10,7 +10,7 @@
module Utility.Bloom (
Bloom,
safeSuggestSizing,
- Hashable,
+ Hashable(..),
cheapHashes,
notElemB,
@@ -26,7 +26,7 @@ import qualified Data.BloomFilter as Bloom
import qualified Data.BloomFilter as Bloom
#endif
import Data.BloomFilter.Easy (safeSuggestSizing, Bloom)
-import Data.BloomFilter.Hash (Hashable, cheapHashes)
+import Data.BloomFilter.Hash (Hashable(..), cheapHashes)
import Control.Monad.ST (ST)
#if MIN_VERSION_bloomfilter(2,0,0)