How to use mmh3 - 10 common examples

To help you get started, we’ve selected a few mmh3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hajimes / mmh3 / test_mmh3.py View on Github external
def test_hash_unsigned():
    assert mmh3.hash('foo', signed = False) == 4138058784

    # Several test vectors devised by Ian Boyd
    # https://stackoverflow.com/a/31929528
    assert mmh3.hash(b'', seed=0, signed = False) == 0
    assert mmh3.hash(b'', seed=1, signed = False) == 0x514E28B7
    assert mmh3.hash(b'', seed=0xffffffff, signed = False) == 0x81F16F39
    assert mmh3.hash(b'\x21\x43\x65\x87', 0, signed = False) == 0xF55B516B
    assert mmh3.hash(b'\x21\x43\x65\x87',
        0x5082EDEE, signed = False) == 0x2362F9DE
    assert mmh3.hash(b'\x21\x43\x65', 0, signed = False) == 0x7E4A8634
    assert mmh3.hash(b'\x21\x43', 0, signed = False) == 0xA0F7B07A
    assert mmh3.hash(b'\x21', 0, signed = False) == 0x72661CF4
    assert mmh3.hash(b'\xff\xff\xff\xff', 0, signed = False) == 0x76293B50
    assert mmh3.hash(b'\x00\x00\x00\x00', 0, signed = False) == 0x2362F9DE
    assert mmh3.hash(b'\x00\x00\x00', 0, signed = False) == 0x85F0B427
    assert mmh3.hash(b'\x00\x00', 0, signed = False) == 0x30F4C306
    assert mmh3.hash(b'\x00', 0, signed = False) == 0x514E28B7
    
    assert mmh3.hash('aaaa', 0x9747b28c, signed = False) == 0x5A97808A
    assert mmh3.hash('aaa', 0x9747b28c, signed = False) == 0x283E0130
    assert mmh3.hash('aa', 0x9747b28c, signed = False) == 0x5D211726
    assert mmh3.hash('a', 0x9747b28c, signed = False) == 0x7FA09EA6

    assert mmh3.hash('abcd', 0x9747b28c, signed = False) == 0xF0478627
    assert mmh3.hash('abc', 0x9747b28c, signed = False) == 0xC84A62DD
    assert mmh3.hash('ab', 0x9747b28c, signed = False) == 0x74875592
github hajimes / mmh3 / test_mmh3.py View on Github external
assert mmh3.hash(b'', seed=0, signed = False) == 0
    assert mmh3.hash(b'', seed=1, signed = False) == 0x514E28B7
    assert mmh3.hash(b'', seed=0xffffffff, signed = False) == 0x81F16F39
    assert mmh3.hash(b'\x21\x43\x65\x87', 0, signed = False) == 0xF55B516B
    assert mmh3.hash(b'\x21\x43\x65\x87',
        0x5082EDEE, signed = False) == 0x2362F9DE
    assert mmh3.hash(b'\x21\x43\x65', 0, signed = False) == 0x7E4A8634
    assert mmh3.hash(b'\x21\x43', 0, signed = False) == 0xA0F7B07A
    assert mmh3.hash(b'\x21', 0, signed = False) == 0x72661CF4
    assert mmh3.hash(b'\xff\xff\xff\xff', 0, signed = False) == 0x76293B50
    assert mmh3.hash(b'\x00\x00\x00\x00', 0, signed = False) == 0x2362F9DE
    assert mmh3.hash(b'\x00\x00\x00', 0, signed = False) == 0x85F0B427
    assert mmh3.hash(b'\x00\x00', 0, signed = False) == 0x30F4C306
    assert mmh3.hash(b'\x00', 0, signed = False) == 0x514E28B7
    
    assert mmh3.hash('aaaa', 0x9747b28c, signed = False) == 0x5A97808A
    assert mmh3.hash('aaa', 0x9747b28c, signed = False) == 0x283E0130
    assert mmh3.hash('aa', 0x9747b28c, signed = False) == 0x5D211726
    assert mmh3.hash('a', 0x9747b28c, signed = False) == 0x7FA09EA6

    assert mmh3.hash('abcd', 0x9747b28c, signed = False) == 0xF0478627
    assert mmh3.hash('abc', 0x9747b28c, signed = False) == 0xC84A62DD
    assert mmh3.hash('ab', 0x9747b28c, signed = False) == 0x74875592
    assert mmh3.hash('a', 0x9747b28c, signed = False) == 0x7FA09EA6

    assert mmh3.hash('Hello, world!',
        0x9747b28c, signed = False) == 0x24884CBA
    
    assert mmh3.hash(u'ππππππππ'.encode('utf-8'),
        0x9747b28c, signed = False) == 0xD58063C1
        
    assert mmh3.hash('a'*256, 0x9747b28c, signed = False) == 0x37405BDC
