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)
set(CMAKE_CXX_STANDARD 14)
include_directories(/opt/homebrew/Cellar/boost/1.76.0/include)
include_directories(.)
include_directories(./invodb)

View File

@ -54,3 +54,7 @@ void StoragePage::save() {
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 setStringStartFrom(const int &index, const char *str);
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]; }
operator const char *() const { return this->page; }
operator char *() { return this->page; }
int getAddress();
private:
char page[1024];
int address;

View File

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

View File

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

View File

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