{ "info": { "author": "Khoa Duong", "author_email": "dnanhkhoa@live.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3" ], "description": "# simple-bloom-filter\n\n[![PyPI](https://img.shields.io/pypi/v/simplebloomfilter.svg)]()\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/simplebloomfilter.svg)]()\n\nA simple implementation of Bloom Filter and Scalable Bloom Filter for Python 3.\n\n## Installation\n\nYou can install this package from PyPI using [pip](http://www.pip-installer.org):\n\n```\n$ [sudo] pip install simplebloomfilter\n```\n\n## Example Usage\n\n```python\n#!/usr/bin/python\n# -*- coding: utf-8 -*-\nfrom bloomfilter import BloomFilter, ScalableBloomFilter, SizeGrowthRate\n\nanimals = [\n \"dog\",\n \"cat\",\n \"giraffe\",\n \"fly\",\n \"mosquito\",\n \"horse\",\n \"eagle\",\n \"bird\",\n \"bison\",\n \"boar\",\n \"butterfly\",\n \"ant\",\n \"anaconda\",\n \"bear\",\n \"chicken\",\n \"dolphin\",\n \"donkey\",\n \"crow\",\n \"crocodile\",\n]\n\nother_animals = [\n \"badger\",\n \"cow\",\n \"pig\",\n \"sheep\",\n \"bee\",\n \"wolf\",\n \"fox\",\n \"whale\",\n \"shark\",\n \"fish\",\n \"turkey\",\n \"duck\",\n \"dove\",\n \"deer\",\n \"elephant\",\n \"frog\",\n \"falcon\",\n \"goat\",\n \"gorilla\",\n \"hawk\",\n]\n\n\ndef bloom_filter_example():\n print(\"========== Bloom Filter Example ==========\")\n bloom_filter = BloomFilter(size=1000, fp_prob=1e-6)\n\n # Insert items into Bloom filter\n for animal in animals:\n bloom_filter.add(animal)\n\n # Print several statistics of the filter\n print(\n \"+ Capacity: {} item(s)\".format(bloom_filter.size),\n \"+ Number of inserted items: {}\".format(len(bloom_filter)),\n \"+ Filter size: {} bit(s)\".format(bloom_filter.filter_size),\n \"+ False Positive probability: {}\".format(bloom_filter.fp_prob),\n \"+ Number of hash functions: {}\".format(bloom_filter.num_hashes),\n sep=\"\\n\",\n end=\"\\n\\n\",\n )\n\n # Check whether an item is in the filter or not\n for animal in animals + other_animals:\n if animal in bloom_filter:\n if animal in other_animals:\n print(\n f'\"{animal}\" is a FALSE POSITIVE case (please adjust fp_prob to a smaller value).'\n )\n else:\n print(f'\"{animal}\" is PROBABLY IN the filter.')\n else:\n print(f'\"{animal}\" is DEFINITELY NOT IN the filter as expected.')\n\n # Save to file\n with open(\"bloom_filter.bin\", \"wb\") as fp:\n bloom_filter.save(fp)\n\n # Load from file\n with open(\"bloom_filter.bin\", \"rb\") as fp:\n bloom_filter = BloomFilter.load(fp)\n\n\ndef scalable_bloom_filter_example():\n print(\"========== Bloom Filter Example ==========\")\n scalable_bloom_filter = ScalableBloomFilter(\n initial_size=100,\n initial_fp_prob=1e-7,\n size_growth_rate=SizeGrowthRate.LARGE,\n fp_prob_rate=0.9,\n )\n # Insert items into Bloom filter\n for animal in animals:\n scalable_bloom_filter.add(animal)\n\n # Print several statistics of the filter\n print(\n \"+ Capacity: {} item(s)\".format(scalable_bloom_filter.size),\n \"+ Number of inserted items: {}\".format(len(scalable_bloom_filter)),\n \"+ Number of Bloom filters: {}\".format(scalable_bloom_filter.num_filters),\n \"+ Total size of filters: {} bit(s)\".format(scalable_bloom_filter.filter_size),\n \"+ False Positive probability: {}\".format(scalable_bloom_filter.fp_prob),\n sep=\"\\n\",\n end=\"\\n\\n\",\n )\n\n # Check whether an item is in the filter or not\n for animal in animals + other_animals:\n if animal in scalable_bloom_filter:\n if animal in other_animals:\n print(\n f'\"{animal}\" is a FALSE POSITIVE case (please adjust fp_prob to a smaller value).'\n )\n else:\n print(f'\"{animal}\" is PROBABLY IN the filter.')\n else:\n print(f'\"{animal}\" is DEFINITELY NOT IN the filter as expected.')\n\n # Save to file\n with open(\"scalable_bloom_filter.bin\", \"wb\") as fp:\n scalable_bloom_filter.save(fp)\n\n # Load from file\n with open(\"scalable_bloom_filter.bin\", \"rb\") as fp:\n scalable_bloom_filter = ScalableBloomFilter.load(fp)\n\n\nif __name__ == \"__main__\":\n bloom_filter_example()\n scalable_bloom_filter_example()\n```\n```\n========== Bloom Filter Example ==========\n+ Capacity: 1000 item(s)\n+ Number of inserted items: 19\n+ Filter size: 28756 bit(s)\n+ False Positive probability: 1e-06\n+ Number of hash functions: 20\n\n\"dog\" is PROBABLY IN the filter.\n\"cat\" is PROBABLY IN the filter.\n\"giraffe\" is PROBABLY IN the filter.\n\"fly\" is PROBABLY IN the filter.\n\"mosquito\" is PROBABLY IN the filter.\n\"horse\" is PROBABLY IN the filter.\n\"eagle\" is PROBABLY IN the filter.\n\"bird\" is PROBABLY IN the filter.\n\"bison\" is PROBABLY IN the filter.\n\"boar\" is PROBABLY IN the filter.\n\"butterfly\" is PROBABLY IN the filter.\n\"ant\" is PROBABLY IN the filter.\n\"anaconda\" is PROBABLY IN the filter.\n\"bear\" is PROBABLY IN the filter.\n\"chicken\" is PROBABLY IN the filter.\n\"dolphin\" is PROBABLY IN the filter.\n\"donkey\" is PROBABLY IN the filter.\n\"crow\" is PROBABLY IN the filter.\n\"crocodile\" is PROBABLY IN the filter.\n\"badger\" is DEFINITELY NOT IN the filter as expected.\n\"cow\" is DEFINITELY NOT IN the filter as expected.\n\"pig\" is DEFINITELY NOT IN the filter as expected.\n\"sheep\" is DEFINITELY NOT IN the filter as expected.\n\"bee\" is DEFINITELY NOT IN the filter as expected.\n\"wolf\" is DEFINITELY NOT IN the filter as expected.\n\"fox\" is DEFINITELY NOT IN the filter as expected.\n\"whale\" is DEFINITELY NOT IN the filter as expected.\n\"shark\" is DEFINITELY NOT IN the filter as expected.\n\"fish\" is DEFINITELY NOT IN the filter as expected.\n\"turkey\" is DEFINITELY NOT IN the filter as expected.\n\"duck\" is DEFINITELY NOT IN the filter as expected.\n\"dove\" is DEFINITELY NOT IN the filter as expected.\n\"deer\" is DEFINITELY NOT IN the filter as expected.\n\"elephant\" is DEFINITELY NOT IN the filter as expected.\n\"frog\" is DEFINITELY NOT IN the filter as expected.\n\"falcon\" is DEFINITELY NOT IN the filter as expected.\n\"goat\" is DEFINITELY NOT IN the filter as expected.\n\"gorilla\" is DEFINITELY NOT IN the filter as expected.\n\"hawk\" is DEFINITELY NOT IN the filter as expected.\n\n\n========== Bloom Filter Example ==========\n+ Capacity: 100 item(s)\n+ Number of inserted items: 19\n+ Number of Bloom filters: 1\n+ Total size of filters: 3355 bit(s)\n+ False Positive probability: 9.999999994736442e-08\n\n\"dog\" is PROBABLY IN the filter.\n\"cat\" is PROBABLY IN the filter.\n\"giraffe\" is PROBABLY IN the filter.\n\"fly\" is PROBABLY IN the filter.\n\"mosquito\" is PROBABLY IN the filter.\n\"horse\" is PROBABLY IN the filter.\n\"eagle\" is PROBABLY IN the filter.\n\"bird\" is PROBABLY IN the filter.\n\"bison\" is PROBABLY IN the filter.\n\"boar\" is PROBABLY IN the filter.\n\"butterfly\" is PROBABLY IN the filter.\n\"ant\" is PROBABLY IN the filter.\n\"anaconda\" is PROBABLY IN the filter.\n\"bear\" is PROBABLY IN the filter.\n\"chicken\" is PROBABLY IN the filter.\n\"dolphin\" is PROBABLY IN the filter.\n\"donkey\" is PROBABLY IN the filter.\n\"crow\" is PROBABLY IN the filter.\n\"crocodile\" is PROBABLY IN the filter.\n\"badger\" is DEFINITELY NOT IN the filter as expected.\n\"cow\" is DEFINITELY NOT IN the filter as expected.\n\"pig\" is DEFINITELY NOT IN the filter as expected.\n\"sheep\" is DEFINITELY NOT IN the filter as expected.\n\"bee\" is DEFINITELY NOT IN the filter as expected.\n\"wolf\" is DEFINITELY NOT IN the filter as expected.\n\"fox\" is DEFINITELY NOT IN the filter as expected.\n\"whale\" is DEFINITELY NOT IN the filter as expected.\n\"shark\" is DEFINITELY NOT IN the filter as expected.\n\"fish\" is DEFINITELY NOT IN the filter as expected.\n\"turkey\" is DEFINITELY NOT IN the filter as expected.\n\"duck\" is DEFINITELY NOT IN the filter as expected.\n\"dove\" is DEFINITELY NOT IN the filter as expected.\n\"deer\" is DEFINITELY NOT IN the filter as expected.\n\"elephant\" is DEFINITELY NOT IN the filter as expected.\n\"frog\" is DEFINITELY NOT IN the filter as expected.\n\"falcon\" is DEFINITELY NOT IN the filter as expected.\n\"goat\" is DEFINITELY NOT IN the filter as expected.\n\"gorilla\" is DEFINITELY NOT IN the filter as expected.\n\"hawk\" is DEFINITELY NOT IN the filter as expected.\n```\n\n## License\n\nMIT\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dnanhkhoa/simple-bloom-filter", "keywords": "bloom-filter scalable-bloom-filter bloomfilter python-3 hashing algorithm data-structure", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "simplebloomfilter", "package_url": "https://pypi.org/project/simplebloomfilter/", "platform": "", "project_url": "https://pypi.org/project/simplebloomfilter/", "project_urls": { "Homepage": "https://github.com/dnanhkhoa/simple-bloom-filter" }, "release_url": "https://pypi.org/project/simplebloomfilter/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "A simple implementation of Bloom Filter and Scalable Bloom Filter for Python 3.", "version": "1.0.0" }, "last_serial": 4159359, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "bb425e512dc4d3786b4f3491bb936051", "sha256": "3611236e6a1b6d16033e413c205d2a00be96061e02109679eb517144f8f09137" }, "downloads": -1, "filename": "simplebloomfilter-1.0.0.tar.gz", "has_sig": false, "md5_digest": "bb425e512dc4d3786b4f3491bb936051", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4829, "upload_time": "2018-08-11T09:57:42", "url": "https://files.pythonhosted.org/packages/dc/6b/ec90026a1eb6f06f8d6e73c5a99e9710acf3949ef1a7770406c4925073b9/simplebloomfilter-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bb425e512dc4d3786b4f3491bb936051", "sha256": "3611236e6a1b6d16033e413c205d2a00be96061e02109679eb517144f8f09137" }, "downloads": -1, "filename": "simplebloomfilter-1.0.0.tar.gz", "has_sig": false, "md5_digest": "bb425e512dc4d3786b4f3491bb936051", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4829, "upload_time": "2018-08-11T09:57:42", "url": "https://files.pythonhosted.org/packages/dc/6b/ec90026a1eb6f06f8d6e73c5a99e9710acf3949ef1a7770406c4925073b9/simplebloomfilter-1.0.0.tar.gz" } ] }