susumu.yata
null+****@clear*****
Tue Apr 9 17:18:16 JST 2013
susumu.yata 2013-04-09 17:18:16 +0900 (Tue, 09 Apr 2013) New Revision: dd97f2e2f94cc5525bdb90ae942c70b3f1c9f3b0 https://github.com/groonga/grnxx/commit/dd97f2e2f94cc5525bdb90ae942c70b3f1c9f3b0 Message: Fix implementations. Modified files: lib/grnxx/alpha/map.cpp lib/grnxx/alpha/map/array.cpp lib/grnxx/alpha/map/array.hpp lib/grnxx/alpha/map/cursor.cpp lib/grnxx/alpha/map/cursor.hpp Modified: lib/grnxx/alpha/map.cpp (+13 -8) =================================================================== --- lib/grnxx/alpha/map.cpp 2013-04-09 16:59:58 +0900 (5c8e595) +++ lib/grnxx/alpha/map.cpp 2013-04-09 17:18:16 +0900 (0e6e425) @@ -170,20 +170,25 @@ void Map<T>::truncate() { } template <typename T> -MapCursor<T> *Map<T>::open_basic_cursor(const MapCursorOptions &) { - // Not supported. - return nullptr; +MapCursor<T> *Map<T>::open_basic_cursor(const MapCursorOptions &options) { + return new (std::nothrow) map::IDCursor<T>(this, -1, -1, options); } template <typename T> -MapCursor<T> *Map<T>::open_id_cursor(int64_t, int64_t, - const MapCursorOptions &) { - // Not supported. - return nullptr; +MapCursor<T> *Map<T>::open_id_cursor(int64_t min, int64_t max, + const MapCursorOptions &options) { + return new (std::nothrow) map::IDCursor<T>(this, min, max, options); } template <typename T> -MapCursor<T> *Map<T>::open_key_cursor(T, T, const MapCursorOptions &) { +MapCursor<T> *Map<T>::open_key_cursor(T min, T max, + const MapCursorOptions &options) { + return new (std::nothrow) map::KeyCursor<T>(this, min, max, options); +} + +template <> +MapCursor<GeoPoint> *Map<GeoPoint>::open_key_cursor(GeoPoint, GeoPoint, + const MapCursorOptions &) { // Not supported. return nullptr; } Modified: lib/grnxx/alpha/map/array.cpp (+0 -41) =================================================================== --- lib/grnxx/alpha/map/array.cpp 2013-04-09 16:59:58 +0900 (4ba6e4d) +++ lib/grnxx/alpha/map/array.cpp 2013-04-09 17:18:16 +0900 (645d4b3) @@ -20,8 +20,6 @@ #include <cmath> #include <string> -#include "grnxx/alpha/map/cursor.hpp" - namespace grnxx { namespace alpha { namespace map { @@ -240,30 +238,6 @@ void Array<T>::truncate() { } template <typename T> -MapCursor<T> *Array<T>::open_basic_cursor(const MapCursorOptions &options) { - return new (std::nothrow) BasicCursor<T>(this, options); -} - -template <typename T> -MapCursor<T> *Array<T>::open_id_cursor(int64_t min, int64_t max, - const MapCursorOptions &options) { - return new (std::nothrow) IDCursor<T>(this, min, max, options); -} - -template <typename T> -MapCursor<T> *Array<T>::open_key_cursor(T min, T max, - const MapCursorOptions &options) { - return new (std::nothrow) KeyCursor<T>(this, min, max, options); -} - -template <> -MapCursor<GeoPoint> *Array<GeoPoint>::open_key_cursor( - GeoPoint, GeoPoint, const MapCursorOptions &) { - // Not supported. - return nullptr; -} - -template <typename T> Array<T>::Array() : pool_(), block_info_(nullptr), @@ -440,21 +414,6 @@ void Array<Slice>::truncate() { header_->max_key_id = -1; } -MapCursor<Slice> *Array<Slice>::open_basic_cursor( - const MapCursorOptions &options) { - return new (std::nothrow) BasicCursor<Slice>(this, options); -} - -MapCursor<Slice> *Array<Slice>::open_id_cursor( - int64_t min, int64_t max, const MapCursorOptions &options) { - return new (std::nothrow) IDCursor<Slice>(this, min, max, options); -} - -MapCursor<Slice> *Array<Slice>::open_key_cursor( - Slice min, Slice max, const MapCursorOptions &options) { - return new (std::nothrow) KeyCursor<Slice>(this, min, max, options); -} - Array<Slice>::Array() : pool_(), block_info_(nullptr), Modified: lib/grnxx/alpha/map/array.hpp (+0 -14) =================================================================== --- lib/grnxx/alpha/map/array.hpp 2013-04-09 16:59:58 +0900 (5307c8f) +++ lib/grnxx/alpha/map/array.hpp 2013-04-09 17:18:16 +0900 (e3def13) @@ -62,13 +62,6 @@ class Array : public grnxx::alpha::Map<T> { void truncate(); - MapCursor<T> *open_basic_cursor( - const MapCursorOptions &options = MapCursorOptions()); - MapCursor<T> *open_id_cursor(int64_t min, int64_t max, - const MapCursorOptions &options = MapCursorOptions()); - MapCursor<T> *open_key_cursor(T min, T max, - const MapCursorOptions &options = MapCursorOptions()); - private: io::Pool pool_; const io::BlockInfo *block_info_; @@ -117,13 +110,6 @@ class Array<Slice> : public grnxx::alpha::Map<Slice> { void truncate(); - MapCursor<Slice> *open_basic_cursor( - const MapCursorOptions &options = MapCursorOptions()); - MapCursor<Slice> *open_id_cursor(int64_t min, int64_t max, - const MapCursorOptions &options = MapCursorOptions()); - MapCursor<Slice> *open_key_cursor(Slice min, Slice max, - const MapCursorOptions &options = MapCursorOptions()); - private: io::Pool pool_; const io::BlockInfo *block_info_; Modified: lib/grnxx/alpha/map/cursor.cpp (+24 -63) =================================================================== --- lib/grnxx/alpha/map/cursor.cpp 2013-04-09 16:59:58 +0900 (adbf817) +++ lib/grnxx/alpha/map/cursor.cpp 2013-04-09 17:18:16 +0900 (976fd6c) @@ -22,68 +22,6 @@ namespace alpha { namespace map { template <typename T> -BasicCursor<T>::BasicCursor(Map<T> *map, const MapCursorOptions &options) - : MapCursor<T>(), map_(map), end_(), step_(), left_(options.limit) { - // TODO? -// if (options.flags & MAP_CURSOR_ORDER_BY_ID) { -// } else if (options.flags & MAP_CURSOR_ORDER_BY_KEY) { -// } - - if (~options.flags & MAP_CURSOR_REVERSE_ORDER) { - this->key_id_ = -1; - end_ = map_->max_key_id(); - step_ = 1; - } else { - this->key_id_ = map_->max_key_id() + 1; - end_ = 0; - step_ = -1; - } - - uint64_t count = 0; - while ((count < options.offset) && (this->key_id_ != end_)) { - this->key_id_ += step_; - if (map_->get(this->key_id_)) { - ++count; - } - } -} - -template <typename T> -BasicCursor<T>::~BasicCursor() {} - -template <typename T> -bool BasicCursor<T>::next() { - if (left_ == 0) { - return false; - } - while (this->key_id_ != end_) { - this->key_id_ += step_; - if (map_->get(this->key_id_, &this->key_)) { - --left_; - return true; - } - } - return false; -} - -template <typename T> -bool BasicCursor<T>::remove() { - return map_->unset(this->key_id_); -} - -template class BasicCursor<int8_t>; -template class BasicCursor<int16_t>; -template class BasicCursor<int32_t>; -template class BasicCursor<int64_t>; -template class BasicCursor<uint8_t>; -template class BasicCursor<uint16_t>; -template class BasicCursor<uint32_t>; -template class BasicCursor<uint64_t>; -template class BasicCursor<double>; -template class BasicCursor<GeoPoint>; -template class BasicCursor<Slice>; - -template <typename T> IDCursor<T>::IDCursor(Map<T> *map, int64_t min, int64_t max, const MapCursorOptions &options) : MapCursor<T>(), map_(map), end_(), step_(), left_(options.limit) { @@ -98,7 +36,7 @@ IDCursor<T>::IDCursor(Map<T> *map, int64_t min, int64_t max, ++min; } - if (max > map_->max_key_id()) { + if ((max < 0) || (max > map_->max_key_id())) { max = map_->max_key_id(); } else if (options.flags & MAP_CURSOR_EXCEPT_MAX) { --max; @@ -235,6 +173,29 @@ bool KeyCursor<T>::in_range(T key) const { return true; } +template <> +bool KeyCursor<Slice>::in_range(Slice key) const { + if (flags_ & MAP_CURSOR_EXCEPT_MIN) { + if (key <= min_) { + return false; + } + } else if (key < min_) { + return false; + } + + if (max_) { + if (flags_ & MAP_CURSOR_EXCEPT_MAX) { + if (key >= max_) { + return false; + } + } else if (key > max_) { + return false; + } + } + + return true; +} + template class KeyCursor<int8_t>; template class KeyCursor<int16_t>; template class KeyCursor<int32_t>; Modified: lib/grnxx/alpha/map/cursor.hpp (+0 -16) =================================================================== --- lib/grnxx/alpha/map/cursor.hpp 2013-04-09 16:59:58 +0900 (ee37a72) +++ lib/grnxx/alpha/map/cursor.hpp 2013-04-09 17:18:16 +0900 (4d41e2c) @@ -25,22 +25,6 @@ namespace alpha { namespace map { template <typename T> -class BasicCursor : public MapCursor<T> { - public: - explicit BasicCursor(Map<T> *map, const MapCursorOptions &options); - ~BasicCursor(); - - bool next(); - bool remove(); - - private: - Map<T> *map_; - int64_t end_; - int64_t step_; - uint64_t left_; -}; - -template <typename T> class IDCursor : public MapCursor<T> { public: explicit IDCursor(Map<T> *map, int64_t min, int64_t max, -------------- next part -------------- HTML����������������������������...Download