susumu.yata
null+****@clear*****
Mon Dec 1 18:09:38 JST 2014
susumu.yata 2014-12-01 18:09:38 +0900 (Mon, 01 Dec 2014) New Revision: c2d3e0795c2cf4042c6b4e850dd79c3538b34636 https://github.com/groonga/grnxx/commit/c2d3e0795c2cf4042c6b4e850dd79c3538b34636 Message: Add interfaces for searching with index. (#124) Modified files: include/grnxx/index.hpp lib/grnxx/impl/index.cpp lib/grnxx/impl/index.hpp Modified: include/grnxx/index.hpp (+67 -55) =================================================================== --- include/grnxx/index.hpp 2014-12-01 17:49:51 +0900 (c6bbf81) +++ include/grnxx/index.hpp 2014-12-01 18:09:38 +0900 (45a56a1) @@ -12,64 +12,52 @@ namespace grnxx { 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_; -// } +enum EndPointType { + INCLUSIVE_END_POINT, + EXCLUSIVE_END_POINT +}; -// 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; -// } +struct EndPoint { + Datum value; + EndPointType type; -// void unset_lower_bound() { -// has_lower_bound_ = false; -// } -// void unset_upper_bound() { -// has_lower_bound_ = false; -// } + EndPoint() : value(NA()), type(INCLUSIVE_END_POINT) {} +}; -// private: -// bool has_lower_bound_; -// bool has_upper_bound_; -// EndPoint lower_bound_; -// EndPoint upper_bound_; -//}; +class IndexRange { + public: + IndexRange() = default; + ~IndexRange() = default; + + 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) { + lower_bound_.value = value; + lower_bound_.type = type; + } + void set_upper_bound(const Datum &value, + EndPointType type = INCLUSIVE_END_POINT) { + upper_bound_.value = value; + upper_bound_.type = type; + } + + void unset_lower_bound() { + lower_bound_.value = NA(); + } + void unset_upper_bound() { + upper_bound_.value = NA(); + } + + private: + EndPoint lower_bound_; + EndPoint upper_bound_; +}; enum IndexType { // TODO: Tree indexes support range search. @@ -118,6 +106,30 @@ class Index { const Datum &value, const CursorOptions &options = CursorOptions()) const = 0; + // Create a cursor to get records. + // + // On success, returns the cursor. + // On failure, throws an exception. + virtual std::unique_ptr<Cursor> find_in_range( + const IndexRange &range = IndexRange(), + const CursorOptions &options = CursorOptions()) const = 0; + + // Create a cursor to get records. + // + // On success, returns the cursor. + // On failure, throws an exception. + virtual std::unique_ptr<Cursor> find_starts_with( + const EndPoint &prefix, + const CursorOptions &options = CursorOptions()) const = 0; + + // Create a cursor to get records. + // + // On success, returns the cursor. + // On failure, throws an exception. + virtual std::unique_ptr<Cursor> find_prefixes( + const Datum &datum, + const CursorOptions &options = CursorOptions()) const = 0; + protected: virtual ~Index() = default; }; Modified: lib/grnxx/impl/index.cpp (+18 -0) =================================================================== --- lib/grnxx/impl/index.cpp 2014-12-01 17:49:51 +0900 (791df7e) +++ lib/grnxx/impl/index.cpp 2014-12-01 18:09:38 +0900 (f581556) @@ -446,6 +446,24 @@ std::unique_ptr<Cursor> Index::find( throw "Not supported yet"; // TODO } +std::unique_ptr<Cursor> Index::find_in_range( + const IndexRange &range, + const CursorOptions &options) const { + throw "Not supported yet"; // TODO +} + +std::unique_ptr<Cursor> Index::find_starts_with( + const EndPoint &prefix, + const CursorOptions &options) const { + throw "Not supported yet"; // TODO +} + +std::unique_ptr<Cursor> Index::find_prefixes( + const Datum &datum, + const CursorOptions &options) const { + throw "Not supported yet"; // TODO +} + Index *Index::create(ColumnBase *column, const String &name, IndexType type, Modified: lib/grnxx/impl/index.hpp (+9 -0) =================================================================== --- lib/grnxx/impl/index.hpp 2014-12-01 17:49:51 +0900 (edc6cf4) +++ lib/grnxx/impl/index.hpp 2014-12-01 18:09:38 +0900 (08a49e5) @@ -34,6 +34,15 @@ class Index : public IndexInterface { virtual std::unique_ptr<Cursor> find( const Datum &value, const CursorOptions &options = CursorOptions()) const; + virtual std::unique_ptr<Cursor> find_in_range( + const IndexRange &range = IndexRange(), + const CursorOptions &options = CursorOptions()) const; + virtual std::unique_ptr<Cursor> find_starts_with( + const EndPoint &prefix, + const CursorOptions &options = CursorOptions()) const; + virtual std::unique_ptr<Cursor> find_prefixes( + const Datum &datum, + const CursorOptions &options = CursorOptions()) const; // -- Internal API -- -------------- next part -------------- HTML����������������������������... 다운로드