/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved. miniob is licensed under Mulan PSL v2. You can use this software according to the terms and conditions of the Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details. */ // // Created by Meiyi & Wangyunlai on 2021/5/11. // #pragma once #include #include #include "common/rc.h" #include "storage/index/index_meta.h" #include "storage/field/field_meta.h" #include "storage/record/record_manager.h" class IndexDataOperator { public: virtual ~IndexDataOperator() = default; virtual int compare(const void *data1, const void *data2) const = 0; virtual size_t hash(const void *data) const = 0; }; class IndexScanner; class Index { public: Index() = default; virtual ~Index() = default; const IndexMeta &index_meta() const { return index_meta_; } virtual RC insert_entry(const char *record, const RID *rid) = 0; virtual RC delete_entry(const char *record, const RID *rid) = 0; virtual IndexScanner *create_scanner(const char *left_key, int left_len, bool left_inclusive, const char *right_key, int right_len, bool right_inclusive) = 0; virtual RC sync() = 0; protected: RC init(const IndexMeta &index_meta, const FieldMeta &field_meta); protected: IndexMeta index_meta_; FieldMeta field_meta_; /// 当前实现仅考虑一个字段的索引 }; class IndexScanner { public: IndexScanner() = default; virtual ~IndexScanner() = default; /** * 遍历元素数据 * 如果没有更多的元素,返回RECORD_EOF */ virtual RC next_entry(RID *rid) = 0; virtual RC destroy() = 0; };