Skip to content

Commit

Permalink
Add skeletons for cursors.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Mar 13, 2013
1 parent 24ffe9c commit 28296af
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
42 changes: 40 additions & 2 deletions lib/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ inline std::ostream &operator<<(std::ostream &stream, const MapKey &key) {
return stream << key.slice();
}

// TODO
class MapCursor {
public:
MapCursor();
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions lib/map/double_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 10 additions & 0 deletions lib/map/double_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit 28296af

Please sign in to comment.