Always rotate tables if new table exceeds threshold.

This commit is contained in:
hns 2002-10-30 11:46:51 +00:00
parent dba715b2db
commit 6266b3b5b7

View file

@ -231,14 +231,15 @@ public class CacheMap {
oldValue = oldTable.get (key); oldValue = oldTable.get (key);
if (oldValue != null) if (oldValue != null)
oldTable.remove( key ); oldTable.remove( key );
else { // we put a key into newtable that wasn't there before. check if it
if (newTable.size() >= threshold) { // grew beyond the threshold
// Rotate the tables. if (newTable.size() >= threshold) {
if (logger != null) // Rotate the tables.
logger.log ("Rotating Cache tables at "+newTable.size()+"/"+oldTable.size()+" (new/old)"); if (logger != null)
oldTable = newTable; logger.log ("Rotating Cache tables at "+newTable.size()+
newTable = new HashMap (eachCapacity, loadFactor); "/"+oldTable.size()+" (new/old)");
} oldTable = newTable;
newTable = new HashMap (eachCapacity, loadFactor);
} }
return oldValue; return oldValue;
} }