private void AddObjectHolder(ObjectHolder holder)
{
Debug.Assert(holder != null, "holder!=null");
Debug.Assert(holder._id >= 0, "holder.m_id>=0");
//If the id that we need to place is greater than our current length, and less
//than the maximum allowable size of the array. We need to double the size
//of the array. If the array has already reached it's maximum allowable size,
//we chain elements off of the buckets.
if (holder._id >= _objects.Length && _objects.Length != MaxArraySize)
{
int newSize = MaxArraySize;
if (holder._id < (MaxArraySize / 2))
{
newSize = (_objects.Length * 2);
//Keep doubling until we're larger than our target size.
//We could also do this with log operations, but that would
//be slower than the brute force approach.
while (newSize <= holder._id && newSize < MaxArraySize)
{
newSize *= 2;
}
if (newSize > MaxArraySize)
{
newSize = MaxArraySize;
}
}
ObjectHolder[] temp = new ObjectHolder[newSize];
Array.Copy(_objects, 0, temp, 0, _objects.Length);
_objects = temp;
}
//Find the bin in which we live and make this new element the first element in the bin.
int index = (int)(holder._id & ArrayMask);
ObjectHolder tempHolder = _objects[index];
holder._next = tempHolder;
_objects[index] = holder;
}