remove boost library

This commit is contained in:
YuhangQ 2021-10-24 14:08:12 +08:00
parent 6cb59287d7
commit 2f12f421e6
6 changed files with 22 additions and 15 deletions

View File

@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.16.3)
project(InvoDB) project(InvoDB)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
include_directories(/opt/homebrew/Cellar/boost/1.76.0/include)
include_directories(.) include_directories(.)
include_directories(./invodb) include_directories(./invodb)

View File

@ -54,3 +54,7 @@ void StoragePage::save() {
PageManager::Instance().setPage(address, *this); PageManager::Instance().setPage(address, *this);
} }
int StoragePage::getAddress() {
return address;
}

View File

@ -23,10 +23,11 @@ public:
void setIntStartFrom(const int &index, const int &value); void setIntStartFrom(const int &index, const int &value);
void setStringStartFrom(const int &index, const char *str); void setStringStartFrom(const int &index, const char *str);
int *intArray(); int *intArray();
StoragePage(const int& id) { memset(page, 0, sizeof(page)); } StoragePage(const int& id) { memset(page, 0, sizeof(page)); this->address = id; }
char& operator[] (int index) { return this->page[index]; } char& operator[] (int index) { return this->page[index]; }
operator const char *() const { return this->page; } operator const char *() const { return this->page; }
operator char *() { return this->page; } operator char *() { return this->page; }
int getAddress();
private: private:
char page[1024]; char page[1024];
int address; int address;

View File

@ -11,7 +11,7 @@ int main() {
PageManager& manager = PageManager::Instance(); PageManager& manager = PageManager::Instance();
//Collection::createCollection("hello");
Collection &col = Collection::getCollection("hello"); Collection &col = Collection::getCollection("hello");
JSON json("{\"hello\": 1}"); JSON json("{\"hello\": 1}");

View File

@ -15,7 +15,7 @@ void Collection::insert(JSON &json) {
std::string uuid = generateUUID(); std::string uuid = generateUUID();
Document::AllocatorType &allocator = json.GetAllocator(); Document::AllocatorType &allocator = json.GetAllocator();
Value invoid (kStringType); Value invoid (kStringType);
invoid.SetString(uuid.c_str(), uuid.size()); invoid.SetString(uuid.c_str(), 3);
json.AddMember(" __Invo_ID__", invoid, allocator); json.AddMember(" __Invo_ID__", invoid, allocator);
} }
@ -57,6 +57,7 @@ Collection& Collection::createCollection(const std::string &name) {
int id = *free.begin(); int id = *free.begin();
free.erase(free.begin()); free.erase(free.begin());
printf("id: %d\n", id / 32);
StoragePage page = PageManager::Instance().getPage(id / 32); StoragePage page = PageManager::Instance().getPage(id / 32);
id %= 32; id %= 32;
@ -68,8 +69,11 @@ Collection& Collection::createCollection(const std::string &name) {
page.setStringStartFrom(id*32, name.c_str()); page.setStringStartFrom(id*32, name.c_str());
page.setIntStartFrom(id*32+28, collectionPage); page.setIntStartFrom(id*32+28, collectionPage);
page.print();
page.save(); page.save();
Collection *col = new Collection(name, collectionPage); Collection *col = new Collection(name, collectionPage);
map.insert(make_pair(name, col)); map.insert(make_pair(name, col));

View File

@ -7,16 +7,17 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/uuid_generators.hpp>
std::string generateUUID() { std::string generateUUID() {
boost::uuids::uuid a_uuid = boost::uuids::random_generator()(); srand(time(NULL));
std::string uuid_string = boost::uuids::to_string(a_uuid); std::string uuid;
std::remove(uuid_string.begin(), uuid_string.end(), '-'); for(int i=0; i<32; i++) {
uuid_string.resize(32); int randn = rand() % 36;
return uuid_string; //0~35;
uuid += (randn < 26 ? ('a' + randn) : ('0' + (randn - 26)));
}
std::cout << uuid << std::endl;
return uuid;
} }
#endif //INVODB_UUID_H #endif //INVODB_UUID_H