]>
git.saurik.com Git - apple/javascriptcore.git/blob - wtf/HashTable.cpp
2 This file is part of the KDE libraries
4 Copyright (C) 2005 Apple Computer
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.
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.
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.
23 #include "HashTable.h"
27 #if DUMP_HASHTABLE_STATS
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
;
37 static HashTableStats logger
;
39 HashTableStats ::~ HashTableStats ()
41 printf ( " \n khtml::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
);
48 printf ( " %d rehashes \n " , numRehashes
);
49 printf ( " %d reinserts \n " , numReinserts
);
52 void HashTableStats :: recordCollisionAtCount ( int count
)
54 if ( count
> maxCollisions
)
55 maxCollisions
= count
;
57 collisionGraph
[ count
]++;