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

Method __init__

join/LSH/datasketch/lsh.py:92–130  ·  view source on GitHub ↗
(self, threshold=0.9, num_perm=128, weights=(0.5, 0.5),
                 params=None, storage_config=None, prepickle=None, hashfunc=None)

Source from the content-addressed store, hash-verified

90 '''
91
92 def __init__(self, threshold=0.9, num_perm=128, weights=(0.5, 0.5),
93 params=None, storage_config=None, prepickle=None, hashfunc=None):
94 storage_config = {'type': 'dict'} if not storage_config else storage_config
95 self._buffer_size = 50000
96 if threshold > 1.0 or threshold < 0.0:
97 raise ValueError("threshold must be in [0.0, 1.0]")
98 if num_perm < 2:
99 raise ValueError("Too few permutation functions")
100 if any(w < 0.0 or w > 1.0 for w in weights):
101 raise ValueError("Weight must be in [0.0, 1.0]")
102 if sum(weights) != 1.0:
103 raise ValueError("Weights must sum to 1.0")
104 self.h = num_perm
105 if params is not None:
106 self.b, self.r = params
107 if self.b * self.r > num_perm:
108 raise ValueError("The product of b and r in params is "
109 "{} * {} = {} -- it must be less than num_perm {}. "
110 "Did you forget to specify num_perm?".format(
111 self.b, self.r, self.b*self.r, num_perm))
112 else:
113 false_positive_weight, false_negative_weight = weights
114 self.b, self.r = _optimal_param(threshold, num_perm,
115 false_positive_weight, false_negative_weight)
116
117 self.prepickle = storage_config['type'] == 'redis' if prepickle is None else prepickle
118
119 self.hashfunc = hashfunc
120 if hashfunc:
121 self._H = self._hashed_byteswap
122 else:
123 self._H = self._byteswap
124
125 basename = storage_config.get('basename', _random_name(11))
126 self.hashtables = [
127 unordered_storage(storage_config, name=b''.join([basename, b'_bucket_', struct.pack('>H', i)]))
128 for i in range(self.b)]
129 self.hashranges = [(i*self.r, (i+1)*self.r) for i in range(self.b)]
130 # self.keys = ordered_storage(storage_config, name=b''.join([basename, b'_keys']))
131
132 @property
133 def buffer_size(self):

Callers

nothing calls this directly

Calls 4

_random_nameFunction · 0.90
unordered_storageFunction · 0.90
_optimal_paramFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected