susumu.yata
null+****@clear*****
Wed Mar 13 15:55:44 JST 2013
susumu.yata 2013-03-13 15:55:44 +0900 (Wed, 13 Mar 2013) New Revision: 28296af0618ce76fb35a86f258f806a00a7e3238 https://github.com/groonga/grnxx/commit/28296af0618ce76fb35a86f258f806a00a7e3238 Message: Add skeletons for cursors. Modified files: lib/map.hpp lib/map/double_array.cpp lib/map/double_array.hpp Modified: lib/map.hpp (+40 -2) =================================================================== --- lib/map.hpp 2013-03-13 10:17:11 +0900 (f6f9a76) +++ lib/map.hpp 2013-03-13 15:55:44 +0900 (934ae29) @@ -125,7 +125,6 @@ inline std::ostream &operator<<(std::ostream &stream, const MapKey &key) { return stream << key.slice(); } -// TODO class MapCursor { public: MapCursor(); @@ -152,6 +151,24 @@ class MapCursor { MapKey key_; }; +typedef FlagsImpl<MapCursor> MapCursorFlags; + +// Get keys in ascending order. +constexpr MapCursorFlags MAP_CURSOR_ASCENDING = + MapCursorFlags::define(0x01); +// Get keys in descending order. +constexpr MapCursorFlags MAP_CURSOR_DESCENDING = + MapCursorFlags::define(0x02); +// Get keys except the begin. +constexpr MapCursorFlags MAP_CURSOR_EXCEPT_BEGIN = + MapCursorFlags::define(0x10); +// Get keys except the end. +constexpr MapCursorFlags MAP_CURSOR_EXCEPT_END = + MapCursorFlags::define(0x20); +// Get keys except the exact match. +constexpr MapCursorFlags MAP_CURSOR_EXCEPT_QUERY = + MapCursorFlags::define(0x40); + class MapScan { public: ~MapScan(); @@ -247,7 +264,28 @@ class Map { // The object must be deleted after the scan. MapScan *open_scan(const Slice &query, const Charset *charset = nullptr); - // TODO + // Find keys in an ID range ["begin", "end"] and return the keys in ID order. + // "flags" accepts MAP_CURSOR_ASCENDING, MAP_CURSOR_DESCENDING, + // MAP_CURSOR_EXCEPT_BEGIN, and MAP_CURSOR_EXCEPT_END. + virtual MapCursor *open_id_cursor(MapCursorFlags flags, + int64_t begin, int64_t end, + int64_t offset, int64_t limit) = 0; + // Find keys in a range ["begin", "end"] and return the keys in lexicographic + // order. "flags" accepts MAP_CURSOR_ASCENDING, MAP_CURSOR_DESCENDING, + // MAP_CURSOR_EXCEPT_BEGIN, and MAP_CURSOR_EXCEPT_END. + virtual MapCursor *open_key_cursor(MapCursorFlags flags, + const Slice &begin, const Slice &end, + int64_t offset, int64_t limit) = 0; + // Find keys in prefixes of "query". "flags" accepts MAP_CURSOR_ASCENDING, + // MAP_CURSOR_DESCENDING, and MAP_CURSOR_EXCEPT_QUERY. + virtual MapCursor *open_prefix_cursor(MapCursorFlags flags, + const Slice &query, + int64_t offset, int64_t limit) = 0; + // Find keys starting with "query". "flags" accepts MAP_CURSOR_ASCENDING, + // MAP_CURSOR_DESCENDING, and MAP_CURSOR_EXCEPT_QUERY. + virtual MapCursor *open_predictive_cursor(MapCursorFlags flags, + const Slice &query, + int64_t offset, int64_t limit) = 0; }; } // namespace grnxx Modified: lib/map/double_array.cpp (+28 -0) =================================================================== --- lib/map/double_array.cpp 2013-03-13 10:17:11 +0900 (104aeee) +++ lib/map/double_array.cpp 2013-03-13 15:55:44 +0900 (b772820) @@ -154,6 +154,34 @@ bool DoubleArray::update(const Slice &src_key, const Slice &dest_key, } } +MapCursor *DoubleArray::open_id_cursor(MapCursorFlags flags, + int64_t begin, int64_t end, + int64_t offset, int64_t limit) { + // TODO + return nullptr; +} + +MapCursor *DoubleArray::open_key_cursor(MapCursorFlags flags, + const Slice &begin, const Slice &end, + int64_t offset, int64_t limit) { + // TODO + return nullptr; +} + +MapCursor *DoubleArray::open_prefix_cursor(MapCursorFlags flags, + const Slice &query, + int64_t offset, int64_t limit) { + // TODO + return nullptr; +} + +MapCursor *DoubleArray::open_predictive_cursor(MapCursorFlags flags, + const Slice &query, + int64_t offset, int64_t limit) { + // TODO + return nullptr; +} + DoubleArray::DoubleArray() : pool_(), block_info_(nullptr), Modified: lib/map/double_array.hpp (+10 -0) =================================================================== --- lib/map/double_array.hpp 2013-03-13 10:17:11 +0900 (035e366) +++ lib/map/double_array.hpp 2013-03-13 15:55:44 +0900 (fe3c837) @@ -58,6 +58,16 @@ class DoubleArray : public Map { bool update(const Slice &src_key, const Slice &dest_key, int64_t *key_id = nullptr); + MapCursor *open_id_cursor(MapCursorFlags flags, int64_t begin, int64_t end, + int64_t offset, int64_t limit); + MapCursor *open_key_cursor(MapCursorFlags flags, + const Slice &begin, const Slice &end, + int64_t offset, int64_t limit); + MapCursor *open_prefix_cursor(MapCursorFlags flags, const Slice &query, + int64_t offset, int64_t limit); + MapCursor *open_predictive_cursor(MapCursorFlags flags, const Slice &query, + int64_t offset, int64_t limit); + private: io::Pool pool_; const io::BlockInfo *block_info_; -------------- next part -------------- HTML����������������������������...下载