MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / __init__

Method __init__

join/LSH/datasketch/minhash.py:73–106  ·  view source on GitHub ↗
(self, num_perm=128, seed=1,
            hashfunc=sha1_hash32,
            hashobj=None, # Deprecated.
            hashvalues=None, permutations=None)

Source from the content-addressed store, hash-verified

71 '''
72
73 def __init__(self, num_perm=128, seed=1,
74 hashfunc=sha1_hash32,
75 hashobj=None, # Deprecated.
76 hashvalues=None, permutations=None):
77 # print("no")
78 if hashvalues is not None:
79 num_perm = len(hashvalues)
80 if num_perm > _hash_range:
81 # Because 1) we don't want the size to be too large, and
82 # 2) we are using 4 bytes to store the size value
83 raise ValueError("Cannot have more than %d number of\
84 permutation functions" % _hash_range)
85 self.seed = seed
86 self.num_perm = num_perm
87 # Check the hash function.
88 if not callable(hashfunc):
89 raise ValueError("The hashfunc must be a callable.")
90 self.hashfunc = hashfunc
91 # Check for use of hashobj and issue warning.
92 if hashobj is not None:
93 warnings.warn("hashobj is deprecated, use hashfunc instead.",
94 DeprecationWarning)
95 # Initialize hash values
96 if hashvalues is not None:
97 self.hashvalues = self._parse_hashvalues(hashvalues)
98 else:
99 self.hashvalues = self._init_hashvalues(num_perm)
100 # Initalize permutation function parameters
101 if permutations is not None:
102 self.permutations = permutations
103 else:
104 self.permutations = self._init_permutations(num_perm)
105 if len(self) != len(self.permutations[0]):
106 raise ValueError("Numbers of hash values and permutations mismatch")
107
108 def _init_hashvalues(self, num_perm):
109 return np.ones(num_perm, dtype=np.uint64)*_max_hash

Callers

nothing calls this directly

Calls 3

_parse_hashvaluesMethod · 0.95
_init_hashvaluesMethod · 0.95
_init_permutationsMethod · 0.95

Tested by

no test coverage detected