]> git.saurik.com Git - apple/javascriptcore.git/blob - wtf/HashTable.cpp
JavaScriptCore-466.1.6.tar.gz
[apple/javascriptcore.git] / wtf / HashTable.cpp
1 /*
2 This file is part of the KDE libraries
3
4 Copyright (C) 2005 Apple Computer
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20 */
21
22 #include "config.h"
23 #include "HashTable.h"
24
25 namespace WTF {
26
27 #if DUMP_HASHTABLE_STATS
28
29 int HashTableStats::numAccesses;
30 int HashTableStats::numCollisions;
31 int HashTableStats::collisionGraph[4096];
32 int HashTableStats::maxCollisions;
33 int HashTableStats::numRehashes;
34 int HashTableStats::numRemoves;
35 int HashTableStats::numReinserts;
36
37 static HashTableStats logger;
38
39 HashTableStats::~HashTableStats()
40 {
41 printf("\nkhtml::HashTable statistics\n\n");
42 printf("%d accesses\n", numAccesses);
43 printf("%d total collisions, average %.2f probes per access\n", numCollisions, 1.0 * (numAccesses + numCollisions) / numAccesses);
44 printf("longest collision chain: %d\n", maxCollisions);
45 for (int i = 1; i <= maxCollisions; i++) {
46 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);
47 }
48 printf("%d rehashes\n", numRehashes);
49 printf("%d reinserts\n", numReinserts);
50 }
51
52 void HashTableStats::recordCollisionAtCount(int count)
53 {
54 if (count > maxCollisions)
55 maxCollisions = count;
56 numCollisions++;
57 collisionGraph[count]++;
58 }
59
60 #endif
61
62 } // namespace WTF