Skip to content

Commit

Permalink
Merge pull request #19 from johnmyleswhite/v0.2.0
Browse files Browse the repository at this point in the history
Fixes bad merge on #17
  • Loading branch information
boydgreenfield authored Mar 11, 2017
2 parents bdfae54 + 421ce8d commit 26a4a30
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.juliahistory
*~
23 changes: 12 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
language: cpp
compiler:
- clang
language: julia
os:
- linux
- osx
julia:
- 0.4
- 0.5
- nightly
notifications:
email: false
before_install:
- sudo add-apt-repository ppa:staticfloat/julia-deps -y
- sudo add-apt-repository ppa:staticfloat/julianightlies -y
- sudo apt-get update -qq -y
- sudo apt-get install libpcre3-dev julia -y
script:
- julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir("BloomFilters"))`); Pkg.pin("BloomFilters"); Pkg.resolve()'
- julia -e 'using BloomFilters; @assert isdefined(:BloomFilters); @assert typeof(BloomFilters) === Module; include(joinpath(Pkg.dir("BloomFilters"), "test/runtests.jl"))'
# uncomment the following lines to override the default test script
#script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("BloomFilters"); Pkg.test("BloomFilters"; coverage=true)'
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.3.1-
julia 0.4
Compat 0.3.2
21 changes: 12 additions & 9 deletions src/bloom-filter.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Compat
import Base.Mmap: mmap

include("probabilities.jl")

type BloomFilter
Expand All @@ -6,7 +9,7 @@ type BloomFilter
capacity::Int
error_rate::Float64
n_bits::Int
mmap_location::String
mmap_location::AbstractString
end

### Hash functions (uses 2 hash method)
Expand All @@ -17,7 +20,7 @@ end
function hash_n(key::Any, k::Int, max::Int)
a_hash = hash(key, UInt(0))
b_hash = hash(key, UInt(170))
hashes = Array(Uint, k)
hashes = Array(UInt, k)
for i in 1:k
hashes[i] = mod(a_hash + i * b_hash, max) + 1
end
Expand All @@ -36,11 +39,11 @@ end

function BloomFilter(mmap_handle::IOStream, capacity::Int, bits_per_elem::Int, k_hashes::Int)
n_bits = capacity * bits_per_elem
mb = mmap_bitarray((n_bits, 1), mmap_handle)
mb = mmap(mmap_handle, BitArray, n_bits)
BloomFilter(mb, k_hashes, capacity, NaN, n_bits, mmap_handle.name)
end

function BloomFilter(mmap_string::String, capacity::Int, bits_per_elem::Int, k_hashes::Int)
function BloomFilter(mmap_string::AbstractString, capacity::Int, bits_per_elem::Int, k_hashes::Int)
if isfile(mmap_string)
mmap_handle = open(mmap_string, "r+")
else
Expand All @@ -64,11 +67,11 @@ end
function BloomFilter(mmap_handle::IOStream, capacity::Int, error_rate::Float64, k_hashes::Int)
bits_per_elem, error_rate = get_k_error(error_rate, k_hashes)
n_bits = capacity * bits_per_elem
mb = mmap_bitarray((n_bits, 1), mmap_handle)
mb = mmap(mmap_handle, BitArray, n_bits)
BloomFilter(mb, k_hashes, capacity, error_rate, n_bits, mmap_handle.name)
end

function BloomFilter(mmap_string::String, capacity::Int, error_rate::Float64, k_hashes::Int)
function BloomFilter(mmap_string::AbstractString, capacity::Int, error_rate::Float64, k_hashes::Int)
if isfile(mmap_string)
mmap_handle = open(mmap_string, "r+")
else
Expand All @@ -93,12 +96,12 @@ end
function BloomFilter(mmap_handle::IOStream, capacity::Int, error_rate::Float64)
bits_per_elem = round(Int, ceil(-1.0 * (log(error_rate) / (log(2) ^ 2))))
k_hashes = round(Int, log(2) * bits_per_elem) # Note: ceil() would be strictly more conservative
n_bits = capacity * bits_per_elem
mb = mmap_bitarray((n_bits, 1), mmap_handle)
n_bits = capacity * bits_per_elem
mb = mmap(mmap_handle, BitArray, n_bits)
BloomFilter(mb, k_hashes, capacity, error_rate, n_bits, mmap_handle.name)
end

function BloomFilter(mmap_string::String, capacity::Int, error_rate::Float64)
function BloomFilter(mmap_string::AbstractString, capacity::Int, error_rate::Float64)
if isfile(mmap_string)
mmap_handle = open(mmap_string, "r+")
else
Expand Down

0 comments on commit 26a4a30

Please sign in to comment.