this code is a disgrace
This commit is contained in:
parent
b2e898eeed
commit
a397347001
5 changed files with 72 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1 +1,3 @@
|
|||
a.out
|
||||
flake.lock
|
||||
/.ccls-cache
|
||||
|
|
|
|||
|
|
@ -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
17
flake.nix
Normal 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; };
|
||||
}
|
||||
);
|
||||
}
|
||||
39
main.cpp
39
main.cpp
|
|
@ -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;
|
||||
|
||||
|
|
@ -11,7 +43,10 @@ int main() {
|
|||
{ "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
8
shell.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{ pkgs ? import <nixpkgs> }:
|
||||
with pkgs;
|
||||
mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
gcc
|
||||
ccls
|
||||
];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue