Update this MinHash with a new value. The value will be hashed using the hash function specified by the `hashfunc` argument in the constructor. Args: b: The value to be hashed using the hash function specified. Example: To update with a new s
(self, b)
| 121 | return np.array(hashvalues, dtype=np.uint64) |
| 122 | |
| 123 | def update(self, b): |
| 124 | '''Update this MinHash with a new value. |
| 125 | The value will be hashed using the hash function specified by |
| 126 | the `hashfunc` argument in the constructor. |
| 127 | |
| 128 | Args: |
| 129 | b: The value to be hashed using the hash function specified. |
| 130 | |
| 131 | Example: |
| 132 | To update with a new string value (using the default SHA1 hash |
| 133 | function, which requires bytes as input): |
| 134 | |
| 135 | .. code-block:: python |
| 136 | |
| 137 | minhash = Minhash() |
| 138 | minhash.update("new value".encode('utf-8')) |
| 139 | |
| 140 | We can also use a different hash function, for example, `pyfarmhash`: |
| 141 | |
| 142 | .. code-block:: python |
| 143 | |
| 144 | import farmhash |
| 145 | def _hash_32(b): |
| 146 | return farmhash.hash32(b) |
| 147 | minhash = MinHash(hashfunc=_hash_32) |
| 148 | minhash.update("new value") |
| 149 | ''' |
| 150 | hv = self.hashfunc(b) |
| 151 | a, b = self.permutations |
| 152 | phv = np.bitwise_and((a * hv + b) % _mersenne_prime, _max_hash) |
| 153 | self.hashvalues = np.minimum(phv, self.hashvalues) |
| 154 | |
| 155 | def update_batch(self, b): |
| 156 | '''Update this MinHash with new values. |
no outgoing calls
no test coverage detected