instance Hashable Key for bloomfilter
This commit is contained in:
parent
8b74aec3ea
commit
a0a8127956
4 changed files with 13 additions and 8 deletions
|
@ -40,14 +40,14 @@ bloomBitsHashes = do
|
||||||
- Once the action completes, the mutable filter is frozen
|
- Once the action completes, the mutable filter is frozen
|
||||||
- for later use.
|
- for later use.
|
||||||
-}
|
-}
|
||||||
genBloomFilter :: Hashable t => (v -> t) -> ((v -> Annex ()) -> Annex b) -> Annex (Bloom t)
|
genBloomFilter :: Hashable v => ((v -> Annex ()) -> Annex b) -> Annex (Bloom v)
|
||||||
genBloomFilter convert populate = do
|
genBloomFilter populate = do
|
||||||
(numbits, numhashes) <- bloomBitsHashes
|
(numbits, numhashes) <- bloomBitsHashes
|
||||||
bloom <- lift $ newMB (cheapHashes numhashes) numbits
|
bloom <- lift $ newMB (cheapHashes numhashes) numbits
|
||||||
_ <- populate $ \v -> lift $ insertMB bloom (convert v)
|
_ <- populate $ \v -> lift $ insertMB bloom v
|
||||||
lift $ unsafeFreezeMB bloom
|
lift $ unsafeFreezeMB bloom
|
||||||
where
|
where
|
||||||
lift = liftIO . stToIO
|
lift = liftIO . stToIO
|
||||||
|
|
||||||
bloomFilter :: Hashable t => (v -> t) -> [v] -> Bloom t -> [v]
|
bloomFilter :: Hashable v => [v] -> Bloom v -> [v]
|
||||||
bloomFilter convert l bloom = filter (\k -> convert k `notElemB` bloom) l
|
bloomFilter l bloom = filter (\v -> v `notElemB` bloom) l
|
||||||
|
|
|
@ -167,7 +167,7 @@ excludeReferenced :: RefSpec -> [Key] -> Annex [Key]
|
||||||
excludeReferenced refspec ks = runfilter firstlevel ks >>= runfilter secondlevel
|
excludeReferenced refspec ks = runfilter firstlevel ks >>= runfilter secondlevel
|
||||||
where
|
where
|
||||||
runfilter _ [] = return [] -- optimisation
|
runfilter _ [] = return [] -- optimisation
|
||||||
runfilter a l = bloomFilter show l <$> genBloomFilter show a
|
runfilter a l = bloomFilter l <$> genBloomFilter a
|
||||||
firstlevel = withKeysReferencedM
|
firstlevel = withKeysReferencedM
|
||||||
secondlevel = withKeysReferencedInGit refspec
|
secondlevel = withKeysReferencedInGit refspec
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import System.Posix.Types
|
||||||
|
|
||||||
import Common
|
import Common
|
||||||
import Utility.QuickCheck
|
import Utility.QuickCheck
|
||||||
|
import Utility.Bloom
|
||||||
|
|
||||||
{- A Key has a unique name, which is derived from a particular backend,
|
{- A Key has a unique name, which is derived from a particular backend,
|
||||||
- and may contain other optional metadata. -}
|
- and may contain other optional metadata. -}
|
||||||
|
@ -130,6 +131,10 @@ instance Arbitrary Key where
|
||||||
<*> ((abs <$>) <$> arbitrary) -- chunksize cannot be negative
|
<*> ((abs <$>) <$> arbitrary) -- chunksize cannot be negative
|
||||||
<*> ((succ . abs <$>) <$> arbitrary) -- chunknum cannot be 0 or 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 :: Key -> Bool
|
||||||
prop_idempotent_key_encode k = Just k == (file2key . key2file) k
|
prop_idempotent_key_encode k = Just k == (file2key . key2file) k
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
module Utility.Bloom (
|
module Utility.Bloom (
|
||||||
Bloom,
|
Bloom,
|
||||||
safeSuggestSizing,
|
safeSuggestSizing,
|
||||||
Hashable,
|
Hashable(..),
|
||||||
cheapHashes,
|
cheapHashes,
|
||||||
notElemB,
|
notElemB,
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import qualified Data.BloomFilter as Bloom
|
||||||
import qualified Data.BloomFilter as Bloom
|
import qualified Data.BloomFilter as Bloom
|
||||||
#endif
|
#endif
|
||||||
import Data.BloomFilter.Easy (safeSuggestSizing, Bloom)
|
import Data.BloomFilter.Easy (safeSuggestSizing, Bloom)
|
||||||
import Data.BloomFilter.Hash (Hashable, cheapHashes)
|
import Data.BloomFilter.Hash (Hashable(..), cheapHashes)
|
||||||
import Control.Monad.ST (ST)
|
import Control.Monad.ST (ST)
|
||||||
|
|
||||||
#if MIN_VERSION_bloomfilter(2,0,0)
|
#if MIN_VERSION_bloomfilter(2,0,0)
|
||||||
|
|
Loading…
Reference in a new issue