bloomfilter 1.2.6.8 → 1.2.6.10
raw patch · 6 files changed
+131/−14 lines, 6 filesdep ~basedep ~bytestringPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base, bytestring
API changes (from Hackage documentation)
- Data.BloomFilter.Hash: class Hashable a
+ Data.BloomFilter.Hash: class Hashable a where hashIO64 v salt = do { let s1 = fromIntegral (salt `shiftR` 32) .&. maxBound s2 = fromIntegral salt; h1 <- hashIO32 v s1; h2 <- hashIO32 v s2; return $ (fromIntegral h1 `shiftL` 32) .|. fromIntegral h2 }
Files
- Data/BloomFilter/Array.hs +5/−1
- Data/BloomFilter/Hash.hs +4/−0
- README.markdown +6/−6
- bloomfilter.cabal +10/−7
- tests/QC.hs +63/−0
- tests/QCSupport.hs +43/−0
Data/BloomFilter/Array.hs view
@@ -1,11 +1,15 @@-{-# LANGUAGE FlexibleContexts, ForeignFunctionInterface, MagicHash,+{-# LANGUAGE CPP, FlexibleContexts, ForeignFunctionInterface, MagicHash, Rank2Types, UnliftedFFITypes #-} module Data.BloomFilter.Array (newArray) where import Control.Monad.ST (ST, unsafeIOToST) import Data.Array.Base (MArray, STUArray(..), unsafeNewArray_)+#if __GLASGOW_HASKELL__ >= 704+import Foreign.C.Types (CInt(..), CSize(..))+#else import Foreign.C.Types (CInt, CSize)+#endif import Foreign.Ptr (Ptr) import GHC.Base (MutableByteArray#)
Data/BloomFilter/Hash.hs view
@@ -44,7 +44,11 @@ import Data.Int (Int8, Int16, Int32, Int64) import Data.Word (Word8, Word16, Word32, Word64) import Foreign.C.String (CString)+#if __GLASGOW_HASKELL__ >= 704+import Foreign.C.Types (CInt(..), CSize(..))+#else import Foreign.C.Types (CInt, CSize)+#endif import Foreign.ForeignPtr (withForeignPtr) import Foreign.Marshal.Alloc (alloca) import Foreign.Marshal.Array (allocaArray, withArrayLen)
README.markdown view
@@ -1,6 +1,6 @@ # A fast, space efficient Bloom filter implementation -Copyright 2008, 2009, 2010 Bryan O'Sullivan <bos@serpentine.com>.+Copyright 2008, 2009, 2010, 2011 Bryan O'Sullivan <bos@serpentine.com>. This package provides both mutable and immutable Bloom filter data types, along with a family of hash function and an easy-to-use@@ -17,15 +17,15 @@ # Get involved! Please report bugs via the-[bitbucket issue tracker](http://bitbucket.org/bos/bloomfilter).+[github issue tracker](https://github.com/bos/bloomfilter). -Master [Mercurial repository](http://bitbucket.org/bos/bloomfilter):+Master [git repository](https://github.com/bos/bloomfilter): -* `hg clone http://bitbucket.org/bos/bloomfilter`+* `git clone git://github.com/bos/bloomfilter.git` -There's also a [git mirror](http://github.com/bos/bloomfilter):+There's also a [Mercurial mirror](https://bitbucket.org/bos/bloomfilter): -* `git clone git://github.com/bos/bloomfilter.git`+* `hg clone https://bitbucket.org/bos/bloomfilter` (You can create and contribute changes using either Mercurial or git.)
bloomfilter.cabal view
@@ -1,17 +1,17 @@ name: bloomfilter-version: 1.2.6.8+version: 1.2.6.10 license: BSD3 license-file: LICENSE author: Bryan O'Sullivan <bos@serpentine.com> maintainer: Bryan O'Sullivan <bos@serpentine.com>-homepage: http://www.serpentine.com/software/bloomfilter-bug-reports: http://bitbucket.org/bos/bloomfilter/issues+homepage: https://github.com/bos/bloomfilter+bug-reports: https://github.com/bos/bloomfilter/issues description: Pure and impure Bloom Filter implementations. synopsis: Pure and impure Bloom Filter implementations. category: Data stability: provisional build-type: Simple-cabal-version: >= 1.6+cabal-version: >= 1.8 extra-source-files: README.markdown cbits/lookup3.c cbits/lookup3.h examples/Makefile examples/SpellChecker.hs examples/Words.hs @@ -19,7 +19,7 @@ build-depends: array, base < 5,- bytestring == 0.9.*,+ bytestring >= 0.9, deepseq if impl(ghc >= 6.10) build-depends:@@ -31,11 +31,14 @@ Data.BloomFilter.Util c-sources: cbits/lookup3.c ghc-options: -O2 -Wall- ghc-prof-options: -auto-all include-dirs: cbits includes: lookup3.h install-includes: lookup3.h source-repository head+ type: git+ location: git://github.com/bos/bloomfilter.git++source-repository head type: mercurial- location: http://bitbucket.org/bos/bloomfilter+ location: https://bitbucket.org/bos/bloomfilter
+ tests/QC.hs view
@@ -0,0 +1,63 @@+module Main where++import Control.Monad (forM_)+import Data.BloomFilter.Easy (easyList, elemB)+import Data.BloomFilter.Hash (Hashable(..), hash64)+import qualified Data.ByteString.Char8 as SB+import qualified Data.ByteString.Lazy.Char8 as LB+import Data.Int (Int8, Int16, Int32, Int64)+import Data.Word (Word8, Word16, Word32, Word64)+import Test.Framework.Providers.QuickCheck2 (testProperty)+import System.IO (BufferMode(..), hSetBuffering, stdout)+import Test.Framework (Test, defaultMain)+import Test.QuickCheck (Property, Testable, (==>), choose, forAll)++import QCSupport (P(..))++prop_pai :: (Hashable a) => a -> a -> P -> Bool+prop_pai _ xs (P q) = let bf = easyList q [xs] in xs `elemB` bf++tests :: [Test]+tests = [+ testProperty "()" $ prop_pai ()+ , testProperty "Bool" $ prop_pai (undefined :: Bool)+ , testProperty "Ordering" $ prop_pai (undefined :: Ordering)+ , testProperty "Char" $ prop_pai (undefined :: Char)+ , testProperty "Int" $ prop_pai (undefined :: Int)+ , testProperty "Float" $ prop_pai (undefined :: Float)+ , testProperty "Double" $ prop_pai (undefined :: Double)+ , testProperty "Int8" $ prop_pai (undefined :: Int8)+ , testProperty "Int16" $ prop_pai (undefined :: Int16)+ , testProperty "Int32" $ prop_pai (undefined :: Int32)+ , testProperty "Int64" $ prop_pai (undefined :: Int64)+ , testProperty "Word8" $ prop_pai (undefined :: Word8)+ , testProperty "Word16" $ prop_pai (undefined :: Word16)+ , testProperty "Word32" $ prop_pai (undefined :: Word32)+ , testProperty "Word64" $ prop_pai (undefined :: Word64)+ , testProperty "String" $ prop_pai (undefined :: String)+ , testProperty "LB.ByteString" $ prop_pai (undefined :: LB.ByteString)+ , testProperty "prop_rechunked_eq" prop_rechunked_eq+ ]++rechunk :: Int64 -> LB.ByteString -> LB.ByteString+rechunk k xs | k <= 0 = xs+ | otherwise = LB.fromChunks (go xs)+ where go s | LB.null s = []+ | otherwise = let (pre,suf) = LB.splitAt k s+ in repack pre : go suf+ repack = SB.concat . LB.toChunks++-- Ensure that a property over a lazy ByteString holds if we change+-- the chunk boundaries.+prop_rechunked :: Eq a => (LB.ByteString -> a) -> LB.ByteString -> Property+prop_rechunked f s =+ let l = LB.length s+ in l > 0 ==> forAll (choose (1,l-1)) $ \k ->+ let n = k `mod` l+ in n > 0 ==> f s == f (rechunk n s)++prop_rechunked_eq :: LB.ByteString -> Property+prop_rechunked_eq = prop_rechunked hash64++main :: IO ()+main = defaultMain tests
+ tests/QCSupport.hs view
@@ -0,0 +1,43 @@+{-# LANGUAGE CPP, GeneralizedNewtypeDeriving #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++module QCSupport+ (+ P(..)+ ) where++import Data.Int (Int8, Int16, Int32, Int64)+import Data.Word (Word8, Word16, Word32, Word64)+import qualified Data.ByteString.Char8 as SB+import qualified Data.ByteString.Lazy.Char8 as LB+import System.Random (Random(..), RandomGen)+import Test.QuickCheck++newtype P = P { unP :: Double }+ deriving (Eq, Ord, Show, Fractional, Num, Random)++instance Arbitrary P where+ arbitrary = choose (epsilon, 1 - epsilon)+ where epsilon = 1e-6 :: P++instance Arbitrary Ordering where+ arbitrary = oneof [return LT, return GT, return EQ]++-- For some reason, MIN_VERSION_random doesn't work here :-(+#if __GLASGOW_HASKELL__ < 704+integralRandomR :: (Integral a, RandomGen g) => (a, a) -> g -> (a, g)+integralRandomR (a,b) g = case randomR (fromIntegral a :: Int,+ fromIntegral b :: Int) g+ of (x,g') -> (fromIntegral x, g')++instance Random Int64 where+ randomR = integralRandomR+ random = randomR (minBound,maxBound)+#endif++instance Arbitrary LB.ByteString where+ arbitrary = sized $ \n -> resize (round (sqrt (toEnum n :: Double)))+ ((LB.fromChunks . filter (not . SB.null)) `fmap` arbitrary)++instance Arbitrary SB.ByteString where+ arbitrary = SB.pack `fmap` arbitrary