Merge pull request 'Binary Search Array Map' (#124) from feature/BinSearchArrayMap into master

Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/124
Reviewed-by: Georg Hagen <georg.hagen@madvoxel.com>
This commit is contained in:
metehan.tuncbilek
2024-10-10 11:25:56 +02:00
5 changed files with 574 additions and 304 deletions

View File

@@ -0,0 +1,141 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <catch2/catch_all.hpp>
#include <vector>
#include <map>
#include <utility>
#include <type_traits>
#include "Data/Containers/BinSearchArrayMap.hpp"
#include "Data/Containers/StableVector.hpp"
using namespace OpenVulkano;
TEST_CASE("BinSearchArrayMap With Default")
{
SECTION("Insert")
{
BinSearchArrayMap<int, std::string> map;
for (int i = 0; i < 50; i++)
{
map.Insert(i, std::to_string(i));
}
REQUIRE(map.Size() == 50);
REQUIRE(map.Get(16) == "16");
REQUIRE(map.Get(23) == "23");
REQUIRE(map.Get(48) == "48");
}
SECTION("Remove")
{
BinSearchArrayMap<int, std::string> map;
for (int i = 0; i < 50; i++)
{
map.Insert(i, std::to_string(i));
}
map.Remove(16);
map.Remove(23);
map.Remove(48);
REQUIRE(map.Size() == 47);
for (int i = 0; i < 50; i++)
{
if (i == 16 || i == 23 || i == 48)
{
REQUIRE(!map.Contains(i));
}
else
{
REQUIRE(map.Get(i) == std::to_string(i));
}
}
}
SECTION("Emplace")
{
BinSearchArrayMap<int, std::string> map;
for (int i = 0; i < 50; i++)
{
map.Emplace(i, std::to_string(i));
}
REQUIRE(map.Size() == 50);
REQUIRE(map.Get(16) == "16");
REQUIRE(map.Get(23) == "23");
REQUIRE(map.Get(48) == "48");
}
SECTION("FindPair")
{
BinSearchArrayMap<int, std::string> map;
for (int i = 0; i < 50; i++)
{
map.Insert(i, std::to_string(i));
}
auto pair = map.FindPair(16);
REQUIRE(pair.first == 16);
REQUIRE(pair.second == "16");
}
}
TEST_CASE("BinSearchArrayMap With StableVector")
{
SECTION("Insert")
{
BinSearchArrayMap<int, std::string, std::pair, StableVector> map;
for (int i = 0; i < 50; i++)
{
map.Insert(i, std::to_string(i));
}
REQUIRE(map.Size() == 50);
REQUIRE(map.Get(16) == "16");
REQUIRE(map.Get(23) == "23");
REQUIRE(map.Get(48) == "48");
for (int i = 0; i < 50; i++)
{
REQUIRE(map.Get(i) == std::to_string(i));
}
}
SECTION("Remove")
{
BinSearchArrayMap<int, std::string, std::pair, StableVector> map;
for (int i = 0; i < 50; i++)
{
map.Insert(i, std::to_string(i));
}
map.Remove(16);
map.Remove(23);
map.Remove(48);
for (int i = 0; i < 50; i++)
{
if (i == 16 || i == 23 || i == 48)
{
REQUIRE(!map.Contains(i));
}
else
{
REQUIRE(map.Get(i) == std::to_string(i));
}
}
}
}

View File

@@ -95,7 +95,6 @@ TEST_CASE("MemMappedFileWrite")
OpenVulkano::MemMappedFileWriteHelper::USE_CURRENT_FILE_SIZE);
REQUIRE(helper.Data() != nullptr);
std::string testData((char*) helper.Data());
printf("size: %llu", helper.Size());
helper.Close();
std::ifstream file(path, std::ios::binary);
@@ -112,8 +111,6 @@ TEST_CASE("MemMappedFileWrite")
}
REQUIRE(streamData.size() == testData.size());
printf("helper size: %llu\n", helper.Size());
}
SECTION("Actual Size")

View File

@@ -136,7 +136,9 @@ TEST_CASE("ChunkVector")
REQUIRE(vec.Size() == 100);
vec.Remove(56);
vec.Add("z");
REQUIRE(vec[56] == "a");
vec.Push("z");
REQUIRE(vec.Size() == 100);
REQUIRE(vec[56] == "z");