|
|
|
|
|
by jpc0
610 days ago
|
|
A hash function will always be more expensive than a pointer lookup, specially concidering a pointer lookuo is still needed after the hash function. No matter what you do, a lookup into an array will always be quicker than a hash lookup if you don't need to do a linear search, even in a lot of cases the linear search will be quicker. Structs in other languages is a lookup of pointer + and offset. Which to my knowledge is also true in python classes using __slots__. There's no reason to use a dict if you know the contents of the data, use a dataclass with slots=True purely because there's no hash function run on every lookup into the datastructure. |
|