Stable Vector fully works as both Standalone and with BinSearchArrayMap

DONE
This commit is contained in:
Metehan Tuncbilek
2024-10-09 18:20:41 +03:00
parent 6f981682f8
commit 0e34b90f67
3 changed files with 70 additions and 96 deletions

View File

@@ -56,28 +56,12 @@ namespace OpenVulkano
Pair<K, V>& FindPair(const K key)
{
size_t low = 0;
size_t high = m_data.size();
while (low <= high)
std::streamsize index = FindIndexInVector(key);
if (index < 0)
{
size_t mid = low + (high - low) / 2;
if (m_data[mid].first == key)
{
return m_data[mid];
}
else if (m_data[mid].first < key)
{
low = mid + 1;
}
else
{
high = mid - 1;
}
std::runtime_error("Key not found");
}
throw std::runtime_error("Key not found.");
return m_data[index];
}
std::streamsize FindIndexInVector(const K key)
@@ -106,31 +90,7 @@ namespace OpenVulkano
return -1;
}
bool Contains(const K key) noexcept
{
size_t low = 0;
size_t high = m_data.size();
while (low <= high)
{
size_t mid = low + (high - low) / 2;
if (m_data[mid].first == key)
{
return true;
}
else if (m_data[mid].first < key)
{
low = mid + 1;
}
else
{
high = mid - 1;
}
}
return false;
}
bool Contains(const K key) noexcept { return FindIndexInVector(key) >= 0; }
void Clear() { m_data.clear(); }