From 6a7849d0c56741ba2b36275f0c181ac1b261b698 Mon Sep 17 00:00:00 2001 From: Estella <10225101469@stu.ecnu.edu.cn> Date: Sun, 5 Jan 2025 19:34:59 +0800 Subject: [PATCH] newDB --- db/NewDB.cc | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ db/NewDB.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 db/NewDB.cc create mode 100644 db/NewDB.h diff --git a/db/NewDB.cc b/db/NewDB.cc new file mode 100644 index 0000000..f64cd27 --- /dev/null +++ b/db/NewDB.cc @@ -0,0 +1,62 @@ +#include "db/NewDB.h" +#include "util/coding.h" +#include "db/write_batch_internal.h" +#include "db/version_set.h" +#include "db/db_impl.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace leveldb{ +NewDB::~NewDB() { + +} + +Status NewDB::Open(const Options& options, const std::string& name, NewDB** dbptr) { + +} + + +Status NewDB::Put_fields(const WriteOptions& options, const Slice& key, const FieldArray& fields){ + +} + +Status NewDB::Get_fields(const ReadOptions& options, const Slice& key, FieldArray* fields){ + +} + +std::vector NewDB::FindKeysByField(Field &field){ + +} + +bool NewDB::Delete(const WriteOptions& options, const Slice& key){ + +} + + + +bool NewDB::CreateIndexOnField(const std::string& field_name) { + +} + +std::vector NewDB::QueryByIndex(Field &field){ + +} + +bool NewDB::DeleteIndex(const std::string& field_name){ + +} + +} + + + + + diff --git a/db/NewDB.h b/db/NewDB.h new file mode 100644 index 0000000..05c8a05 --- /dev/null +++ b/db/NewDB.h @@ -0,0 +1,53 @@ +#ifndef NEWDB_H +#define NEWDB_H + +#include +#include +#include +#include +#include "leveldb/db.h" +#include "db/log_writer.h" + +namespace leveldb{ + +class LEVELDB_EXPORT NewDB { + public: + NewDB() = default; + + NewDB(const NewDB&) = delete; + NewDB& operator=(const NewDB&) = delete; + + virtual ~NewDB(); + + static Status Open(const Options& options, const std::string& name, + NewDB** dbptr); // 改为返回 NewDB* 类型-橙 + + Status Put_fields(const WriteOptions& options, const Slice& key, + const FieldArray& fields); + + Status Get_fields(const ReadOptions& options, const Slice& key, + FieldArray* fields); + + bool Delete(const WriteOptions& options, const Slice& key); + + std::vector FindKeysByField(Field &field); + + bool CreateIndexOnField(const std::string& field_name); + + std::vector QueryByIndex(Field &field); + + bool DeleteIndex(const std::string& field_name); + + // 用于存储已经为其创建索引的字段名称。只有当字段名在这个集合中时,才会在 indexDB 中插入对应的索引条目。 + std::unordered_set indexed_fields_read; + std::unordered_set indexed_fields_write; + + private: + std::unique_ptr data_db_; + + std::unique_ptr index_db_; +}; + +} + +#endif \ No newline at end of file