digitalmars.D.learn - What wrong did i do? (key in hashtable is always null)
- The Anh Tran (17/17) Dec 30 2009 This is just a small D exercise. I port c++ knucleotide from
- bearophile (9/11) Dec 30 2009 This was my version, maybe it solves some of your problems:
- The Anh Tran (9/20) Dec 31 2009 Thanks for pointing out code format style. :)
- grauzone (4/28) Dec 31 2009 Is your opCmp/toHash really called? Maybe the function signature is off,...
- The Anh Tran (6/9) Dec 31 2009 toHash + opCmp are called.
This is just a small D exercise. I port c++ knucleotide from shootout.alioth.debian.org Issue 1: If i manually listing hashtable contents, the key does exist in that ht. But (key in hash_table) always yield null. Worse, if i use: "auto val = ht[key]", an exception is thrown. Problem code is from line 163 to 177. Issue 2: If I pass an AA (uint[ulong]) to a template function. DMD complains that uint[ulong] is void. How can i get the type of AA? DMD 2.037. Linux Ubuntu. Source code: ftp://ftp.4utours.com/dualamd/Dlang/knu5.d Sample data: ftp://ftp.4utours.com/dualamd/Dlang/fa50k.txt Thanks.
Dec 30 2009
The Anh Tran:This is just a small D exercise. I port c++ knucleotide from shootout.alioth.debian.orgThis was my version, maybe it solves some of your problems: http://shootout.alioth.debian.org/debian/benchmark.php?test=knucleotide&lang=gdc&id=2 I haven't used my dlibs here, so for example that sort in the middle is long and ugly (and not fully correct, that opCmp doesn't compare accordingly both key and value, as the problem specs state: "sorted by descending frequency and then ascending k-nucleotide key"), in Python it becomes: l = sorted(frequences.items(), reverse=True, key=lambda (seq,freq): (freq,seq)) With my dlibs it's similar. You can probably do something similar with Phobos2. By the way, the formatting of your code needs improvements, reduce indentation length and format code in a more readable way. Bye, bearophile
Dec 30 2009
bearophile wrote:This was my version, maybe it solves some of your problems: http://shootout.alioth.debian.org/debian/benchmark.php?test=knucleotide&lang=gdc&id=2 I haven't used my dlibs here, so for example that sort in the middle is long and ugly (and not fully correct, that opCmp doesn't compare accordingly both key and value, as the problem specs state: "sorted by descending frequency and then ascending k-nucleotide key"), in Python it becomes: l = sorted(frequences.items(), reverse=True, key=lambda (seq,freq): (freq,seq)) With my dlibs it's similar. You can probably do something similar with Phobos2. By the way, the formatting of your code needs improvements, reduce indentation length and format code in a more readable way. Bye, bearophileThanks for pointing out code format style. :) Shootout site stop benching D lang => why wasting time in formating code for someone else. I just curious in D's AA perf compared to C++ pb_ds::cc_hash_table. The newest C++ knucleotide using uint64 as key, not char[] anymore. In my small test case, D's built-in AA has the same perf as C glib. That's 4-5 times slower that pb_ds::cc_hash_table. Moreover, i think that it has bug -.-
Dec 31 2009
The Anh Tran wrote:This is just a small D exercise. I port c++ knucleotide from shootout.alioth.debian.org Issue 1: If i manually listing hashtable contents, the key does exist in that ht. But (key in hash_table) always yield null. Worse, if i use: "auto val = ht[key]", an exception is thrown. Problem code is from line 163 to 177. Issue 2: If I pass an AA (uint[ulong]) to a template function. DMD complains that uint[ulong] is void. How can i get the type of AA? DMD 2.037. Linux Ubuntu. Source code: ftp://ftp.4utours.com/dualamd/Dlang/knu5.dIs your opCmp/toHash really called? Maybe the function signature is off, and dmd doesn't "find" the function. Just a guess, I don't really know how this D2 stuff works.Sample data: ftp://ftp.4utours.com/dualamd/Dlang/fa50k.txt Thanks.
Dec 31 2009
grauzone wrote:Is your opCmp/toHash really called? Maybe the function signature is off, and dmd doesn't "find" the function. Just a guess, I don't really know how this D2 stuff works.toHash + opCmp are called. The awkward is that, most of those functions are copied & pasted from C. They work perfectly. I suspect that it is a bug. I would like to know if someone else meet the same problem.
Dec 31 2009