Python dictionary inspired hash table implementation

bearophile bearophileHUGS at lycos.com
Wed Jul 2 14:11:43 PDT 2008


Moritz Warning Wrote:
> E.g., it is twice as slow for lookups of ulong keys compared to Tango HashMap
> (3 times slower for insertion). It's also slower for arrays.
> But that's likely to change with some more tweaking.

I think it may need more than just tweakings: the advantage of not using pointers may get lost when the data is too much long. So you may switch to using pointers when the data requires more than 4 or 8 bytes.


How much work does it need to be ported to Phobos?


Instead of this:
import tango.stdc.string; //for memset
You probably want to write something like:
import tango.stdc.string: memset;


I suggest you to compact the code vertically some, to improve readability.


This may enjoy a better name:
template Helper(T)
In my libs I have named it DeconstArrayType.


If you have a Python, like a 2.5, you may try it with similar code, to compare the speeds. The simpler code you may try are (in pairs):

def main():
    d = {}
    for i in xrange(500000):
        d["key_" + str(i)] = 0
import psyco; psyco.bind(main)
main()


import std.string: format;
void main() {
    int[string] d;
    for (int i = 0; i < 500_000; ++i)
        d["key_" ~ format(i)] = 0;
}



def main():
    d = dict.fromkeys(xrange(10000000), 0)
main()



void main() {
    int[int] d;
    for (int i; i < 10_000_000; ++i)
        d[i] = 0;
}

Bye,
bearophile



More information about the Digitalmars-d mailing list