diff --git a/include/grnxx/Makefile.am b/include/grnxx/Makefile.am index 1d9b0e1..0ddf15b 100644 --- a/include/grnxx/Makefile.am +++ b/include/grnxx/Makefile.am @@ -10,12 +10,12 @@ pkginclude_HEADERS = \ db.hpp \ error.hpp \ features.hpp \ + index.hpp \ library.hpp \ string.hpp \ table.hpp # expression.hpp \ -# index.hpp \ # merger.hpp \ # pipeline.hpp \ # sorter.hpp diff --git a/include/grnxx/index.hpp b/include/grnxx/index.hpp index ab70f7b..97c99c3 100644 --- a/include/grnxx/index.hpp +++ b/include/grnxx/index.hpp @@ -1,199 +1,211 @@ #ifndef GRNXX_INDEX_HPP #define GRNXX_INDEX_HPP -#include "grnxx/name.hpp" -#include "grnxx/types.hpp" +#include -namespace grnxx { -namespace impl { - -class ColumnBase; - -} // namespace impl +#include "grnxx/cursor.hpp" +#include "grnxx/data_types.hpp" +#include "grnxx/index.hpp" +#include "grnxx/string.hpp" -enum EndPointType { - INCLUSIVE_END_POINT, - EXCLUSIVE_END_POINT -}; +namespace grnxx { -struct EndPoint { - Datum value; - EndPointType type; +class Column; + +//enum EndPointType { +// INCLUSIVE_END_POINT, +// EXCLUSIVE_END_POINT +//}; + +//struct EndPoint { +// Datum value; +// EndPointType type; +//}; + +//class IndexRange { +// public: +// IndexRange() +// : has_lower_bound_(false), +// has_upper_bound_(false), +// lower_bound_(), +// upper_bound_() {} + +// bool has_lower_bound() const { +// return has_lower_bound_; +// } +// bool has_upper_bound() const { +// return has_upper_bound_; +// } + +// const EndPoint &lower_bound() const { +// return lower_bound_; +// } +// const EndPoint &upper_bound() const { +// return upper_bound_; +// } + +// void set_lower_bound(const Datum &value, +// EndPointType type = INCLUSIVE_END_POINT) { +// has_lower_bound_ = true; +// lower_bound_.value = value; +// lower_bound_.type = type; +// } +// void set_upper_bound(const Datum &value, +// EndPointType type = INCLUSIVE_END_POINT) { +// has_upper_bound_ = true; +// upper_bound_.value = value; +// upper_bound_.type = type; +// } + +// void unset_lower_bound() { +// has_lower_bound_ = false; +// } +// void unset_upper_bound() { +// has_lower_bound_ = false; +// } + +// private: +// bool has_lower_bound_; +// bool has_upper_bound_; +// EndPoint lower_bound_; +// EndPoint upper_bound_; +//}; + +enum IndexType { + // TODO: Tree indexes support range search. + TREE_INDEX, + // TODO: Hash indexes support exact match search. + HASH_INDEX }; -class IndexRange { - public: - IndexRange() - : has_lower_bound_(false), - has_upper_bound_(false), - lower_bound_(), - upper_bound_() {} - - bool has_lower_bound() const { - return has_lower_bound_; - } - bool has_upper_bound() const { - return has_upper_bound_; - } - - const EndPoint &lower_bound() const { - return lower_bound_; - } - const EndPoint &upper_bound() const { - return upper_bound_; - } - - void set_lower_bound(const Datum &value, - EndPointType type = INCLUSIVE_END_POINT) { - has_lower_bound_ = true; - lower_bound_.value = value; - lower_bound_.type = type; - } - void set_upper_bound(const Datum &value, - EndPointType type = INCLUSIVE_END_POINT) { - has_upper_bound_ = true; - upper_bound_.value = value; - upper_bound_.type = type; - } - - void unset_lower_bound() { - has_lower_bound_ = false; - } - void unset_upper_bound() { - has_lower_bound_ = false; - } - - private: - bool has_lower_bound_; - bool has_upper_bound_; - EndPoint lower_bound_; - EndPoint upper_bound_; +struct IndexOptions { }; class Index { public: - virtual ~Index(); - - // Return the owner column. - Column *column() const { - return column_; - } - // Return the name. - StringCRef name() const { - return name_.ref(); - } - // Return the index type. - IndexType type() const { - return type_; - } - - // Check if "datum" is registered or not. - // - // If registered, returns true. - // Otherwise, returns false. - virtual bool contains(const Datum &datum) const; - - // Search the index for "datum". - // - // On success, returns the row ID of one of the matched values. - // On failure, returns NULL_ROW_ID. - virtual Int find_one(const Datum &datum) const; - - // Create a cursor to get records. - // - // On success, returns a pointer to the cursor. - // On failure, returns nullptr and stores error information into "*error" if - // "error" != nullptr. - virtual unique_ptr find( - Error *error, - const Datum &datum, - const CursorOptions &options = CursorOptions()) const; - - // Create a cursor to get records. - // - // Returns a pointer to the cursor on success. - // On failure, returns nullptr and stores error information into "*error" if - // "error" != nullptr. - virtual unique_ptr find_in_range( - Error *error, - const IndexRange &range = IndexRange(), - const CursorOptions &options = CursorOptions()) const; - - // Create a cursor to get records. - // - // Returns a pointer to the cursor on success. - // On failure, returns nullptr and stores error information into "*error" if - // "error" != nullptr. - virtual unique_ptr find_starts_with( - Error *error, - const EndPoint &prefix, - const CursorOptions &options = CursorOptions()) const; - - // Create a cursor to get records. - // - // Returns a pointer to the cursor on success. - // On failure, returns nullptr and stores error information into "*error" if - // "error" != nullptr. - virtual unique_ptr find_prefixes( - Error *error, - const Datum &datum, - const CursorOptions &options = CursorOptions()) const; - - // Insert a new entry. - // - // On success, returns true. - // On failure, returns false and stores error information into "*error" if - // "error" != nullptr. - virtual bool insert(Error *error, Int row_id, const Datum &value) = 0; - // Insert an entry. - // - // On success, returns true. - // On failure, returns false and stores error information into "*error" if - // "error" != nullptr. - virtual bool remove(Error *error, Int row_id, const Datum &value) = 0; + virtual ~Index() = default; + +// // Return the owner column. +// Column *column() const { +// return column_; +// } +// // Return the name. +// StringCRef name() const { +// return name_.ref(); +// } +// // Return the index type. +// IndexType type() const { +// return type_; +// } + +// // Check if "datum" is registered or not. +// // +// // If registered, returns true. +// // Otherwise, returns false. +// virtual bool contains(const Datum &datum) const; + +// // Search the index for "datum". +// // +// // On success, returns the row ID of one of the matched values. +// // On failure, returns NULL_ROW_ID. +// virtual Int find_one(const Datum &datum) const; + +// // Create a cursor to get records. +// // +// // On success, returns a pointer to the cursor. +// // On failure, returns nullptr and stores error information into "*error" if +// // "error" != nullptr. +// virtual unique_ptr find( +// Error *error, +// const Datum &datum, +// const CursorOptions &options = CursorOptions()) const; + +// // Create a cursor to get records. +// // +// // Returns a pointer to the cursor on success. +// // On failure, returns nullptr and stores error information into "*error" if +// // "error" != nullptr. +// virtual unique_ptr find_in_range( +// Error *error, +// const IndexRange &range = IndexRange(), +// const CursorOptions &options = CursorOptions()) const; + +// // Create a cursor to get records. +// // +// // Returns a pointer to the cursor on success. +// // On failure, returns nullptr and stores error information into "*error" if +// // "error" != nullptr. +// virtual unique_ptr find_starts_with( +// Error *error, +// const EndPoint &prefix, +// const CursorOptions &options = CursorOptions()) const; + +// // Create a cursor to get records. +// // +// // Returns a pointer to the cursor on success. +// // On failure, returns nullptr and stores error information into "*error" if +// // "error" != nullptr. +// virtual unique_ptr find_prefixes( +// Error *error, +// const Datum &datum, +// const CursorOptions &options = CursorOptions()) const; + +// // Insert a new entry. +// // +// // On success, returns true. +// // On failure, returns false and stores error information into "*error" if +// // "error" != nullptr. +// virtual bool insert(Error *error, Int row_id, const Datum &value) = 0; +// // Insert an entry. +// // +// // On success, returns true. +// // On failure, returns false and stores error information into "*error" if +// // "error" != nullptr. +// virtual bool remove(Error *error, Int row_id, const Datum &value) = 0; + +// protected: +// Column *column_; +// Name name_; +// IndexType type_; + +// Index(); + +// // Initialize the base members. +// // +// // On success, returns true. +// // On failure, returns false and stores error information into "*error" if +// // "error" != nullptr. +// bool initialize_base(Error *error, +// Column *column, +// const StringCRef &name, +// IndexType type, +// const IndexOptions &options); + +// private: +// // Create a new index. +// // +// // Returns a pointer to the index on success. +// // On failure, returns nullptr and stores error information into "*error" if +// // "error" != nullptr. +// static unique_ptr create( +// Error *error, +// Column *column, +// const StringCRef &name, +// IndexType type, +// const IndexOptions &options = IndexOptions()); + +// // Change the index name. +// // +// // Returns true on success. +// // On failure, returns false and stores error information into "*error" if +// // "error" != nullptr. +// bool rename(Error *error, const StringCRef &new_name); + +// // Return whether the index is removable or not. +// bool is_removable(); protected: - Column *column_; - Name name_; - IndexType type_; - - Index(); - - // Initialize the base members. - // - // On success, returns true. - // On failure, returns false and stores error information into "*error" if - // "error" != nullptr. - bool initialize_base(Error *error, - Column *column, - const StringCRef &name, - IndexType type, - const IndexOptions &options); - - private: - // Create a new index. - // - // Returns a pointer to the index on success. - // On failure, returns nullptr and stores error information into "*error" if - // "error" != nullptr. - static unique_ptr create( - Error *error, - Column *column, - const StringCRef &name, - IndexType type, - const IndexOptions &options = IndexOptions()); - - // Change the index name. - // - // Returns true on success. - // On failure, returns false and stores error information into "*error" if - // "error" != nullptr. - bool rename(Error *error, const StringCRef &new_name); - - // Return whether the index is removable or not. - bool is_removable(); - - friend class impl::ColumnBase; + Index() = default; }; } // namespace grnxx