mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-16 00:02:14 +11:00
🐎 changed log structure from vector to deque
This commit is contained in:
parent
fa1a9e6728
commit
e112468395
2 changed files with 6 additions and 12 deletions
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include <json/json.h> // to be removed later
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include "ccash_config.hpp"
|
||||
#include "change_flag.h"
|
||||
#include "transaction.h"
|
||||
|
|
@ -19,10 +18,10 @@ public:
|
|||
#if MAX_LOG_SIZE == 1
|
||||
Transaction data;
|
||||
#else
|
||||
std::vector<Transaction> data;
|
||||
std::deque<Transaction> data;
|
||||
#endif
|
||||
|
||||
std::string GetLogs() noexcept;
|
||||
void AddTrans(const Transaction &t) noexcept;
|
||||
void AddTrans(const std::string &from, const std::string &to, uint32_t amount, time_t time) noexcept;
|
||||
Json::Value Serialize() const; // to be removed later
|
||||
};
|
||||
|
|
|
|||
11
src/log.cpp
11
src/log.cpp
|
|
@ -1,6 +1,6 @@
|
|||
#include "log.h"
|
||||
|
||||
void Log::AddTrans(const Transaction &t) noexcept
|
||||
void Log::AddTrans(const std::string &from, const std::string &to, uint32_t amount, time_t time) noexcept
|
||||
{
|
||||
log_flag.SetChangesOn();
|
||||
#if MAX_LOG_SIZE == 1
|
||||
|
|
@ -8,14 +8,9 @@ void Log::AddTrans(const Transaction &t) noexcept
|
|||
#else
|
||||
if (data.size() == MAX_LOG_SIZE) // If we hit the max size
|
||||
{
|
||||
for (size_t i = 1; i < data.size(); i++) // Make room at the back
|
||||
{
|
||||
data[i - 1] = std::move(data[i]); // Shifts everything left
|
||||
}
|
||||
data[data.size() - 1] = std::move(t); // Place new in opened spot
|
||||
return;
|
||||
data.pop_back();
|
||||
}
|
||||
data.push_back(t); // In either case we have space under max length, move to new spot
|
||||
data.emplace_back(from, to, amount, time); // In either case we have space under max length, move to new spot
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue