A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-August/037418.html below:

[Python-Dev] Caching tuple hashes

[Python-Dev] Caching tuple hashes [Python-Dev] Caching tuple hashesAndrew Bennetts andrew-pythondev at puzzling.org
Mon Aug 4 19:14:15 EDT 2003
On Mon, Aug 04, 2003 at 02:51:29AM -0400, Raymond Hettinger wrote:
> Strings save their hash values to avoid recomputation in subsequent
> hashings.  In contrast, tuples recompute on every call.   I've googled
> around and cannot find the rationale for this.  Some ideas are:
> 
> * the time to initialize and check the hash fields isn't repaid on average
> * it isn't worth an extra structure field for storing the hash value
> * C code can mutate immutables so there is a safety risk
> * nobody ever thought of it (unlikely) or got around to it (more likely).

Perhaps this:

* Tuples can contain badly-behaved mutables, e.g.:

>>> class X:
...     x = 1       
...     def __hash__(self):    
...         return self.x 
... 
>>> x = X()
>>> t = (x,)
>>> hash(t)
-1660579480
>>> X.x = 2
>>> hash(t)
-1660579477

-Andrew.


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4