Name: eth-bloom
Owner: ethereum
Description: An implementation of the Ethereum bloom filter.
Created: 2017-04-05 17:26:40.0
Updated: 2018-05-18 08:16:14.0
Pushed: 2018-04-10 16:45:20.0
Homepage: null
Size: 40
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A python implementation of the bloom filter used by Ethereum.
This library and repository was previously located at https://github.com/pipermerriam/ethereum-bloom. It was transferred to the Ethereum foundation github in November 2017 and renamed to
eth-bloom
. The PyPi package was also renamed fromethereum-bloom
to `eth-bloom.
For more information on what Ethereum Bloom Filters are see here
p install eth-bloom
install -e . -r requirements-dev.txt
You can run the tests with:
est tests
Or you can install tox
to run the full test suite.
Pandoc is required for transforming the markdown README to the proper format to render correctly on pypi.
For Debian-like systems:
install pandoc
Or on OSX:
install pandoc
To release a new version:
version $$VERSION_PART_TO_BUMP$$
push && git push --tags
release
The version format for this repo is {major}.{minor}.{patch}
for stable, and
{major}.{minor}.{patch}-{stage}.{devnum}
for unstable (stage
can be alpha or beta).
To issue the next version in line, use bumpversion and specify which part to bump,
like bumpversion minor
or bumpversion devnum
.
If you are in a beta version, bumpversion stage
will switch to a stable.
To issue an unstable version when the current version is stable, specify the
new version explicitly, like bumpversion --new-version 4.0.0-alpha.1 devnum
The BloomFilter
object
from eth_bloom import BloomFilter
b = BloomFilter()
b'a value' in b # check whether a value is present
e
b.add(b'a value') # add a single value
b'a value' in b
int(b) # cast to an integer
628712844765018311492773359360516229024449585949240367644166080576879632652362184119765613545163153674691520749911733485693171622325900647078772681584616740134230153806267998022370194756399579977294154062696916779055028045657302214591620589415314367270329881298073237757853875497241510733954508399863880080986777555986663988492288946856978031023631618215522505971170427986911575695114157059398791122395379400594948096
bin(b) # cast to a binary string
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
You can also add an iterable of items to a bloom filter.
b = BloomFilter()
b'value-a' in b
e
b'value-b' in b
e
b.extend([b'value-a', b'value-b'])
b'value-a' in b
b'value-b' in b
You can initialize a bloom filter from an iterable of byte strings.
b = BloomFilter.from_iterable([b'value-a', b'value-b']) # initialize from an iterable of values.
b'value-a' in b
b'value-b' in b
You can initialize a bloom filter from the integer representation of the bloom bits.
b = BloomFilter(3458628712844765018311492773359360516229024449585949240367644166080576879632652362184119765613545163153674691520749911733485693171622325900647078772681584616740134230153806267998022370194756399579977294154062696916779055028045657302214591620589415314367270329881298073237757853875497241510733954508399863880080986777555986663988492288946856978031023631618215522505971170427986911575695114157059398791122395379400594948096)
b'a value' in b
You can also merge bloom filters
from eth_bloom import BloomFilter
b1 = BloomFilter()
b2 = BloomFilter()
b1.add(b'a')
b1.add(b'common')
b2.add(b'b')
b2.add(b'common')
b'a' in b1
b'b' in b1
e
b'common' in b1
b'a' in b2
e
b'b' in b2
b'common' in b2
b3 = b1 + b2 # using addition
b'a' in b3
b'b' in b3
b'common' in b3
b4 = b1 | b2 # or using bitwise or
b'a' in b4
b'b' in b4
b'common' in b4
b1 |= b2 # or using in-place operations (works with += too)
b'a' in b1
b'b' in b1
b'common' in b1