public override void Add(T element)
{
int index = Interlocked.Increment(ref _index) - 1;
int adjustedIndex = index;
int arrayIndex = GetArrayIndex(index + 1);
if (arrayIndex > 0)
{
adjustedIndex -= Counts[arrayIndex - 1];
}
if (_array[arrayIndex] == null)
{
int arrayLength = Sizes[arrayIndex];
Interlocked.CompareExchange(ref _array[arrayIndex], new T[arrayLength], null);
}
_array[arrayIndex][adjustedIndex] = element;
int count = _count;
int fuzzyCount = Interlocked.Increment(ref _fuzzyCount);
if (fuzzyCount == index + 1)
{
Interlocked.CompareExchange(ref _count, fuzzyCount, count);
}
ItemAddedEvent?.Invoke(element, index);
}