2023年5月26日,周五下午:
这个版本主要实现了设置键值对和读取键值对,
下个版本主要实现把内存中的数据写入到磁盘中,把磁盘中的数据读取到内存中,
这个项目我已经放到了github上
GitHub - JuLongZhiLu/MaQueKVDB: just a very very small key/value database implemented by C++
目前只有两个文件MaqueKVDB.h和MaQueKVDB.cpp
采用面向对象编程
MaqueKVDB.h
#include <map>
#include <iostream>
#include <string>
class MaQueKVDB{
private:
std::map<std::string,std::string> map;
std::string version_information="Welcome to MaQueKVDB!\nVersion:1.0.0\nAuthor:JuLongZhiLu\n";
public:
bool set(std::string key,std::string value);
std::string get(std::string key);
void getVersionInformation();
};
MaQueKVDB.cpp
#include "MaQueKVDB.h"
bool MaQueKVDB::set(std::string key,std::string value){
//定义一个pair用来接收insert的返回值
std::pair<std::map<std::string, std::string>::iterator, bool> result;
//也可以用auto[iter,success]来接收
//auto[iter,success]=map.insert(std::pair<std::string,std::string>(key,value));
result=map.insert(std::pair<std::string,std::string>(key,value));
return result.second;
}
std::string MaQueKVDB::get(std::string key){
return map[key];
}
void MaQueKVDB::getVersionInformation(){
std::cout<<version_information<<std::endl;
}