private void RehashTable(bool ensureIntSpace)
{
if (keys != null)
{
// Check if removing deleted entries would free enough space
if (keyCount * 2 >= occupiedCount)
{
// Need to grow: less then half of deleted entries
++power;
}
}
int N = 1 << power;
int[] old = keys;
int oldShift = ivaluesShift;
if (oldShift == 0 && !ensureIntSpace)
{
keys = new int[N];
}
else
{
ivaluesShift = N;
keys = new int[N * 2];
}
for (int i = 0; i != N; ++i)
{
keys[i] = EMPTY;
}
object[] oldValues = values;
if (oldValues != null)
{
values = new object[N];
}
int oldCount = keyCount;
occupiedCount = 0;
if (oldCount != 0)
{
keyCount = 0;
for (int i_1 = 0, remaining = oldCount; remaining != 0; ++i_1)
{
int key = old[i_1];
if (key != EMPTY && key != DELETED)
{
int index = InsertNewKey(key);
if (oldValues != null)
{
values[index] = oldValues[i_1];
}
if (oldShift != 0)
{
keys[ivaluesShift + index] = old[oldShift + i_1];
}
--remaining;
}
}
}
}