null+****@clear*****
null+****@clear*****
2011年 6月 19日 (日) 06:18:37 JST
Daijiro MORI 2011-06-18 21:18:37 +0000 (Sat, 18 Jun 2011)
New Revision: a5ce015b6daf40851e0f82c4b5e6d52097fb1ced
Log:
implmented grn_dat_cursor_next()
Modified files:
lib/dat.cpp
lib/dat.h
lib/dat/trie.hpp
Modified: lib/dat.cpp (+38 -3)
===================================================================
--- lib/dat.cpp 2011-06-18 12:17:53 +0000 (c650fdf)
+++ lib/dat.cpp 2011-06-18 21:18:37 +0000 (b62554e)
@@ -258,18 +258,45 @@ grn_dat_cursor_open(grn_ctx *ctx, grn_dat *dat,
const void *max, unsigned int max_size,
int offset, int limit, int flags)
{
- return NULL;
+ grn_dat_cursor *dc = static_cast<grn_dat_cursor *>(GRN_MALLOC(sizeof(grn_dat_cursor)));
+ if (dc) {
+ // Cursor is now an abstract type;
+ // dc->cursor = new grn::dat::Cursor;
+ if (dc->cursor) {
+ dc->dat = dat;
+ /* open stuff */
+ } else {
+ GRN_FREE(dc);
+ dc = NULL;
+ }
+ }
+ return dc;
}
grn_id
grn_dat_cursor_next(grn_ctx *ctx, grn_dat_cursor *c)
{
- return GRN_ID_NIL;
+ grn_id id = GRN_ID_NIL;
+ if (c && c->cursor) {
+ grn::dat::Key k;
+ grn::dat::Cursor *cursor = static_cast<grn::dat::Cursor *>(c->cursor);
+ if (cursor->next(&k)) {
+ id = c->curr_rec = k.id();
+ } else {
+ c->curr_rec = GRN_ID_NIL;
+ }
+ }
+ return id;
}
void
grn_dat_cursor_close(grn_ctx *ctx, grn_dat_cursor *c)
{
+ if (c && c->cursor) {
+ grn::dat::Cursor *cursor = static_cast<grn::dat::Cursor *>(c->cursor);
+ delete cursor;
+ GRN_FREE(c);
+ }
}
int
@@ -281,7 +308,15 @@ grn_dat_cursor_get_key(grn_ctx *ctx, grn_dat_cursor *c, void **key)
grn_id
grn_dat_curr_id(grn_ctx *ctx, grn_dat *dat)
{
- return 0;
+ grn_id id = GRN_ID_NIL;
+ if (dat && dat->header->file_id) {
+ grn_dat_confirm_handle(ctx, dat);
+ grn::dat::Trie *trie = static_cast<grn::dat::Trie *>(dat->handle);
+ if (trie) {
+ id = trie->num_keys();
+ }
+ }
+ return id;
}
const char *
Modified: lib/dat.h (+2 -1)
===================================================================
--- lib/dat.h 2011-06-18 12:17:53 +0000 (ab2996b)
+++ lib/dat.h 2011-06-18 21:18:37 +0000 (f007c06)
@@ -50,8 +50,9 @@ struct grn_dat_header {
struct _grn_dat_cursor {
grn_db_obj obj;
- grn_id curr_rec;
grn_dat *dat;
+ void *cursor;
+ grn_id curr_rec;
};
GRN_API grn_dat *grn_dat_create(grn_ctx *ctx, const char *path, unsigned int key_size,
Modified: lib/dat/trie.hpp (+1 -0)
===================================================================
--- lib/dat/trie.hpp 2011-06-18 12:17:53 +0000 (1b482ca)
+++ lib/dat/trie.hpp 2011-06-18 21:18:37 +0000 (fec3095)
@@ -6,6 +6,7 @@
#include "block.hpp"
#include "key-info.hpp"
#include "key.hpp"
+#include "cursor.hpp"
namespace grn {
namespace dat {