[Tutor] check against multiple variables
Steven D'Aprano
steve at pearwood.info
Fri Jul 20 12:06:16 CEST 2012
Walter Prins wrote:
> On 19 July 2012 23:20, Steven D'Aprano <steve at pearwood.info> wrote:
>> Selby Rowley-Cannon wrote:
>>> I am using a hash table in a small randomization program. I know that some
>>> hash functions can be prone to collisions, so I need a way to detect
>>> collisions.
>
>> This entire question seems like a remarkable case of premature optimization.
>> Start with demonstrating that collisions are an actual problem that need
>> fixing.
>
> Unless you know all the keys in advance and have consructed a proven
> perfect hash, potential collisions are something that *any* hash table
> implementation fundamentally *has* to deal with, no matter how small
> the probability of a collision. (If there's a non-zero probability of
> collision you *have* to deal with collisions.)
Absolutely. And did you think that Python, a 20 year old language which uses
dicts (hash tables) as a fundamental data structure for its own internals,
somehow neglected to do so? (A rhetorical question, I know you didn't :)
Naturally dictionaries (hash tables) deal with collisions. They couldn't work
if they didn't.
[...]
> But yes, rolling your own is not a good idea given highly optimized
> solutions already exist inside the Python language (dict) Except of
> course if you're studying hash tables as part of some course...
Ah, of course that would be an excellent reason for writing your own hash
table implementation! I didn't think of that at the time.
--
Steven
More information about the Tutor
mailing list