WTF
HashTable.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2005 Apple Inc. All rights reserved. 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "config.h" 00021 #include "HashTable.h" 00022 00023 namespace WTF { 00024 00025 #if DUMP_HASHTABLE_STATS 00026 00027 int HashTableStats::numAccesses; 00028 int HashTableStats::numCollisions; 00029 int HashTableStats::collisionGraph[4096]; 00030 int HashTableStats::maxCollisions; 00031 int HashTableStats::numRehashes; 00032 int HashTableStats::numRemoves; 00033 int HashTableStats::numReinserts; 00034 00035 static HashTableStats logger; 00036 00037 HashTableStats::~HashTableStats() 00038 { 00039 printf("\nkhtml::HashTable statistics\n\n"); 00040 printf("%d accesses\n", numAccesses); 00041 printf("%d total collisions, average %.2f probes per access\n", numCollisions, 1.0 * (numAccesses + numCollisions) / numAccesses); 00042 printf("longest collision chain: %d\n", maxCollisions); 00043 for (int i = 1; i <= maxCollisions; i++) { 00044 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); 00045 } 00046 printf("%d rehashes\n", numRehashes); 00047 printf("%d reinserts\n", numReinserts); 00048 } 00049 00050 void HashTableStats::recordCollisionAtCount(int count) 00051 { 00052 if (count > maxCollisions) 00053 maxCollisions = count; 00054 numCollisions++; 00055 collisionGraph[count]++; 00056 } 00057 00058 #endif 00059 00060 } // namespace WTF
KDE 4.6 API Reference