github hajimes / mmh3 / test_mmh3.py View on Github external
assert mmh3.hash(b'\x21\x43', 0) == u32_to_s32(0xA0F7B07A)
    assert mmh3.hash(b'\x21', 0) == u32_to_s32(0x72661CF4)
    assert mmh3.hash(b'\xff\xff\xff\xff', 0) == u32_to_s32(0x76293B50)
    assert mmh3.hash(b'\x00\x00\x00\x00', 0) == u32_to_s32(0x2362F9DE)
    assert mmh3.hash(b'\x00\x00\x00', 0) == u32_to_s32(0x85F0B427)
    assert mmh3.hash(b'\x00\x00', 0) == u32_to_s32(0x30F4C306)
    assert mmh3.hash(b'\x00', 0) == u32_to_s32(0x514E28B7)
    
    assert mmh3.hash('aaaa', 0x9747b28c) == u32_to_s32(0x5A97808A)
    assert mmh3.hash('aaa', 0x9747b28c) == u32_to_s32(0x283E0130)
    assert mmh3.hash('aa', 0x9747b28c) == u32_to_s32(0x5D211726)
    assert mmh3.hash('a', 0x9747b28c) == u32_to_s32(0x7FA09EA6)

    assert mmh3.hash('abcd', 0x9747b28c) == u32_to_s32(0xF0478627)
    assert mmh3.hash('abc', 0x9747b28c) == u32_to_s32(0xC84A62DD)
    assert mmh3.hash('ab', 0x9747b28c) == u32_to_s32(0x74875592)
    assert mmh3.hash('a', 0x9747b28c) == u32_to_s32(0x7FA09EA6)

    assert mmh3.hash('Hello, world!', 0x9747b28c) == u32_to_s32(0x24884CBA)
    
    assert mmh3.hash(u'ππππππππ'.encode('utf-8'),
        0x9747b28c) == u32_to_s32(0xD58063C1)
        
    assert mmh3.hash('a'*256, 0x9747b28c) == u32_to_s32(0x37405BDC)

    assert mmh3.hash('abc', 0) == u32_to_s32(0xB3DD93FA)
    assert mmh3.hash('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq',
        0) == u32_to_s32(0xEE925B90)

    assert mmh3.hash('The quick brown fox jumps over the lazy dog',
        0x9747b28c) == u32_to_s32(0x2FA826CD)
github hajimes / mmh3 / test_mmh3.py View on Github external
def test_hash64():
    assert mmh3.hash64('foo') == (-2129773440516405919, 9128664383759220103)
    assert mmh3.hash64('foo', signed = False) == (16316970633193145697,
        9128664383759220103)
    # TODO
github huydhn / cuckoo-filter / tests / test_bucket.py View on Github external
'transformer': lambda string: str(int(IPAddress(string))),

                'action': bucket.delete,
                'expected': True,

                'full': False,
                'included': False,
            },
        ]

        for case in cases:
            item = case['transformer'](case['item'])

            # Generate all the fingerprints
            fingerprint = bitarray()
            fingerprint.frombytes(mmh3.hash_bytes(item))

            self.assertEqual(case['action'](fingerprint), case['expected'], 'Save {0} into the bucket ok'.format(item))
            self.assertEqual(bucket.is_full(), case['full'], 'Bucket capacity is ok')

            # Make sure that all items are in the bucket
            self.assertEqual(bucket.contains(fingerprint), case['included'], 'Item {0} is in the bucket'.format(item))
            self.assertEqual(fingerprint in bucket, case['included'], 'Item {0} is in the bucket'.format(item))
github hajimes / mmh3 / test_mmh3.py View on Github external
def test_hash128():
    assert mmh3.hash128('foo') == 168394135621993849475852668931176482145
    assert mmh3.hash128('foo', 42) == 215966891540331383248189432718888555506
    assert mmh3.hash128('foo', 42, signed = False) == 215966891540331383248189432718888555506
    assert mmh3.hash128('foo', 42, signed = True) == -124315475380607080215185174712879655950
    # TODO
github hajimes / mmh3 / test_mmh3.py View on Github external
def test_hash128():
    assert mmh3.hash128('foo') == 168394135621993849475852668931176482145
    assert mmh3.hash128('foo', 42) == 215966891540331383248189432718888555506
    assert mmh3.hash128('foo', 42, signed = False) == 215966891540331383248189432718888555506
    assert mmh3.hash128('foo', 42, signed = True) == -124315475380607080215185174712879655950
    # TODO
github hajimes / mmh3 / test_mmh3.py View on Github external
def test_hash128():
    assert mmh3.hash128('foo') == 168394135621993849475852668931176482145
    assert mmh3.hash128('foo', 42) == 215966891540331383248189432718888555506
    assert mmh3.hash128('foo', 42, signed = False) == 215966891540331383248189432718888555506
    assert mmh3.hash128('foo', 42, signed = True) == -124315475380607080215185174712879655950
    # TODO
github hajimes / mmh3 / test_mmh3.py View on Github external
def test_hash128():
    assert mmh3.hash128('foo') == 168394135621993849475852668931176482145
    assert mmh3.hash128('foo', 42) == 215966891540331383248189432718888555506
    assert mmh3.hash128('foo', 42, signed = False) == 215966891540331383248189432718888555506
    assert mmh3.hash128('foo', 42, signed = True) == -124315475380607080215185174712879655950
    # TODO
github hajimes / mmh3 / test_mmh3.py View on Github external
def test_hash_from_buffer():
    mview = memoryview('foo'.encode('utf8'))
    assert mmh3.hash_from_buffer(mview) == -156908512
    assert mmh3.hash_from_buffer(mview, signed = False) == 4138058784

mmh3

Python extension for MurmurHash (MurmurHash3), a set of fast and robust hash functions.

MIT
Latest version published 7 months ago

Package Health Score

82 / 100
Full package analysis

Similar packages