User constructor now enforces logging rule

This commit is contained in:
doggo 2021-06-03 19:11:32 -05:00
parent ab11101611
commit 69121557a9
2 changed files with 11 additions and 13 deletions

View file

@ -13,7 +13,7 @@ struct Log
{
for (auto i = data.size() - 1; i > 0; i--) // Make room at the back
{
data[i - 1] == std::move(data[i])
data[i - 1] == std::move(data[i]) // Shifts everything left
}
}
else if (data.size() == data.capacity()) // If we haven't hit the max but hit capacity

View file

@ -1,6 +1,7 @@
#pragma once
#include <json/json.h>
#include <string>
#include <algorithm>
#include "log.hpp"
struct User
@ -35,19 +36,16 @@ struct User
{
if (log_j.size())
{
if (max_log_size > (log_j.size() + pre_log_size)) //if current imported log's size + prefetch amount is less then max
auto size = ((log_j.size() / pre_log_size) + 1) * pre_log_size; // Ensures that we have a log size aligned on a multiple of `pre_log_size`
log.data.reserve(std::min(size, max_log_size)); // Ensures that the log size is under `max_log_size`
for (uint32_t i = 0; i < log.size(); i++) // Matches the logs
{
//std::cout << "allocating " << log_j.size() + pre_log_size << '\n';
log.data.reserve(log_j.size() + pre_log_size); //allocate that amount
}
else
{
//std::cout << "allocating " << max_log_size << '\n';
log.data.reserve(max_log_size); //allocate max amount
}
for (uint32_t i = 0; i < log_j.size(); ++i)
{
log.data.push_back(std::move(Transaction(log_j[i]["from"].asCString(), log_j[i]["to"].asCString(), log_j[i]["amount"].asUInt(), log_j[i]["time"].asUInt64())));
log.data[i] = std::move(Transaction(
log_j[i]["from"].asCString(),
log_j[i]["to"].asCString(),
log_j[i]["amount"].asUInt(),
log_j[i]["time"].asUInt64()
));
}
}
}