if ( !clear ){
Iterator it = map.values().iterator();
while( it.hasNext()){
entryDetails entry = (entryDetails)it.next();
// random guess: size of an entry is
// Object: 8
// Reference: 4*8
// entryDetails: 4
// Map.Entry: 2*8 + 4
// = say 90 bytes (testing shows 90 :))
// a String is 24 bytes + chars
final int overhead = 90;
final int str_size = 24 + entry.size;
if ( entry.hit_count * str_size < overhead ){
it.remove();
}
}
if ( map.size() > MAX_MAP_SIZE / 2 ){
// didn't compact enough, dump the whole thing and start again!
clear = true;
}
}
if ( clear ){
map = new WeakHashMap( MAX_MAP_SIZE );
}
/*
System.out.println( "trimmed down to " + map.size());
List l = new ArrayList(map.values());
Collections.sort(
l,
new Comparator()
{
public int
compare(
Object o1,
Object o2 )
{
entryDetails e1 = (entryDetails)o1;
entryDetails e2 = (entryDetails)o2;
return( e2.hit_count - e1.hit_count );
}
});
String line = "";
for (int i=0;i<Math.min( 128, l.size());i++){
entryDetails e = (entryDetails)l.get(i);
line += "\"" + e.get() + "\",";
if ( (i+1) % 8 == 0 ){
System.out.println( line );
line = "";
}
}
System.out.println( line );
*/