mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-19 01:22: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
|
#pragma once
|
||||||
#include <json/json.h> // to be removed later
|
#include <json/json.h> // to be removed later
|
||||||
#include <vector>
|
#include <deque>
|
||||||
#include <algorithm>
|
|
||||||
#include "ccash_config.hpp"
|
#include "ccash_config.hpp"
|
||||||
#include "change_flag.h"
|
#include "change_flag.h"
|
||||||
#include "transaction.h"
|
#include "transaction.h"
|
||||||
|
|
@ -19,10 +18,10 @@ public:
|
||||||
#if MAX_LOG_SIZE == 1
|
#if MAX_LOG_SIZE == 1
|
||||||
Transaction data;
|
Transaction data;
|
||||||
#else
|
#else
|
||||||
std::vector<Transaction> data;
|
std::deque<Transaction> data;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string GetLogs() noexcept;
|
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
|
Json::Value Serialize() const; // to be removed later
|
||||||
};
|
};
|
||||||
|
|
|
||||||
11
src/log.cpp
11
src/log.cpp
|
|
@ -1,6 +1,6 @@
|
||||||
#include "log.h"
|
#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();
|
log_flag.SetChangesOn();
|
||||||
#if MAX_LOG_SIZE == 1
|
#if MAX_LOG_SIZE == 1
|
||||||
|
|
@ -8,14 +8,9 @@ void Log::AddTrans(const Transaction &t) noexcept
|
||||||
#else
|
#else
|
||||||
if (data.size() == MAX_LOG_SIZE) // If we hit the max size
|
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.pop_back();
|
||||||
{
|
|
||||||
data[i - 1] = std::move(data[i]); // Shifts everything left
|
|
||||||
}
|
}
|
||||||
data[data.size() - 1] = std::move(t); // Place new in opened spot
|
data.emplace_back(from, to, amount, time); // In either case we have space under max length, move to new spot
|
||||||
return;
|
|
||||||
}
|
|
||||||
data.push_back(t); // In either case we have space under max length, move to new spot
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue