protected void Rebalance() {
#if BRUNET_DEBUG
Console.Error.WriteLine("Rebalance");
#endif
int new_expon = _expon;
if( ( ( 2 * _count ) > _size ) ) {
//On average, there is more than one element in every 2 bins.
//go up by a factor of 8 in size
new_expon += 3;
}
else if( (8 * _count) < _size ) {
//On average there are more than 8 bins per object
new_expon -= 1;
if( new_expon < _MIN_EXP ) {
//Don't let the exponent get too low
new_expon = _MIN_EXP;
}
}
if( new_expon != _expon ) {
#if BRUNET_DEBUG
Console.Error.WriteLine("Rebalance: go");
#endif
ArrayList all_elements = new ArrayList();
foreach(IList l in _table) {
if( l != null ) {
all_elements.AddRange(l);
}
}
//Add all the elements into the reseted table
Init(new_expon);
for(int i = 0; i < all_elements.Count; i++) {
Element e = (Element)all_elements[i];
object key = e.Key;
if( key != null ) {
//Make sure the key doesn't disappear until it is added
//Make sure not to rebalance which could put us into a loop
//Also make sure we don't add the same key twice
this.Add(key, e.Value, false, false);
}
}
}
}
#if BRUNET_NUNIT