From 5b425d5e683f4ac79508cbe838b12cb301686c2e Mon Sep 17 00:00:00 2001 From: punjitha <132387971+algotyrnt@users.noreply.github.com> Date: Thu, 22 Jan 2026 14:43:55 +0530 Subject: [PATCH] Add LICENSE file and update README.md to include licensing information --- LICENSE | 21 +++++++++++++++++++++ README.md | 3 +++ include/cache0.hpp | 15 +++++++-------- src/cache0.cpp | 15 +++++++-------- src/main.cpp | 19 +++++++++---------- test/test_cache0.cpp | 25 ++++++++++++------------- 6 files changed, 59 insertions(+), 39 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d18d93d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Punjitha (algotyrnt) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index bc3d4f4..eec005a 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,6 @@ Cache0/ ├── .github/ # The CI workflow └── README.md # Readme File ``` +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/include/cache0.hpp b/include/cache0.hpp index bc2ac77..e6684d2 100644 --- a/include/cache0.hpp +++ b/include/cache0.hpp @@ -1,9 +1,8 @@ -// -// cache0.hpp -// cache0 -// -// Created by Punjitha Bandara on 2026-01-19. -// +/* + * Cache0 - A lightweight C++ Key-Value Store + * Copyright (c) 2026 Punjitha (algotyrnt) + * Licensed under the MIT License. + */ #ifndef CACHE0_HPP #define CACHE0_HPP @@ -17,13 +16,13 @@ class Cache0 { private: std::unordered_map store; const std::string filename = "cache0.db"; - + void load(); void save(); public: Cache0(); // Constructor (Loads data) ~Cache0(); // Destructor (Saves data) - + void put(const std::string& key, const std::string& value); std::optional get(const std::string& key); bool remove(const std::string& key); diff --git a/src/cache0.cpp b/src/cache0.cpp index f12203d..ae426a3 100644 --- a/src/cache0.cpp +++ b/src/cache0.cpp @@ -1,9 +1,8 @@ -// -// cache0.cpp -// cache0 -// -// Created by Punjitha Bandara on 2026-01-19. -// +/* + * Cache0 - A lightweight C++ Key-Value Store + * Copyright (c) 2026 Punjitha (algotyrnt) + * Licensed under the MIT License. + */ #include #include "../include/cache0.hpp" @@ -33,7 +32,7 @@ bool Cache0::remove(const std::string& key) { void Cache0::save() { std::ofstream file(filename); - + if (file.is_open()) { for (const auto& pair : store) { file << pair.first << "=" << pair.second << std::endl; @@ -52,7 +51,7 @@ void Cache0::load() { if (file.is_open()) { while (std::getline(file, line)) { size_t delimiterPos = line.find('='); - + if (delimiterPos != std::string::npos) { std::string key = line.substr(0, delimiterPos); std::string value = line.substr(delimiterPos + 1); diff --git a/src/main.cpp b/src/main.cpp index 8db742a..c6621b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,24 +1,23 @@ -// -// main.cpp -// cache0 -// -// Created by Punjitha Bandara on 2026-01-19. -// +/* + * Cache0 - A lightweight C++ Key-Value Store + * Copyright (c) 2026 Punjitha (algotyrnt) + * Licensed under the MIT License. + */ #include #include "../include/cache0.hpp" int main() { std::cout << "[cache0] Initializing..." << std::endl; - + Cache0 db; - + db.put("user_id", "1024"); - + auto result = db.get("user_id"); if (result) { std::cout << "[cache0] Found: " << *result << std::endl; } - + return 0; } diff --git a/test/test_cache0.cpp b/test/test_cache0.cpp index 4168671..5e4e1cc 100644 --- a/test/test_cache0.cpp +++ b/test/test_cache0.cpp @@ -1,9 +1,8 @@ -// -// test_cache0.cpp -// cache0 -// -// Created by Punjitha Bandara on 2026-01-20. -// +/* + * Cache0 - A lightweight C++ Key-Value Store + * Copyright (c) 2026 Punjitha (algotyrnt) + * Licensed under the MIT License. + */ #include #include @@ -17,24 +16,24 @@ void pass(const std::string& name) { void test_basic_operations() { { Cache0 db; - + // 1. Test PUT and GET db.put("test_key", "123"); auto val = db.get("test_key"); assert(val.has_value() && "Key should exist"); assert(*val == "123" && "Value should be 123"); - + // 2. Test UPDATE (Overwrite) db.put("test_key", "456"); val = db.get("test_key"); assert(*val == "456" && "Value should be updated to 456"); - + // 3. Test REMOVE db.remove("test_key"); val = db.get("test_key"); assert(!val.has_value() && "Key should be deleted"); } - + pass("Basic Operations"); } @@ -50,16 +49,16 @@ void test_persistence() { assert(val.has_value() && "Data should survive restart"); assert(*val == "alive" && "Value should be preserved"); } - + pass("Persistence (Save/Load)"); } int main() { std::cout << "Running cache0 Tests..." << std::endl; - + test_basic_operations(); test_persistence(); - + std::cout << "All tests passed successfully!" << std::endl; return 0; }