Compute MinHashes in a generator. This method avoids unnecessary overhead when initializing many minhashes by reusing the initialized state. Args: b (Iterable): An Iterable of lists of bytes, each list is hashed in to one MinHash in the output.
(cls, b, **minhash_kwargs)
| 318 | |
| 319 | @classmethod |
| 320 | def generator(cls, b, **minhash_kwargs): |
| 321 | '''Compute MinHashes in a generator. This method avoids unnecessary |
| 322 | overhead when initializing many minhashes by reusing the initialized |
| 323 | state. |
| 324 | |
| 325 | Args: |
| 326 | b (Iterable): An Iterable of lists of bytes, each list is |
| 327 | hashed in to one MinHash in the output. |
| 328 | minhash_kwargs: Keyword arguments used to initialize MinHash, |
| 329 | will be used for all minhashes. |
| 330 | |
| 331 | Returns: |
| 332 | A generator of computed MinHashes. |
| 333 | |
| 334 | Example: |
| 335 | |
| 336 | .. code-block:: python |
| 337 | |
| 338 | from datasketch import MinHash |
| 339 | data = [[b'token1', b'token2', b'token3'], |
| 340 | [b'token4', b'token5', b'token6']] |
| 341 | for minhash in MinHash.generator(data, num_perm=64): |
| 342 | # do something useful |
| 343 | minhash |
| 344 | |
| 345 | ''' |
| 346 | m = cls(**minhash_kwargs) |
| 347 | for _b in b: |
| 348 | _m = m.copy() |
| 349 | _m.update_batch(_b) |
| 350 | yield _m |
no test coverage detected