Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

absolute fastest lookup in python / cython

I'd like to do a lookup mapping 32bit integer => 32bit integer.

The input keys aren't necessary contiguous nor cover 2^32 -1 (nor do I want this in-memory to consume that much space!).

The use case is for a poker evaluator, so doing a lookup must be as fast as possible. Perfect hashing would be nice, but that might be a bit out of scope.

I feel like the answer is some kind of cython solution, but I'm not sure about the underpinnings of cython and if it really does any good with Python's dict() type. Of course a flat array with just a simple offset jump would be super fast, but then I'm allocating 2^32 - 1 places in memory for the table, which I don't want.

Any tips / strategies? Absolute speed with minimal memory footprint is the goal.

like image 617
lollercoaster Avatar asked Dec 11 '22 04:12

lollercoaster


1 Answers

You aren't smart enough to write something faster than dict. Don't feel bad; 99.99999% of the people on the planet aren't. Use a dict.

like image 55
Ignacio Vazquez-Abrams Avatar answered Dec 30 '22 09:12

Ignacio Vazquez-Abrams