Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for xxhash #38

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pybloom_live/benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/usr/bin/env python
#
"""Test performance of BloomFilter at a set capacity and error rate."""
import math
import sys
import time

import bitarray

from pybloom import BloomFilter
import bitarray, math, time
from utils import range_fn


Expand Down
14 changes: 9 additions & 5 deletions pybloom_live/pybloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
Requires the bitarray library: http://pypi.python.org/pypi/bitarray/
"""
from __future__ import absolute_import
import math
import hashlib

import copy
from pybloom_live.utils import range_fn, is_string_io, running_python_3
from struct import unpack, pack, calcsize
import hashlib
import math
from struct import calcsize, pack, unpack

import xxhash

from pybloom_live.utils import is_string_io, range_fn, running_python_3

try:
import bitarray
Expand All @@ -34,7 +38,7 @@ def make_hashfuncs(num_slices, num_bits):
elif total_hash_bits > 128:
hashfn = hashlib.sha1
else:
hashfn = hashlib.md5
hashfn = xxhash.xxh128

fmt = fmt_code * (hashfn().digest_size // chunk_size)
num_salts, extra = divmod(num_slices, len(fmt))
Expand Down
18 changes: 9 additions & 9 deletions pybloom_live/test_pybloom.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
from __future__ import absolute_import

from pybloom_live.pybloom import (BloomFilter, ScalableBloomFilter,
make_hashfuncs)
from pybloom_live.utils import running_python_3, range_fn
from pybloom_live.utils import range_fn, running_python_3

try:
import StringIO
import cStringIO
import StringIO
except ImportError:
pass

import io

import unittest
import random
import tempfile
import unittest

import pytest


class TestMakeHashFuncs(unittest.TestCase):
def test_make_hashfuncs_returns_hashfn(self):
make_hashes, hashfn = make_hashfuncs(100, 20)
self.assertEquals('openssl_sha512', hashfn.__name__)
self.assertEqual('openssl_sha512', hashfn.__name__)
make_hashes, hashfn = make_hashfuncs(20, 3)
self.assertEquals('openssl_sha384', hashfn.__name__)
self.assertEqual('openssl_sha384', hashfn.__name__)
make_hashes, hashfn = make_hashfuncs(15, 2)
self.assertEquals('openssl_sha256', hashfn.__name__)
self.assertEqual('openssl_sha256', hashfn.__name__)
make_hashes, hashfn = make_hashfuncs(10, 2)
self.assertEquals('openssl_sha1', hashfn.__name__)
self.assertEqual('openssl_sha1', hashfn.__name__)
make_hashes, hashfn = make_hashfuncs(5, 1)
self.assertEquals('openssl_md5', hashfn.__name__)
self.assertEqual('xxh3_128', hashfn.__name__)


class TestUnionIntersection(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bitarray>=0.3.4
bitarray>=0.3.4
xxhash>=3.0.0