-first draft of BinSearchArrayMap
This commit is contained in:
@@ -33,7 +33,7 @@ namespace OpenVulkano
|
|||||||
throw std::runtime_error("Key cannot be lesser than the last used key.");
|
throw std::runtime_error("Key cannot be lesser than the last used key.");
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args> void Emplace(K key, Args... args)
|
template<typename... Args> void Emplace(K key, Args... args)
|
||||||
{
|
{
|
||||||
// Check if the key is bigger than the last element
|
// Check if the key is bigger than the last element
|
||||||
if (m_data.empty() || key > m_data.back().first)
|
if (m_data.empty() || key > m_data.back().first)
|
||||||
@@ -45,7 +45,7 @@ namespace OpenVulkano
|
|||||||
throw std::runtime_error("Key cannot be lesser than the last used key.");
|
throw std::runtime_error("Key cannot be lesser than the last used key.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Remove(K key) noexcept
|
void Remove(K key) noexcept
|
||||||
{
|
{
|
||||||
auto it = std::lower_bound(m_data.begin(), m_data.end(), key,
|
auto it = std::lower_bound(m_data.begin(), m_data.end(), key,
|
||||||
[](const auto& pair, const K& key) { return pair.first < key; });
|
[](const auto& pair, const K& key) { return pair.first < key; });
|
||||||
@@ -70,7 +70,8 @@ namespace OpenVulkano
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
V& Get(K key) noexcept {
|
V& Get(K key) noexcept
|
||||||
|
{
|
||||||
auto it = std::lower_bound(m_data.begin(), m_data.end(), key,
|
auto it = std::lower_bound(m_data.begin(), m_data.end(), key,
|
||||||
[](const auto& pair, const K& key) { return pair.first < key; });
|
[](const auto& pair, const K& key) { return pair.first < key; });
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "Data/Containers/BinSearchArrayMap.hpp"
|
#include "Data/Containers/BinSearchArrayMap.hpp"
|
||||||
|
#include "Data/Containers/StableVector.hpp"
|
||||||
|
|
||||||
using namespace OpenVulkano;
|
using namespace OpenVulkano;
|
||||||
|
|
||||||
@@ -26,7 +27,6 @@ TEST_CASE("BinSearchArrayMap")
|
|||||||
|
|
||||||
auto wtf =
|
auto wtf =
|
||||||
std::lower_bound(data.begin(), data.end(), 10, [](const auto& pair, const int& key) { return pair.first < key; });
|
std::lower_bound(data.begin(), data.end(), 10, [](const auto& pair, const int& key) { return pair.first < key; });
|
||||||
|
|
||||||
auto test = *wtf;
|
auto test = *wtf;
|
||||||
REQUIRE(test.first == 10);
|
REQUIRE(test.first == 10);
|
||||||
REQUIRE(test.second == "Five");
|
REQUIRE(test.second == "Five");
|
||||||
@@ -39,4 +39,5 @@ TEST_CASE("BinSearchArrayMap")
|
|||||||
map.Insert(10, "Five");
|
map.Insert(10, "Five");
|
||||||
|
|
||||||
REQUIRE(map[6] == "Three");
|
REQUIRE(map[6] == "Three");
|
||||||
|
REQUIRE(map[10] == "Five");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ TEST_CASE("MemMappedFileWrite")
|
|||||||
OpenVulkano::MemMappedFileWriteHelper::USE_CURRENT_FILE_SIZE);
|
OpenVulkano::MemMappedFileWriteHelper::USE_CURRENT_FILE_SIZE);
|
||||||
REQUIRE(helper.Data() != nullptr);
|
REQUIRE(helper.Data() != nullptr);
|
||||||
std::string testData((char*) helper.Data());
|
std::string testData((char*) helper.Data());
|
||||||
printf("size: %llu", helper.Size());
|
|
||||||
helper.Close();
|
helper.Close();
|
||||||
|
|
||||||
std::ifstream file(path, std::ios::binary);
|
std::ifstream file(path, std::ios::binary);
|
||||||
@@ -112,8 +111,6 @@ TEST_CASE("MemMappedFileWrite")
|
|||||||
}
|
}
|
||||||
|
|
||||||
REQUIRE(streamData.size() == testData.size());
|
REQUIRE(streamData.size() == testData.size());
|
||||||
|
|
||||||
printf("helper size: %llu\n", helper.Size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Actual Size")
|
SECTION("Actual Size")
|
||||||
|
|||||||
Reference in New Issue
Block a user