File indexing completed on 2024-05-12 15:43:38

0001 /*
0002     Copyright (C) 2005 Apple Inc. All rights reserved.
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; either
0007     version 2 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include <wtf/HashTable.h>
0021 
0022 namespace WTF
0023 {
0024 
0025 #if DUMP_HASHTABLE_STATS
0026 
0027 int HashTableStats::numAccesses;
0028 int HashTableStats::numCollisions;
0029 int HashTableStats::collisionGraph[4096];
0030 int HashTableStats::maxCollisions;
0031 int HashTableStats::numRehashes;
0032 int HashTableStats::numRemoves;
0033 int HashTableStats::numReinserts;
0034 
0035 static HashTableStats logger;
0036 
0037 HashTableStats::~HashTableStats()
0038 {
0039     printf("\nkhtml::HashTable statistics\n\n");
0040     printf("%d accesses\n", numAccesses);
0041     printf("%d total collisions, average %.2f probes per access\n", numCollisions, 1.0 * (numAccesses + numCollisions) / numAccesses);
0042     printf("longest collision chain: %d\n", maxCollisions);
0043     for (int i = 1; i <= maxCollisions; i++) {
0044         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);
0045     }
0046     printf("%d rehashes\n", numRehashes);
0047     printf("%d reinserts\n", numReinserts);
0048 }
0049 
0050 void HashTableStats::recordCollisionAtCount(int count)
0051 {
0052     if (count > maxCollisions) {
0053         maxCollisions = count;
0054     }
0055     numCollisions++;
0056     collisionGraph[count]++;
0057 }
0058 
0059 #endif
0060 
0061 } // namespace WTF