rollback types and fix corner case with iterator
This commit is contained in:
@@ -39,7 +39,7 @@ namespace OpenVulkano
|
|||||||
|
|
||||||
size_t m_size; // Size of the chunk
|
size_t m_size; // Size of the chunk
|
||||||
size_t m_capacity; // Capacity of the chunk
|
size_t m_capacity; // Capacity of the chunk
|
||||||
std::ptrdiff_t m_nextIndex; // Next index to insert
|
size_t m_nextIndex; // Next index to insert
|
||||||
size_t m_gapCount; // Count of emptied gaps in the chunk
|
size_t m_gapCount; // Count of emptied gaps in the chunk
|
||||||
bool* m_occupiedIndices; // filled gaps array
|
bool* m_occupiedIndices; // filled gaps array
|
||||||
T m_data[0]; // data array
|
T m_data[0]; // data array
|
||||||
@@ -178,11 +178,11 @@ namespace OpenVulkano
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ptrdiff_t GetIteratorIndex() const { return m_chunk->GetRealIndex(m_index); }
|
size_t GetIteratorIndex() const { return m_chunk->GetRealIndex(m_index); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VectorChunk* m_chunk;
|
VectorChunk* m_chunk;
|
||||||
std::ptrdiff_t m_index;
|
size_t m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -266,15 +266,6 @@ namespace OpenVulkano
|
|||||||
return; // return? or make
|
return; // return? or make
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_lastChunk->m_nextIndex == -1)
|
|
||||||
{
|
|
||||||
VectorChunk* temp = m_lastChunk;
|
|
||||||
m_lastChunk = m_lastChunk->m_prev;
|
|
||||||
m_lastChunk->m_next = nullptr;
|
|
||||||
temp->~VectorChunk();
|
|
||||||
::operator delete(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_lastChunk->m_data[m_lastChunk->m_nextIndex - 1].~T();
|
m_lastChunk->m_data[m_lastChunk->m_nextIndex - 1].~T();
|
||||||
m_lastChunk->m_occupiedIndices[m_lastChunk->m_nextIndex - 1] = false;
|
m_lastChunk->m_occupiedIndices[m_lastChunk->m_nextIndex - 1] = false;
|
||||||
m_lastChunk->m_size--;
|
m_lastChunk->m_size--;
|
||||||
@@ -378,10 +369,24 @@ namespace OpenVulkano
|
|||||||
bool Empty() const noexcept { return m_size == 0; }
|
bool Empty() const noexcept { return m_size == 0; }
|
||||||
|
|
||||||
RegIterator begin() { return RegIterator(m_firstChunk, 0); }
|
RegIterator begin() { return RegIterator(m_firstChunk, 0); }
|
||||||
RegIterator end() { return RegIterator(m_lastChunk, m_lastChunk->m_nextIndex - 1); }
|
RegIterator end()
|
||||||
|
{
|
||||||
|
if (Empty()) [[unlikely]]
|
||||||
|
{
|
||||||
|
return begin();
|
||||||
|
}
|
||||||
|
return RegIterator(m_lastChunk, m_lastChunk->m_nextIndex - 1);
|
||||||
|
}
|
||||||
|
|
||||||
ConstIterator cbegin() const { return ConstIterator(m_firstChunk, 0); }
|
ConstIterator cbegin() const { return ConstIterator(m_firstChunk, 0); }
|
||||||
ConstIterator cend() const { return ConstIterator(m_lastChunk, m_lastChunk->m_nextIndex - 1); }
|
ConstIterator cend() const
|
||||||
|
{
|
||||||
|
if (Empty()) [[unlikely]]
|
||||||
|
{
|
||||||
|
return cbegin();
|
||||||
|
}
|
||||||
|
return ConstIterator(m_lastChunk, m_lastChunk->m_nextIndex - 1);
|
||||||
|
}
|
||||||
|
|
||||||
//region std aliases
|
//region std aliases
|
||||||
void push_back(const T& value) { PushBack(value); }
|
void push_back(const T& value) { PushBack(value); }
|
||||||
|
|||||||
@@ -101,6 +101,12 @@ TEST_CASE("ChunkVector")
|
|||||||
REQUIRE(vec.Capacity() == tempVal);
|
REQUIRE(vec.Capacity() == tempVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("Iterators with empty vector")
|
||||||
|
{
|
||||||
|
StableVector<uint32_t> vec;
|
||||||
|
REQUIRE(vec.begin() == vec.end());
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("Clear")
|
SECTION("Clear")
|
||||||
{
|
{
|
||||||
StableVector<uint32_t> vec;
|
StableVector<uint32_t> vec;
|
||||||
|
|||||||
Reference in New Issue
Block a user