MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / MinHash

Class MinHash

graphify/_minhash.py:36–49  ·  view source on GitHub ↗

MinHash sketch — same API as datasketch.MinHash for the subset used here.

Source from the content-addressed store, hash-verified

34
35
36class MinHash:
37 """MinHash sketch — same API as datasketch.MinHash for the subset used here."""
38
39 __slots__ = ("num_perm", "hashvalues", "_a", "_b")
40
41 def __init__(self, num_perm: int = 128) -> None:
42 self.num_perm = num_perm
43 self.hashvalues = np.full(num_perm, int(_MH), dtype=np.uint64)
44 self._a, self._b = _mh_coeffs(num_perm)
45
46 def update(self, v: bytes) -> None:
47 hv = np.uint64(struct.unpack("<I", hashlib.sha1(v).digest()[:4])[0])
48 phv = np.bitwise_and((self._a * hv + self._b) % _MP, _MH)
49 self.hashvalues = np.minimum(self.hashvalues, phv)
50
51
52def _lsh_integrate(f, lo: float, hi: float, n: int = 128) -> float:

Callers 3

_make_minhashFunction · 0.90
_minhash_forFunction · 0.90

Calls

no outgoing calls

Tested by 2

_minhash_forFunction · 0.72