C
cnb
Are dictionaries the same as hashtables?
Are dictionaries the same as hashtables?
Yes, but there is nothing in there that does sane collision handling
like making a list instead of simply overwriting.
PS: your sig was *a bit* longer than you question. please don't do
that...
signature.asc
< 1KViewDownload
Yes, but there is nothing in there that does sane collision handling
like making a list instead of simply overwriting.
Martin said:Yes, but there is nothing in there that does sane collision handling
like making a list instead of simply overwriting.
The term "collision" is rather well defined when talking about associative
arrays using hashing (which python's dicts are): it means that two distinct
keys produce the same hash-value, leading to a bucket collision. And of
course python deals with that sanely, and creates a list of objects inside
the bucket which is traversed and comparison is used to determine which
actual value to retrieve.
John said:I see neither buckets nor lists in the CPython svn trunk version of
dictobject.c and IIRC it's been using open addressing for a very long
time.
my what?
l = {}
l {}
l["a"] = 12
l["b"] = 13
l {'a': 12, 'b': 13}
l["a"] = "This is a collision"
l {'a': 'This is a collision', 'b': 13}
Martin said:Yes, but there is nothing in there that does sane collision handling
like making a list instead of simply overwriting.
Diez said:I don't know the exact names of the involved structures - I named them
liberally from my understanding of how associative arrays based on hashing
are implemented. But the below code shows that hash-collisions can occur
without corrupting data
Cameron said:.Martin said:On 2008-08-26 00:32:20, cnb wrote:
Are dictionaries the same as hashtables?
.
.
Python does not have a "one key maps to a list of values"-semantics -
which I consider the sane choice...
However, you can have that using the defaultdict for example:
listdict = defaultdict(list)
listdict[key].append(value)
Diez
? I'm lost. As I understand your terms, Python's dictionaries
map keys to objects, but you would prefer that Python's
dictionaries map keys only to lists of values. That *sounds*
like a complexification, at best. Are you trying to make a
point about implementation aligning with semantics?
are you sure you know what "collision handling" means in this context?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.