(self, threshold=0.9, num_perm=128, weights=(0.5, 0.5),
params=None, storage_config=None, prepickle=None, hashfunc=None)
| 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): |
nothing calls this directly
no test coverage detected