this code is a disgrace

This commit is contained in:
Xory 2025-09-24 16:16:45 +03:00
parent b2e898eeed
commit a397347001
5 changed files with 72 additions and 4 deletions

2
.gitignore vendored
View file

@ -1 +1,3 @@
a.out
flake.lock
/.ccls-cache

View file

@ -1,4 +1,10 @@
# bluedis
Redis, but worse in every conceivable manner.
And also written in C++.
And also my first serious C++ project.
## Roadmap
- [X] Basic K/V store
- [ ] Remove/add entries
- [ ] Serialisation and saving
- [ ] Networking

17
flake.nix Normal file
View file

@ -0,0 +1,17 @@
{
description = "Development flake for bluedis";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/release-25.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShells.default = import ./shell.nix { inherit pkgs; };
}
);
}

View file

@ -2,6 +2,38 @@
#include <string>
#include <iostream>
void add_entry(std::vector<std::vector<std::string>>& database, std::string key, std::string value) {
database.push_back({key, value});
}
void remove_entry(std::vector<std::vector<std::string>>& database, std::string key) {
int index = 0;
for (std::vector<std::string>& entry : database) {
index++;
if (entry[0] == key) {
database.erase(database.begin() + index);
}
}
}
void prompt_user(std::vector<std::vector<std::string>>& database) {
std::string mode;
std::cin >> mode;
if (mode == "add") {
std::string key;
std::string value;
std::cin >> key;
std::cin >> value;
add_entry(database, key, value);
} else if (mode == "rem") {
std::string key;
std::cin >> key;
remove_entry(database, key);
} else {
prompt_user(database);
}
}
int main() {
std::vector<std::vector<std::string>> database;
@ -10,8 +42,11 @@ int main() {
{ "john", "unwanted_guest"},
{ "laith", "ducc" }
};
for (std::vector entry: database) {
std::cout << entry[0] << " | " << entry[1] << std::endl;
while (true) {
for (std::vector entry: database) {
std::cout << entry[0] << " | " << entry[1] << std::endl;
}
prompt_user(database);
}
}

8
shell.nix Normal file
View file

@ -0,0 +1,8 @@
{ pkgs ? import <nixpkgs> }:
with pkgs;
mkShell {
buildInputs = with pkgs; [
gcc
ccls
];
}