PythonHashesVsLists

From brainsik
Jump to navigation Jump to search

>How could a hash ever be faster than a straight table~x~y lookup?

Because lists are not arrays. table~x~y traverses one linked list to the x'th position, then traverses the list it just arrived at to the y'th possition. If you want a fast table, you should use an "array" object, see the array module. You could write some wrapper code to implement an efficient multidimentional array. Point being, python has no built in array syntax.

If you care, and have free time (ha====),try making larger and larger

==

tables, I presume it won't scale. hashtables scale well.

>>key = (i << 16) || j >I'm not following, what advantage does this get you?

The hashtable is going to have an easier time using an int as a key because comparisons are faster, and there is no need to create a tuple to contain the same info.

Frankly, this is all moot. Like I said, if you are concerned about speed, go to C. Python is slow, no one will claim otherwise.


Last Edit: Tue, 3 Sep 2002 21:12:22 -0700
Revisions: 1