2018-07-14 13:00:25 +00:00
|
|
|
void DqnVHashTable_Test()
|
|
|
|
{
|
|
|
|
LOG_HEADER();
|
|
|
|
struct Block
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
using Height = u32;
|
|
|
|
|
2018-07-23 14:05:43 +00:00
|
|
|
{
|
|
|
|
Block block = {};
|
|
|
|
|
|
|
|
DqnVHashTable<Height, Block> table = {};
|
2018-09-02 11:17:14 +00:00
|
|
|
DQN_DEFER { table.Free(); };
|
2018-07-23 14:05:43 +00:00
|
|
|
table.Set(12, block);
|
|
|
|
|
|
|
|
Block *getResult = table.Get(12);
|
|
|
|
Block *operatorResult = table[12];
|
|
|
|
DQN_ASSERT(operatorResult == getResult);
|
|
|
|
DQN_ASSERT(operatorResult != nullptr);
|
|
|
|
Log(Status::Ok, "Set and get element using key");
|
|
|
|
|
|
|
|
table.Erase(12);
|
|
|
|
getResult = table.Get(12);
|
|
|
|
operatorResult = table[12];
|
|
|
|
|
|
|
|
DQN_ASSERT(operatorResult == getResult);
|
|
|
|
DQN_ASSERT(operatorResult == nullptr);
|
|
|
|
Log(Status::Ok, "Erase element using key");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-07-24 15:33:31 +00:00
|
|
|
Block blocks[] = {{0}, {1}, {2}, {3}, {4}};
|
2018-07-23 14:05:43 +00:00
|
|
|
DqnVHashTable<Height, Block> table = {};
|
2018-09-02 11:17:14 +00:00
|
|
|
DQN_DEFER { table.Free(); };
|
2018-07-14 13:00:25 +00:00
|
|
|
|
2018-07-23 14:05:43 +00:00
|
|
|
table.Set(1, blocks[0]);
|
|
|
|
table.Set(2, blocks[1]);
|
|
|
|
table.Set(3, blocks[2]);
|
|
|
|
table.Set(4, blocks[3]);
|
|
|
|
table.Set(5, blocks[4]);
|
2018-07-14 13:00:25 +00:00
|
|
|
|
2018-07-23 14:05:43 +00:00
|
|
|
{
|
2018-07-24 10:44:01 +00:00
|
|
|
bool blockSeen[DQN_ARRAY_COUNT(blocks)] = {};
|
|
|
|
isize blocksSeen = 0;
|
2018-07-24 15:33:31 +00:00
|
|
|
for (auto const &entry : table)
|
2018-07-24 10:44:01 +00:00
|
|
|
{
|
2018-07-24 15:33:31 +00:00
|
|
|
Block const *block = &entry.item;
|
|
|
|
DQN_ASSERT(blockSeen[block->x] == false);
|
|
|
|
blockSeen[block->x] = true;
|
2018-07-24 10:44:01 +00:00
|
|
|
blocksSeen++;
|
|
|
|
}
|
|
|
|
DQN_ASSERT(blocksSeen == DQN_ARRAY_COUNT(blockSeen));
|
|
|
|
Log(Status::Ok, "Auto iterator using prefix operator++");
|
2018-07-23 14:05:43 +00:00
|
|
|
}
|
2018-07-14 13:00:25 +00:00
|
|
|
|
2018-07-24 10:44:01 +00:00
|
|
|
{
|
|
|
|
bool blockSeen[DQN_ARRAY_COUNT(blocks)] = {};
|
|
|
|
isize blocksSeen = 0;
|
|
|
|
for (auto it = table.begin(); it != table.end();)
|
|
|
|
{
|
2018-07-24 15:33:31 +00:00
|
|
|
Block *block = &it.entry->item;
|
2018-07-24 10:44:01 +00:00
|
|
|
|
|
|
|
DQN_ASSERT(blockSeen[block->x] == false);
|
|
|
|
blockSeen[block->x] = true;
|
|
|
|
blocksSeen++;
|
2018-07-24 15:33:31 +00:00
|
|
|
it = it + 1;
|
2018-07-24 10:44:01 +00:00
|
|
|
}
|
|
|
|
DQN_ASSERT(blocksSeen == DQN_ARRAY_COUNT(blockSeen));
|
|
|
|
Log(Status::Ok, "Auto iterator using operator+");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
bool blockSeen[DQN_ARRAY_COUNT(blocks)] = {};
|
|
|
|
isize blocksSeen = 0;
|
|
|
|
for (auto it = table.begin(); it != table.end(); it++)
|
|
|
|
{
|
2018-07-24 15:33:31 +00:00
|
|
|
Block *block = &it.entry->item;
|
2018-07-24 10:44:01 +00:00
|
|
|
|
|
|
|
DQN_ASSERT(blockSeen[block->x] == false);
|
|
|
|
blockSeen[block->x] = true;
|
|
|
|
blocksSeen++;
|
|
|
|
}
|
|
|
|
DQN_ASSERT(blocksSeen == DQN_ARRAY_COUNT(blockSeen));
|
|
|
|
Log(Status::Ok, "Auto iterator using postfix operator++");
|
|
|
|
}
|
2018-07-23 14:05:43 +00:00
|
|
|
}
|
2018-07-14 13:00:25 +00:00
|
|
|
}
|