|
|
Subscribe / Log in / New account

Python sets, frozensets, and literals

Python sets, frozensets, and literals

Posted Jan 20, 2022 1:47 UTC (Thu) by Wol (subscriber, #4433)
In reply to: Python sets, frozensets, and literals by NYKevin
Parent article: Python sets, frozensets, and literals

> Sure, if you happen to be working with strings you might want to make this assumption, but it is not generally required. You could just as easily assume that all strings are forcibly interned and pre-hashed at creation time, and then hashing really is O(1) because it's just a pointer deref to get the precomputed hash value.

And what is a string? JUST A BIG INTEGER!

The only datatype Pick has is string, but that's just what the user sees. Internally, I'm pretty certain it just treats the key as a large number, runs something like md5 over it, and then applies its hash function.

And then, given the hash, the time taken to access the target is constant. And much larger than computing the hash, in terms of total time that's just noise!

Cheers,
Wol


to post comments


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds