InvoDB/invodb/collection/collection.h

64 lines
2.6 KiB
C
Raw Normal View History

2021-10-11 22:05:45 +08:00
//
// Created by YuhangQ on 2021/10/9.
//
#ifndef INVODB_COLLECTION_H
#define INVODB_COLLECTION_H
2021-10-23 16:28:57 +08:00
#include "file/page_manager.h"
#include "utils/logger.h"
2021-10-30 19:48:39 +08:00
#include "btree/btree.h"
2021-10-31 14:51:09 +08:00
#include "json/json.hpp"
2021-10-23 16:28:57 +08:00
#include <map>
#include <set>
#include <algorithm>
#include <cstring>
2021-10-25 22:07:18 +08:00
#include "utils/uuid.h"
2021-11-01 15:11:33 +08:00
#include "btree/list.h"
2021-10-11 22:05:45 +08:00
class Collection {
2021-10-23 16:28:57 +08:00
public:
2021-10-31 14:51:09 +08:00
void insert(nlohmann::json &json);
2021-11-01 15:11:33 +08:00
void remove(const nlohmann::json &json);
2021-11-08 20:03:38 +08:00
std::vector<nlohmann::json> query(const nlohmann::json &json);
2021-10-23 16:28:57 +08:00
static void loadCollections();
static Collection& getCollection(const std::string& name);
static Collection& createCollection(const std::string& name);
2021-11-03 22:05:13 +08:00
void test();
2021-10-23 16:28:57 +08:00
private:
2021-11-01 15:11:33 +08:00
void indexJSON(const std::string prefix, const nlohmann::json &json, const int& address);
void insertIndex(const std::string indexName, const std::string indexValue, const int& address);
void insertIndex(const std::string indexName, double indexValue, const int& address);
void insertIndex(const std::string indexName, bool indexValue, const int& address);
void clearIndex(const std::string prefix, const nlohmann::json &json, const int& address);
void removeIndex(const std::string indexName, const std::string indexValue, const int& address);
void removeIndex(const std::string indexName, double indexValue, const int& address);
void removeIndex(const std::string indexName, bool indexValue, const int& address);
2021-11-08 20:03:38 +08:00
std::set<nlohmann::json> setIntersection(const std::set<nlohmann::json> &a, const std::set<nlohmann::json> &b);
std::set<nlohmann::json> setUnion(const std::set<nlohmann::json> &a, const std::set<nlohmann::json> &b);
std::set<nlohmann::json> innerQuery(const std::string &prefix, const nlohmann::json &json);
std::set<nlohmann::json> queryString(const std::string &prefix, const std::string &minValue, const std::string &maxValue, const int &mod = 0);
std::set<nlohmann::json> queryNumber(const std::string &prefix, const double &minValue, const double &maxValue, const int &mod = 0);
std::set<nlohmann::json> queryBool(const std::string &prefix, const bool &value);
std::set<nlohmann::json> queryRange(const std::string &prefix, const nlohmann::json &json);
2021-10-23 16:28:57 +08:00
static std::map<std::string, Collection*> map;
2021-11-03 11:14:34 +08:00
static BTree<std::string, 32> colList;
2021-10-30 23:46:11 +08:00
2021-11-01 15:11:33 +08:00
BTree<std::string, 32> *uuid;
BTree<std::string, 128> *index;
2021-10-30 23:46:11 +08:00
2021-10-23 16:28:57 +08:00
Collection(const std::string& name,const int& firstPage);
Collection() {}
~Collection() {}
Collection(const Collection&);
Collection& operator=(const Collection&);
2021-10-11 22:05:45 +08:00
};
#endif //INVODB_COLLECTION_H