From 0c05c4424c986ae41d1e2708b0eba2a915550b57 Mon Sep 17 00:00:00 2001 From: YuhangQ Date: Mon, 1 Nov 2021 10:35:16 +0000 Subject: [PATCH] sync --- CMakeLists.txt | 2 +- invodb/index/query.cpp | 9 +++++++++ invodb/index/query.h | 16 ++++++++++++++++ invodb/main.cpp | 34 ++++++++++++++++------------------ invodb/models/collection.cpp | 9 ++++++++- 5 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 invodb/index/query.cpp create mode 100644 invodb/index/query.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c21cb0d..778b760 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,4 +11,4 @@ include_directories(./invodb) add_executable(InvoDB invodb/main.cpp - invodb/main.h invodb/file/page_manager.cpp invodb/file/page_manager.h invodb/models/collection.cpp invodb/models/collection.h invodb/file/storage_page.cpp invodb/file/storage_page.h invodb/utils/logger.h invodb/utils/uuid.h invodb/btree/node.h invodb/btree/btree.h invodb/index/index.cpp invodb/index/index.h invodb/btree/list.h) + invodb/main.h invodb/file/page_manager.cpp invodb/file/page_manager.h invodb/models/collection.cpp invodb/models/collection.h invodb/file/storage_page.cpp invodb/file/storage_page.h invodb/utils/logger.h invodb/utils/uuid.h invodb/btree/node.h invodb/btree/btree.h invodb/index/index.cpp invodb/index/index.h invodb/btree/list.h invodb/index/query.cpp invodb/index/query.h) diff --git a/invodb/index/query.cpp b/invodb/index/query.cpp new file mode 100644 index 0000000..1edac9e --- /dev/null +++ b/invodb/index/query.cpp @@ -0,0 +1,9 @@ +// +// Created by projector-user on 11/1/21. +// + +#include "query.h" + +std::vector Query::find(const nlohmann::json &json) { + return std::vector(); +} diff --git a/invodb/index/query.h b/invodb/index/query.h new file mode 100644 index 0000000..d3a54af --- /dev/null +++ b/invodb/index/query.h @@ -0,0 +1,16 @@ +// +// Created by projector-user on 11/1/21. +// + +#ifndef INVODB_QUERY_H +#define INVODB_QUERY_H + +#include "json/json.hpp" + +class Query { + std::vector find(const nlohmann::json &json); + +}; + + +#endif //INVODB_QUERY_H diff --git a/invodb/main.cpp b/invodb/main.cpp index 2dda153..64a7bd3 100644 --- a/invodb/main.cpp +++ b/invodb/main.cpp @@ -29,26 +29,24 @@ int main() { col = &Collection::getCollection("hello"); } - std::string test; - for(int i=0; i<100; i++) { - test += generateUUID(); - } - nlohmann::json j = nlohmann::json::parse(R"( -{ - "string": "this is a string!", - "double": 3.1415, - "int": 25565, - "bool": true, - "child": { - "id": 3 - }, - "array": ["1", "2", "3"] -} - )"); + testAndBenchmark(10000); - col->insert(j); - col->remove(j); +// nlohmann::json j = nlohmann::json::parse(R"( +//{ +// "string": "this is a string!", +// "double": 3.1415, +// "int": 25565, +// "bool": true, +// "child": { +// "id": 3 +// }, +// "array": ["1", "2", "3"] +// )"); +// +// col->insert(j); +// +// col->remove(j); return 0; } diff --git a/invodb/models/collection.cpp b/invodb/models/collection.cpp index 0dad326..27673cf 100644 --- a/invodb/models/collection.cpp +++ b/invodb/models/collection.cpp @@ -68,6 +68,8 @@ Collection &Collection::getCollection(const std::string &name) { Collection::Collection(const std::string &name, const int &firstPage) { Logger::info("load Collection: ", name); index = new BTree(firstPage); + + if(!index->exists("__INVO_ID__")) { index->insert("__INVO_ID__", PageManager::Instance().allocate()); } @@ -80,6 +82,9 @@ void Collection::insert(nlohmann::json &json) { } else { remove(json); } + + + std::string id = json["__INVO_ID__"].get(); int add = PageManager::Instance().saveJSONToFile(json); uuid->insert(id, add); @@ -94,9 +99,10 @@ void Collection::remove(const nlohmann::json &json) { throw "no invo_id"; } std::string id = json["__INVO_ID__"].get(); - uuid->remove(id); + int address = uuid->find(id); + uuid->remove(id); nlohmann::json jsonInDisk = PageManager::Instance().readJSONFromFile(address); @@ -105,6 +111,7 @@ void Collection::remove(const nlohmann::json &json) { PageManager::Instance().release(address); } +// age=1 age=“hello” void Collection::indexJSON(const std::string prefix, const nlohmann::json &json, const int& address) { // even easier with structured bindings (C++17) for (auto& [key, value] : json.items()) {