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_hash64():
assert mmh3.hash64('foo') == (-2129773440516405919, 9128664383759220103)
assert mmh3.hash64('foo', signed = False) == (16316970633193145697,
9128664383759220103)
# TODO
def _indexes(self, key):
for i in xrange(self.num_hashes):
h1, h2 = mmh3.hash64(key)
yield (h1 + i * h2) % self.num_bytes_per_hash + i*self.num_bytes_per_hash
def _indexes(self, key):
"""
Generates the indicies corresponding to the given key
"""
h1, h2 = mmh3.hash64(key)
for i in xrange(self.num_hashes):
yield (h1 + i * h2) % self.num_bytes
def _idxiter(self, key):
k1, k2 = mmh3.hash64(key)
for i in range(self.N):
idx = (k1 + i * k2) % self.size
yield idx
def compute_sql_signature(query):
"""
Given a raw SQL query or prepared statement, generate a 64-bit hex signature
on the normalized query.
"""
normalized = datadog_agent.obfuscate_sql(query)
return format(mmh3.hash64(normalized, signed=False)[0], 'x')
def compute_exec_plan_signature(json_plan):
"""
Given a query execution plan, generate a 64-bit hex signature on the normalized execution plan
"""
if not json_plan:
return None, None
normalized_json = datadog_agent.obfuscate_sql_exec_plan(json_plan, normalize=True)
with_sorted_keys = json.dumps(json.loads(normalized_json), sort_keys=True)
return normalized_json, format(mmh3.hash64(with_sorted_keys, signed=False)[0], 'x')
def triple_hash(self, item):
'''Returns a triple i, val, aug hashed values, where i is bucketbits,
val is the position of the leading one in a 64-bit integer, and aug is the bits
to go in the subbuckets'''
y, h2 = mmh3.hash64(str(item).encode())
val = 64 + 1 - int(np.uint64(y)).bit_length()
val = min(val, 2**self.bucketsize)
h2prime = int(np.uint64(h2))
i = h2prime >> self._bucketbit_shift
aug = h2prime & self._bbit_mask
return (i, val, aug)
def compute_sql_signature(query):
"""
Given a raw SQL query or prepared statement, generate a 64-bit hex signature
on the normalized query.
"""
normalized = datadog_agent.obfuscate_sql(query)
return format(mmh3.hash64(normalized, signed=False)[0], 'x')
def hash64(key, seed):
"""
Wrapper around mmh3.hash64 to get us single 64-bit value.
This also does the extra work of ensuring that we always treat the
returned values as big-endian unsigned long, like smhasher used to
do.
"""
hash_val = mmh3.hash64(key, seed)[0]
return struct.unpack('>Q', struct.pack('q', hash_val))[0]