On Mon, Oct 1, 2012 at 6:52 PM, Peter <pnau...@dataraker.com> wrote:
> Is there a hashtable implementation/library available to cython?
> I've found the map.pyx, but no hash-based implementations.
> Thanks :)
If you can't use Python dicts for some reason (e.g. need to hash lots
of small objects without "boxing" them), then khash is popular. Pandas
has cython code to wrap it.
> I've found the map.pyx, but no hash-based implementations.
In C++11, there is an std::unsorted_map which is hash-based (std::map is a BST). Similarly, std::unsorted_set is hash-based, whereas std::set is BST based. The interfaces are similar, so just copy the contents of map.pyx and replace "map" with "unsorted_map" (and ditto for set).
Also note that Pythons builtin dict and set are hash-based, but they can only store Python objects.
If you need to hash C or C++ objects, use C++11 STL or another C or C++ hash-implementation. You can of course convert a C object to a Python object, but it comes with a speed penalty.
> In C++11, there is an std::unsorted_map which is hash-based (std::map is
> a BST). Similarly, std::unsorted_set is hash-based, whereas std::set is
> BST based. The interfaces are similar, so just copy the contents of
> map.pyx and replace "map" with "unsorted_map" (and ditto for set).
Sorry, it's called "unordered_map", not "unsorted_map" :)
On Tuesday, October 2, 2012 8:22:32 AM UTC-4, sturlamolden wrote:
> On 02.10.2012 14:17, Sturla Molden wrote:
> > In C++11, there is an std::unsorted_map which is hash-based (std::map is > > a BST). Similarly, std::unsorted_set is hash-based, whereas std::set is > > BST based. The interfaces are similar, so just copy the contents of > > map.pyx and replace "map" with "unsorted_map" (and ditto for set).
> Sorry, it's called "unordered_map", not "unsorted_map" :)