bloomfilter-redis 0.1.0.1 → 0.1.0.2
raw patch · 3 files changed
+16/−14 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.RedisBloom: querySafeBF :: (Applicative f, MonadRedis m, RedisCtx m f) => Bloom a -> a -> m (f Bool)
- Data.RedisBloom.Hash.FNV: fnvPrime :: forall a. (Num a, FiniteBits a) => a
+ Data.RedisBloom.Hash.FNV: fnvPrime :: (Num a, FiniteBits a) => a
- Data.RedisBloom.Suggestions: suggestCapacity :: forall a b. (Integral a, RealFrac b, Floating b) => a -> b -> Capacity
+ Data.RedisBloom.Suggestions: suggestCapacity :: (Integral a, RealFrac b, Floating b) => a -> b -> Capacity
- Data.RedisBloom.Suggestions: suggestHashCount :: forall a. (Integral a) => a -> Capacity -> HashCount
+ Data.RedisBloom.Suggestions: suggestHashCount :: (Integral a) => a -> Capacity -> HashCount
Files
- CHANGELOG.md +5/−0
- bloomfilter-redis.cabal +1/−1
- src/Data/RedisBloom.hs +10/−13
CHANGELOG.md view
@@ -1,3 +1,8 @@+0.1.0.2+------+* Fix bad Hackage upload of 0.1.0.2 (it accidentally contained a+ breaking API change to be released in a later version)+ 0.1.0.1 ------ * README improvements
bloomfilter-redis.cabal view
@@ -1,5 +1,5 @@ name: bloomfilter-redis-version: 0.1.0.1+version: 0.1.0.2 synopsis: Distributed bloom filters on Redis (using the Hedis client). description: Distributed bloom filters on Redis (using the Hedis client).
src/Data/RedisBloom.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE CPP #-} {-# LANGUAGE Trustworthy #-} @@ -12,7 +11,7 @@ -- ** Static bloom filter configuration Bloom(..), -- * Bloom filter operations- createBF, createIfNewBF, addBF, queryBF, querySafeBF+ createBF, createIfNewBF, addBF, queryBF ) where #if !MIN_VERSION_base(4,8,0)@@ -58,28 +57,26 @@ (Capacity cap) = capacity bf one = pack "1" -getBit :: forall m f a. (Functor f, MonadRedis m, RedisCtx m f) => Bloom a -> Integer -> m (f Bool)+getBit :: (MonadRedis m, RedisCtx m (Either Reply)) => Bloom a -> Integer -> m Bool getBit bf i = do r <- getbit (key bf) i- return . fmap (>= 1) $ (r :: f Integer)---- | Query whether an element exists in the bloom filter.-querySafeBF :: (Applicative f, MonadRedis m, RedisCtx m f) => Bloom a -> a -> m (f Bool)-querySafeBF bf = query (capacity bf) (getBit bf) (hf bf)+ let l = case r of+ Left _ -> False+ Right j -> j >= 1+ return l -- | Query whether an element exists in the bloom filter. -- -- Gracefully fails upon failure by returning 'False'. queryBF :: (MonadRedis m, RedisCtx m (Either Reply)) => Bloom a -> a -> m Bool-queryBF bf = fmap (either (const False) id) . query (capacity bf) (getBit bf) (hf bf)+queryBF bf = query (capacity bf) (getBit bf) (hf bf) -query :: (Applicative f, Monad m) => Capacity -> (Integer -> m (f Bool)) -> HashFamily a -> a -> m (f Bool)+query :: Monad m => Capacity -> (Integer -> m Bool) -> HashFamily a -> a -> m Bool query (Capacity c) q hashf x = do let hashes = fmap (toInteger . (`mod` c) . fromIntegral) . hashf $ x lookupMany q hashes -lookupMany :: (Applicative f, Traversable t, Monad m) => (a -> m (f Bool)) -> t a -> m (f Bool)+lookupMany :: (Traversable t, Monad m) => (a -> m Bool) -> t a -> m Bool lookupMany lookupBit hashes = do bools <- mapM lookupBit hashes- let b' = fmap (getAll . foldMap All) . sequenceA $ bools- return b'+ return . getAll . foldMap All $ bools