[Python-ideas] incremental hashing in __hash__
Chris Angelico
rosuav at gmail.com
Thu Dec 29 03:35:04 EST 2016
On Thu, Dec 29, 2016 at 7:20 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> I'd rather add a generator to the itertools
> module:
>
> itertools.iterhash(iterable) # yield incremental hashes
>
> or, copying the API of itertools.chain, add a method to hash:
>
> hash.from_iterable(iterable) # return hash calculated incrementally
The itertools module is mainly designed to be consumed lazily. The
hash has to be calculated eagerly, so it's not really a good fit for
itertools. The only real advantage of this "hash from iterable" over
hash(tuple(it)) is avoiding the intermediate tuple, so I'd want to see
evidence that that's actually significant.
ChrisA
More information about the Python-ideas
mailing list