Skip to content

Commit

Permalink
Merge pull request #10 from seomoz/linting
Browse files Browse the repository at this point in the history
Linting and cleaning up some of the source
  • Loading branch information
dlecocq committed Mar 20, 2014
2 parents 19cca48 + c770c13 commit 9ee0114
Show file tree
Hide file tree
Showing 12 changed files with 1,528 additions and 1,483 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
build/*
dist/
*.o

*.so
*.pyc
pyreBloom/pyre
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: python
services:
- redis-server
python:
- '2.7'
install:
- 'sudo apt-get install libhiredis-dev'
- 'pip install -r requirements.txt'
- 'make install'
script: make test
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
build: pyreBloom/*.c
python setup.py build_ext --inplace

install:
python setup.py install

clean:
# Remove the build
sudo rm -rf build dist
find . -name '*.pyc' | xargs -n 100 rm
find . -name .coverage | xargs rm
find . -name '*.o' | xargs rm
find . -name '*.so' | xargs rm

.PHONY: test
test: install
rm -f .coverage
nosetests --exe -v
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__Py__thon + __Re__dis + __Bloom__ Filter = pyreBloom
Python + Redis + Bloom Filter = pyreBloom
=====================================================
[![Build Status](https://travis-ci.org/seomoz/pyreBloom.svg?branch=linting)](https://travis-ci.org/seomoz/pyreBloom)

One of Salvatore's suggestions for Redis' GETBIT and SETBIT commands is to
implement bloom filters. There was an existing python project that we used
Expand All @@ -18,11 +19,14 @@ versions.
Installation
============

You will need `hiredis` installed, as well as Cython (for the time being --
we'd like to remove this dependency soon), and a C compiler (probably GCC).
You will need `hiredis` installed, and a C compiler (probably GCC). You can
optionally have `Cython` installed, which will generate the C extension code.
With those things installed, it's pretty simple:

sudo python setup.py install
```bash
pip install -r requirements
python setup.py install
```

Hiredis
-------
Expand Down Expand Up @@ -51,27 +55,33 @@ modes are about 4-5 times faster than their serial equivalents, so use them
when you can. When you instantiate a pyreBloom, you should give it a redis
key name, a capacity, and an error rate:

import pyreBloom
p = pyreBloom.pyreBloom('myBloomFilter', 100000, 0.01)
# You can find out how many bits this will theoretically consume
p.bytes
# And how many hashes are needed to satisfy the false positive rate
p.hashes
```python
import pyreBloom
p = pyreBloom.pyreBloom('myBloomFilter', 100000, 0.01)
# You can find out how many bits this will theoretically consume
p.bytes
# And how many hashes are needed to satisfy the false positive rate
p.hashes
```

From that point, you can add elements quite easily:

tests = ['hello', 'how', 'are', 'you', 'today']
p.extend(tests)
```python
tests = ['hello', 'how', 'are', 'you', 'today']
p.extend(tests)
```

The batch mode of `contains` differs from the serial version in that it actually
returns which elements are in the bloom filter:

p.contains('hello')
# True
p.contains(['hello', 'whats', 'new', 'with', 'you'])
# ['hello', 'you']
'hello' in p
# True
```python
p.contains('hello')
# True
p.contains(['hello', 'whats', 'new', 'with', 'you'])
# ['hello', 'you']
'hello' in p
# True
```

The Story
=========
Expand Down
Loading

0 comments on commit 9ee0114

Please sign in to comment.