| 299 | |
| 300 | # 对第b个hashtable做冲突判断 |
| 301 | def _query_b(self, minhash, b): |
| 302 | if len(minhash) != self.h: |
| 303 | raise ValueError("Expecting minhash with length %d, got %d" |
| 304 | % (self.h, len(minhash))) |
| 305 | if b > len(self.hashtables): |
| 306 | raise ValueError("b must be less or equal to the number of hash tables") |
| 307 | candidates = set() |
| 308 | for (start, end), hashtable in zip(self.hashranges[:b], self.hashtables[:b]): |
| 309 | H = self._H(minhash.hashvalues[start:end]) |
| 310 | if H in hashtable: |
| 311 | for key in hashtable[H]: |
| 312 | candidates.add(key) |
| 313 | if self.prepickle: |
| 314 | return {pickle.loads(key) for key in candidates} |
| 315 | else: |
| 316 | return candidates |
| 317 | |
| 318 | def get_counts(self): |
| 319 | ''' |