Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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)
def _isdup(parsed_output, channel):
record_hash = hex(mmh3.hash(parsed_output))
if record_hash in PARSED_RECORDS[channel]:
return True
else:
PARSED_RECORDS[channel].add(record_hash)
return False
def get_postions(self, url):
# Get points positions in bit vector.
point1 = mmh3.hash(url, 41) % BIT_SIZE
point2 = mmh3.hash(url, 42) % BIT_SIZE
point3 = mmh3.hash(url, 43) % BIT_SIZE
point4 = mmh3.hash(url, 44) % BIT_SIZE
point5 = mmh3.hash(url, 45) % BIT_SIZE
point6 = mmh3.hash(url, 46) % BIT_SIZE
point7 = mmh3.hash(url, 47) % BIT_SIZE
return [point1, point2, point3, point4, point5, point6, point7]
def add(self,item):
for i in range(self.hash_count):
idx = mmh3.hash(item,i) % self.size
self.bits[idx]=1
return self
def __contains__(self,item):
def get_postions(self, url):
# Get points positions in bit vector.
point1 = mmh3.hash(url, 41) % BIT_SIZE
point2 = mmh3.hash(url, 42) % BIT_SIZE
point3 = mmh3.hash(url, 43) % BIT_SIZE
point4 = mmh3.hash(url, 44) % BIT_SIZE
point5 = mmh3.hash(url, 45) % BIT_SIZE
point6 = mmh3.hash(url, 46) % BIT_SIZE
point7 = mmh3.hash(url, 47) % BIT_SIZE
return [point1, point2, point3, point4, point5, point6, point7]
def mmh3_item(item, n):
return (2**32 + mmh3.hash(json.dumps(item))) % n
fn = np.vectorize(lambda t: mmh3.hash(normalize(t)), otypes=[np.uint32])
text_features[:,1] = fn(lab_token_text_features[:,1]) % model_settings.font_hash_size
essid=None,
tx=None,
intent=None):
# all arguments are required
assert not any([
location is None,
bssid is None,
channel is None,
essid is None,
tx is None,
intent is None,
])
# return dict from arguments
_id = str(mmh3.hash(''.join([ bssid, str(channel), intent])))
return {
'id' : _id,
'location' : location,
'bssid' : bssid,
'channel' : channel,
'tx' : tx,
'essid' : essid,
'intent' : intent,
'timestamp' : time.time(),
}