From 6026e6aad59cd6268cbc9ed1e3c4643dd345c2d6 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 4 Jul 2021 20:18:34 -0700 Subject: [PATCH 1/2] :books::construction: working on docs --- README.md | 2 +- docs/connected_services/how_to/APIs.md | 2 ++ docs/contributors.md | 13 ++++++------- .../{implementations.md => implementation.md} | 0 4 files changed, 9 insertions(+), 8 deletions(-) rename docs/features/{implementations.md => implementation.md} (100%) diff --git a/README.md b/README.md index a9d95de..5319fd9 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ * [existing services](docs/connected_services/existing_services.md) * features * [user side](docs/features/user_side.md) - * [implementation](docs/features/implementations.md) + * [implementation](docs/features/implementation.md) * [building](docs/building.md) * [FAQ](docs/FAQ.md) * [Patreon](https://www.patreon.com/twoxx) if you wanna support this and/or future projects. \ No newline at end of file diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index e69de29..bf31292 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -0,0 +1,2 @@ +| language | +| -------- | \ No newline at end of file diff --git a/docs/contributors.md b/docs/contributors.md index d3bbfa6..50c9dc1 100644 --- a/docs/contributors.md +++ b/docs/contributors.md @@ -1,8 +1,7 @@ # Contributors -| name | work | -| :------------------------------------------ | -------------------------- | -| Caesay | Restful API suggestions | -| [Luke](https://github.com/LukeeeeBennett) | JS API, Docker package | -| [React](https://github.com/Reactified) | Computer Craft API, logo | -| [Doggo](https://github.com/FearlessDoggo21) | Logs optimized, Python API | -| [Expand](https://github.com/Expand-sys) | fixed Docker package | \ No newline at end of file +| name | work | +| :------------------------------------------ | ----------------------- | +| Caesay | Restful API suggestions | +| [Luke](https://github.com/LukeeeeBennett) | Docker package | +| [React](https://github.com/Reactified) | logo | +| [Doggo](https://github.com/FearlessDoggo21) | Logs optimized | \ No newline at end of file diff --git a/docs/features/implementations.md b/docs/features/implementation.md similarity index 100% rename from docs/features/implementations.md rename to docs/features/implementation.md From 3edd25dbe8b1311504e4cf704f74299e9f44fe2b Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 4 Jul 2021 20:34:49 -0700 Subject: [PATCH 2/2] :racehorse: optimized for when log == 1 --- include/log.h | 6 +++++- src/log.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/log.h b/include/log.h index 2d1ef98..001fccc 100644 --- a/include/log.h +++ b/include/log.h @@ -1,6 +1,6 @@ #pragma once #include // to be removed later -#include +#include #include #include "ccash_config.hpp" #include "change_flag.h" @@ -13,7 +13,11 @@ private: Json::Value log_snapshot; public: +#if MAX_LOG_SIZE == 1 + Transaction data; +#else std::vector data; +#endif const Json::Value &GetLog() noexcept; void AddTrans(Transaction &&t) noexcept; diff --git a/src/log.cpp b/src/log.cpp index dd3b308..e37b58c 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -2,6 +2,9 @@ void Log::AddTrans(Transaction &&t) noexcept { +#if MAX_LOG_SIZE == 1 + data = std::move(t); +#else if (data.size() == MAX_LOG_SIZE) // If we hit the max size { for (uint32_t i = 1; i < data.size(); i++) // Make room at the back @@ -16,6 +19,7 @@ void Log::AddTrans(Transaction &&t) noexcept data.reserve(data.capacity() + PRE_LOG_SIZE); // Reserve more memory } data.push_back(std::move(t)); // In either case we have space under max length, move to new spot +#endif log_flag.SetChangesOn(); } @@ -25,6 +29,15 @@ const Json::Value &Log::GetLog() noexcept { //re-generate snapshot Json::Value res; +#if MAX_LOG_SIZE == 1 + res[0]["to"] = data.to; + res[0]["from"] = data.from; +#ifdef _USE_32BIT_TIME_T + res[0]["time"] = (Json::UInt)data.time; +#else + res[0]["time"] = (Json::UInt64)data.time; +#endif +#else for (uint32_t i = data.size(); i > 0; --i) { res[i - 1]["to"] = data[data.size() - i].to; @@ -36,6 +49,7 @@ const Json::Value &Log::GetLog() noexcept res[i - 1]["time"] = (Json::UInt64)data[data.size() - i].time; #endif } +#endif log_flag.SetChangesOff(); log_snapshot = res; } @@ -45,6 +59,15 @@ const Json::Value &Log::GetLog() noexcept Json::Value Log::Serialize() const { Json::Value res; +#if MAX_LOG_SIZE == 1 + res[0]["to"] = data.to; + res[0]["from"] = data.from; +#ifdef _USE_32BIT_TIME_T + res[0]["time"] = (Json::UInt)data.time; +#else + res[0]["time"] = (Json::UInt64)data.time; +#endif +#else for (uint32_t i = 0; i < data.size(); ++i) { res[i]["to"] = data[i].to; @@ -56,5 +79,6 @@ Json::Value Log::Serialize() const res[i]["time"] = (Json::UInt64)data[i].time; #endif } +#endif return res; }