When Python outruns C++ ...
Isaac To
kkto at csis.hku.hk
Tue Apr 1 08:02:39 EST 2003
>>>>> "Alex" == Alex Martelli <aleax at aleax.it> writes:
Alex> Julian Tibble wrote: ...
>> his C++ program, since I'm not sure I can write a better hash table
>> than the g++ STL developers.
Alex> I'm SURE you can write a hash-table that's a better hash-table
Alex> than C++'s std::map, because the latter CANNOT be a hash table --
Alex> it must rely on ordering of keys, and is normally a red-black
Alex> tree;-).
But g++ does provide a hash table, although not many people know it.
#include <iostream>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
int main() {
hash_map<long, int> hm;
for (int i = 0; i < 10000; ++i)
hm[i*i] = i;
for (int i = 0; i < 10000; ++i)
if (hm[i])
cout << i << ": " << hm[i] << endl;
}
Regards,
Isaac.
More information about the Python-list
mailing list