Permalink
Browse files

Useful snapshot

  • Loading branch information...
1 parent f786745 commit 8a0b16be7f755fa96a98fa9fe9f1d13b3b26396f @bos committed May 21, 2008
Showing with 76 additions and 17 deletions.
  1. +4 −17 Data/BloomFilter.hs
  2. +29 −0 LICENSE
  3. +3 −0 Setup.lhs
  4. +40 −0 bloomfilter.cabal
View
@@ -24,10 +24,10 @@ module Data.BloomFilter
, (:*:)(..)
) where
-import Control.Monad (forM_, ap)
+import Control.Monad (forM_)
import Control.Monad.ST (ST, runST)
import Data.Array.Vector
-import Data.Bits ((.&.), (.|.), shiftL, shiftR)
+import Data.Bits ((.&.), (.|.), shiftL)
import Data.Word (Word32)
import Foreign.Storable (sizeOf)
@@ -111,9 +111,6 @@ bitsToLength :: Int -> Int
bitsToLength nubitsMB =
((nubitsMB - 1) `div` bitsInHash) + 1
-lengthToBits :: Int -> Int
-lengthToBits numElems = numElems * bitsInHash
-
lengthMB :: MBloom a s -> Int
{-# INLINE lengthMB #-}
lengthMB mb = bitsInHash * lengthMU (bitsMB mb)
@@ -129,22 +126,12 @@ unfoldUB hashes nubitsMB f k =
mb <- newMB hashes nubitsMB
loop mb k
unsafeFreezeMB mb
- where loop mb k = case f k of
- JustS (a :*: k') -> insertMB mb a >> loop mb k'
+ where loop mb j = case f j of
+ JustS (a :*: j') -> insertMB mb a >> loop mb j'
_ -> return ()
fromListUB :: [a -> Hash] -> Int -> [a] -> UBloom a
{-# INLINE fromListUB #-}
fromListUB hashes nubitsMB = unfoldUB hashes nubitsMB convert
where convert (x:xs) = JustS (x :*: xs)
convert _ = NothingS
-
-tryM = runST $ do
- mb <- newMB [fromIntegral] 32
- insertMB mb (1::Int)
- (,) `fmap` lookupMB mb 1 `ap` lookupMB mb 2
-
-tryU = runST $ do
- mb <- newMB [fromIntegral] 32
- insertMB mb (1::Int)
- unsafeFreezeMB mb
View
29 LICENSE
@@ -0,0 +1,29 @@
+Copyright 2008 Bryan O'Sullivan <bos@serpentine.com>.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the author nor the names of his contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
+OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,3 @@
+#!/usr/bin/env runhaskell
+> import Distribution.Simple
+> main = defaultMain
View
@@ -0,0 +1,40 @@
+name: bloomfilter
+version: 0.1
+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
+description: Pure and impure Bloom Filter implementations.
+synopsis: Pure and impure Bloom Filter implementations.
+category: Data
+stability: provisional
+build-type: Simple
+cabal-version: >= 1.2
+tested-with: GHC ==6.8.2
+extra-source-files: README index.html cbits/lookup3.c
+
+flag bytestring-in-base
+flag split-base
+
+library
+ build-depends: random, uvector
+
+ if flag(bytestring-in-base)
+ -- bytestring was in base-2.0 and 2.1.1
+ build-depends: base >= 2.0 && < 2.2
+ cpp-options: -DBYTESTRING_IN_BASE
+ else
+ -- in base 1.0 and 3.0 bytestring is a separate package
+ build-depends: base < 2.0 || >= 3, bytestring >= 0.9
+
+ if flag(split-base)
+ build-depends: base >= 3.0, containers, array
+ else
+ build-depends: base < 3.0
+
+ exposed-modules: Data.BloomFilter
+ Data.BloomFilter.Hash
+ c-sources: cbits/lookup3.c
+ ghc-options: -O2 -Wall -fliberate-case-threshold=1000
+ cc-options: -O3

0 comments on commit 8a0b16b

Please sign in to comment.