Collections de/increment operations fix
This one is more stylistic but is consistent with practice of using pre- operations for iterators.
This commit is contained in:
@@ -482,7 +482,7 @@ public:
|
||||
{
|
||||
EnsureCapacity(_count + 1);
|
||||
Memory::ConstructItems(_allocation.Get() + _count, &item, 1);
|
||||
_count++;
|
||||
++_count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -493,7 +493,7 @@ public:
|
||||
{
|
||||
EnsureCapacity(_count + 1);
|
||||
Memory::MoveItems(_allocation.Get() + _count, &item, 1);
|
||||
_count++;
|
||||
++_count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -557,7 +557,7 @@ public:
|
||||
{
|
||||
EnsureCapacity(_count + 1);
|
||||
Memory::ConstructItems(_allocation.Get() + _count, 1);
|
||||
_count++;
|
||||
++_count;
|
||||
return _allocation.Get()[_count - 1];
|
||||
}
|
||||
|
||||
@@ -605,7 +605,7 @@ public:
|
||||
Memory::ConstructItems(data + _count, 1);
|
||||
for (int32 i = _count - 1; i >= index; i--)
|
||||
data[i + 1] = MoveTemp(data[i]);
|
||||
_count++;
|
||||
++_count;
|
||||
data[index] = MoveTemp(item);
|
||||
}
|
||||
|
||||
@@ -621,7 +621,7 @@ public:
|
||||
Memory::ConstructItems(data + _count, 1);
|
||||
for (int32 i = _count - 1; i >= index; i--)
|
||||
data[i + 1] = data[i];
|
||||
_count++;
|
||||
++_count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -661,7 +661,7 @@ public:
|
||||
/// <param name="item">The item to remove.</param>
|
||||
void RemoveAllKeepOrder(const T& item)
|
||||
{
|
||||
for (int32 i = Count() - 1; i >= 0; i--)
|
||||
for (int32 i = Count() - 1; i >= 0; --i)
|
||||
{
|
||||
if (_allocation.Get()[i] == item)
|
||||
{
|
||||
@@ -679,14 +679,14 @@ public:
|
||||
void RemoveAtKeepOrder(const int32 index)
|
||||
{
|
||||
ASSERT(index < _count && index >= 0);
|
||||
_count--;
|
||||
--_count;
|
||||
T* data = _allocation.Get();
|
||||
if (index < _count)
|
||||
{
|
||||
T* dst = data + index;
|
||||
T* src = data + (index + 1);
|
||||
const int32 count = _count - index;
|
||||
for (int32 i = 0; i < count; i++)
|
||||
for (int32 i = 0; i < count; ++i)
|
||||
dst[i] = MoveTemp(src[i]);
|
||||
}
|
||||
Memory::DestructItems(data + _count, 1);
|
||||
@@ -712,7 +712,7 @@ public:
|
||||
/// <param name="item">The item to remove.</param>
|
||||
void RemoveAll(const T& item)
|
||||
{
|
||||
for (int32 i = Count() - 1; i >= 0; i--)
|
||||
for (int32 i = Count() - 1; i >= 0; --i)
|
||||
{
|
||||
if (_allocation.Get()[i] == item)
|
||||
{
|
||||
@@ -730,7 +730,7 @@ public:
|
||||
void RemoveAt(const int32 index)
|
||||
{
|
||||
ASSERT(index < _count && index >= 0);
|
||||
_count--;
|
||||
--_count;
|
||||
T* data = _allocation.Get();
|
||||
if (_count)
|
||||
data[index] = data[_count];
|
||||
@@ -743,7 +743,7 @@ public:
|
||||
void RemoveLast()
|
||||
{
|
||||
ASSERT(_count > 0);
|
||||
_count--;
|
||||
--_count;
|
||||
Memory::DestructItems(_allocation.Get() + _count, 1);
|
||||
}
|
||||
|
||||
@@ -772,7 +772,7 @@ public:
|
||||
{
|
||||
T* data = _allocation.Get();
|
||||
const int32 count = _count / 2;
|
||||
for (int32 i = 0; i < count; i++)
|
||||
for (int32 i = 0; i < count; ++i)
|
||||
::Swap(data[i], data[_count - i - 1]);
|
||||
}
|
||||
|
||||
@@ -1052,7 +1052,7 @@ public:
|
||||
Iterator& operator--()
|
||||
{
|
||||
if (_index > 0)
|
||||
_index--;
|
||||
--_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1060,7 +1060,7 @@ public:
|
||||
{
|
||||
Iterator temp = *this;
|
||||
if (_index > 0)
|
||||
_index--;
|
||||
--_index;
|
||||
return temp;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -304,7 +304,7 @@ public:
|
||||
void Add(const bool item)
|
||||
{
|
||||
EnsureCapacity(_count + 1);
|
||||
_count++;
|
||||
++_count;
|
||||
Set(_count - 1, item);
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ public:
|
||||
void Add(const bool* items, const int32 count)
|
||||
{
|
||||
EnsureCapacity(_count + count);
|
||||
for (int32 i = 0; i < count; i++)
|
||||
for (int32 i = 0; i < count; ++i)
|
||||
Add(items[i]);
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ public:
|
||||
void Add(const BitArray& other)
|
||||
{
|
||||
EnsureCapacity(_count, other.Count());
|
||||
for (int32 i = 0; i < other.Count(); i++)
|
||||
for (int32 i = 0; i < other.Count(); ++i)
|
||||
Add(other[i]);
|
||||
}
|
||||
|
||||
|
||||
@@ -363,8 +363,9 @@ public:
|
||||
const Bucket* data = _collection->_allocation.Get();
|
||||
do
|
||||
{
|
||||
_index++;
|
||||
} while (_index != capacity && data[_index].IsNotOccupied());
|
||||
++_index;
|
||||
}
|
||||
while (_index != capacity && data[_index].IsNotOccupied());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -383,8 +384,9 @@ public:
|
||||
const Bucket* data = _collection->_allocation.Get();
|
||||
do
|
||||
{
|
||||
_index--;
|
||||
} while (_index > 0 && data[_index].IsNotOccupied());
|
||||
--_index;
|
||||
}
|
||||
while (_index > 0 && data[_index].IsNotOccupied());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -423,7 +425,7 @@ public:
|
||||
|
||||
// Insert
|
||||
ASSERT(pos.FreeSlotIndex != -1);
|
||||
_elementsCount++;
|
||||
++_elementsCount;
|
||||
Bucket& bucket = _allocation.Get()[pos.FreeSlotIndex];
|
||||
bucket.Occupy(key);
|
||||
return bucket.Value;
|
||||
@@ -582,7 +584,7 @@ public:
|
||||
Memory::MoveItems(&bucket->Key, &oldBucket.Key, 1);
|
||||
Memory::MoveItems(&bucket->Value, &oldBucket.Value, 1);
|
||||
bucket->_state = Bucket::Occupied;
|
||||
_elementsCount++;
|
||||
++_elementsCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -682,8 +684,8 @@ public:
|
||||
if (pos.ObjectIndex != -1)
|
||||
{
|
||||
_allocation.Get()[pos.ObjectIndex].Delete();
|
||||
_elementsCount--;
|
||||
_deletedCount++;
|
||||
--_elementsCount;
|
||||
++_deletedCount;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -701,8 +703,8 @@ public:
|
||||
{
|
||||
ASSERT(_allocation.Get()[i._index].IsOccupied());
|
||||
_allocation.Get()[i._index].Delete();
|
||||
_elementsCount--;
|
||||
_deletedCount++;
|
||||
--_elementsCount;
|
||||
++_deletedCount;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -721,7 +723,7 @@ public:
|
||||
if (i->Value == value)
|
||||
{
|
||||
Remove(i);
|
||||
result++;
|
||||
++result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -768,7 +770,7 @@ public:
|
||||
if (HasItems())
|
||||
{
|
||||
const Bucket* data = _allocation.Get();
|
||||
for (int32 i = 0; i < _size; i++)
|
||||
for (int32 i = 0; i < _size; ++i)
|
||||
{
|
||||
if (data[i].IsOccupied() && data[i].Value == value)
|
||||
return true;
|
||||
@@ -788,7 +790,7 @@ public:
|
||||
if (HasItems())
|
||||
{
|
||||
const Bucket* data = _allocation.Get();
|
||||
for (int32 i = 0; i < _size; i++)
|
||||
for (int32 i = 0; i < _size; ++i)
|
||||
{
|
||||
if (data[i].IsOccupied() && data[i].Value == value)
|
||||
{
|
||||
@@ -928,7 +930,7 @@ private:
|
||||
result.ObjectIndex = bucketIndex;
|
||||
return;
|
||||
}
|
||||
checksCount++;
|
||||
++checksCount;
|
||||
bucketIndex = (bucketIndex + DICTIONARY_PROB_FUNC(_size, checksCount)) & tableSizeMinusOne;
|
||||
}
|
||||
result.ObjectIndex = -1;
|
||||
|
||||
@@ -102,7 +102,7 @@ private:
|
||||
to.Allocate(fromSize);
|
||||
Bucket* toData = to.Get();
|
||||
Bucket* fromData = from.Get();
|
||||
for (int32 i = 0; i < fromSize; i++)
|
||||
for (int32 i = 0; i < fromSize; ++i)
|
||||
{
|
||||
Bucket& fromBucket = fromData[i];
|
||||
if (fromBucket.IsOccupied())
|
||||
@@ -344,8 +344,9 @@ public:
|
||||
const Bucket* data = _collection->_allocation.Get();
|
||||
do
|
||||
{
|
||||
_index++;
|
||||
} while (_index != capacity && data[_index].IsNotOccupied());
|
||||
++_index;
|
||||
}
|
||||
while (_index != capacity && data[_index].IsNotOccupied());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -364,8 +365,9 @@ public:
|
||||
const Bucket* data = _collection->_allocation.Get();
|
||||
do
|
||||
{
|
||||
_index--;
|
||||
} while (_index > 0 && data[_index].IsNotOccupied());
|
||||
--_index;
|
||||
}
|
||||
while (_index > 0 && data[_index].IsNotOccupied());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -559,8 +561,8 @@ public:
|
||||
if (pos.ObjectIndex != -1)
|
||||
{
|
||||
_allocation.Get()[pos.ObjectIndex].Delete();
|
||||
_elementsCount--;
|
||||
_deletedCount++;
|
||||
--_elementsCount;
|
||||
++_deletedCount;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -578,8 +580,8 @@ public:
|
||||
{
|
||||
ASSERT(_allocation.Get()[i._index].IsOccupied());
|
||||
_allocation.Get()[i._index].Delete();
|
||||
_elementsCount--;
|
||||
_deletedCount++;
|
||||
--_elementsCount;
|
||||
++_deletedCount;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -750,7 +752,7 @@ private:
|
||||
|
||||
// Insert
|
||||
ASSERT(pos.FreeSlotIndex != -1);
|
||||
_elementsCount++;
|
||||
++_elementsCount;
|
||||
return &_allocation.Get()[pos.FreeSlotIndex];
|
||||
}
|
||||
|
||||
@@ -760,7 +762,7 @@ private:
|
||||
{
|
||||
// Fast path if it's empty
|
||||
Bucket* data = _allocation.Get();
|
||||
for (int32 i = 0; i < _size; i++)
|
||||
for (int32 i = 0; i < _size; ++i)
|
||||
data[i]._state = Bucket::Empty;
|
||||
}
|
||||
else
|
||||
@@ -770,11 +772,11 @@ private:
|
||||
MoveToEmpty(oldAllocation, _allocation, _size);
|
||||
_allocation.Allocate(_size);
|
||||
Bucket* data = _allocation.Get();
|
||||
for (int32 i = 0; i < _size; i++)
|
||||
for (int32 i = 0; i < _size; ++i)
|
||||
data[i]._state = Bucket::Empty;
|
||||
Bucket* oldData = oldAllocation.Get();
|
||||
FindPositionResult pos;
|
||||
for (int32 i = 0; i < _size; i++)
|
||||
for (int32 i = 0; i < _size; ++i)
|
||||
{
|
||||
Bucket& oldBucket = oldData[i];
|
||||
if (oldBucket.IsOccupied())
|
||||
@@ -786,7 +788,7 @@ private:
|
||||
bucket->_state = Bucket::Occupied;
|
||||
}
|
||||
}
|
||||
for (int32 i = 0; i < _size; i++)
|
||||
for (int32 i = 0; i < _size; ++i)
|
||||
oldData[i].Free();
|
||||
}
|
||||
_deletedCount = 0;
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
}
|
||||
Memory::ConstructItems(_allocation.Get() + _back, &data, 1);
|
||||
_back = (_back + 1) % _capacity;
|
||||
_count++;
|
||||
++_count;
|
||||
}
|
||||
|
||||
FORCE_INLINE T& PeekFront()
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
{
|
||||
Memory::DestructItems(_allocation.Get() + _front, 1);
|
||||
_front = (_front + 1) % _capacity;
|
||||
_count--;
|
||||
--_count;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
|
||||
Reference in New Issue
Block a user