WTF
HashTable.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "HashTable.h"
00023 #include <config.h>
00024
00025 namespace WTF {
00026
00027 #if DUMP_HASHTABLE_STATS
00028
00029 int HashTableStats::numAccesses;
00030 int HashTableStats::numCollisions;
00031 int HashTableStats::collisionGraph[4096];
00032 int HashTableStats::maxCollisions;
00033 int HashTableStats::numRehashes;
00034 int HashTableStats::numRemoves;
00035 int HashTableStats::numReinserts;
00036
00037 static HashTableStats logger;
00038
00039 HashTableStats::~HashTableStats()
00040 {
00041 printf("\nkhtml::HashTable statistics\n\n");
00042 printf("%d accesses\n", numAccesses);
00043 printf("%d total collisions, average %.2f probes per access\n", numCollisions, 1.0 * (numAccesses + numCollisions) / numAccesses);
00044 printf("longest collision chain: %d\n", maxCollisions);
00045 for (int i = 1; i <= maxCollisions; i++) {
00046 printf(" %d lookups with exactly %d collisions (%.2f%% , %.2f%% with this many or more)\n", collisionGraph[i], i, 100.0 * (collisionGraph[i] - collisionGraph[i+1]) / numAccesses, 100.0 * collisionGraph[i] / numAccesses);
00047 }
00048 printf("%d rehashes\n", numRehashes);
00049 printf("%d reinserts\n", numReinserts);
00050 }
00051
00052 void HashTableStats::recordCollisionAtCount(int count)
00053 {
00054 if (count > maxCollisions)
00055 maxCollisions = count;
00056 numCollisions++;
00057 collisionGraph[count]++;
00058 }
00059
00060 #endif
00061
00062 }