susumu.yata
null+****@clear*****
Tue Dec 2 10:45:39 JST 2014
susumu.yata 2014-12-02 10:45:39 +0900 (Tue, 02 Dec 2014) New Revision: a0b5fff46e425d6de918fcd7674d1dbb6071b82c https://github.com/groonga/grnxx/commit/a0b5fff46e425d6de918fcd7674d1dbb6071b82c Message: Add TreeIndex<Int>::find_in_range(). (#124) Modified files: lib/grnxx/impl/index.cpp Modified: lib/grnxx/impl/index.cpp (+55 -0) =================================================================== --- lib/grnxx/impl/index.cpp 2014-12-02 10:09:05 +0900 (4712027) +++ lib/grnxx/impl/index.cpp 2014-12-02 10:45:39 +0900 (60d2465) @@ -223,6 +223,9 @@ class TreeIndex<Int> : public Index { std::unique_ptr<Cursor> find(const Datum &datum, const CursorOptions &options) const; + std::unique_ptr<Cursor> find_in_range( + const IndexRange &range, + const CursorOptions &options) const; private: mutable Map map_; @@ -295,6 +298,58 @@ std::unique_ptr<Cursor> TreeIndex<Int>::find( } } +std::unique_ptr<Cursor> TreeIndex<Int>::find_in_range( + const IndexRange &range, + const CursorOptions &options) const { + Int lower_bound_value = Int::min(); + // TODO: Datum should provide is_na()? + if (range.lower_bound().value.type() != NA_DATA) { + // TODO: Typecast will be supported in future? + if (range.lower_bound().value.type() != INT_DATA) { + throw "Data type conflict"; // TODO + } + if (!range.lower_bound().value.as_int().is_na()) { + lower_bound_value = range.lower_bound().value.as_int(); + if (range.lower_bound().type == EXCLUSIVE_END_POINT) { + if (lower_bound_value.is_max()) { + return std::unique_ptr<Cursor>(new EmptyCursor); + } + ++lower_bound_value; + } + } + } + + Int upper_bound_value = Int::max(); + if (range.upper_bound().value.type() != NA_DATA) { + if (range.upper_bound().value.type() != INT_DATA) { + throw "Data type conflict"; // TODO + } + if (!range.upper_bound().value.as_int().is_na()) { + upper_bound_value = range.upper_bound().value.as_int(); + if (range.upper_bound().type == EXCLUSIVE_END_POINT) { + if (upper_bound_value.is_min()) { + return std::unique_ptr<Cursor>(new EmptyCursor); + } + --upper_bound_value; + } + } + } + + if ((lower_bound_value > upper_bound_value).is_true()) { + return std::unique_ptr<Cursor>(new EmptyCursor); + } + + auto begin = map_.lower_bound(lower_bound_value); + auto end = map_.upper_bound(upper_bound_value); + if (options.order_type == CURSOR_REGULAR_ORDER) { + return create_range_cursor( + begin, end, options.offset, options.limit); + } else { + return create_reverse_range_cursor( + begin, end, options.offset, options.limit); + } +} + template <> class TreeIndex<Float> : public Index { public: -------------- next part -------------- HTML����������������������������... Download