Kouhei Sutou
null+****@clear*****
Thu Feb 5 11:44:01 JST 2015
Kouhei Sutou 2015-02-05 11:44:01 +0900 (Thu, 05 Feb 2015) New Revision: 699567d6d656ff74fe0d785498d7389b3a90c5bc https://github.com/groonga/groonga/commit/699567d6d656ff74fe0d785498d7389b3a90c5bc Message: mrb: add TableCursor#count Modified files: lib/mrb/mrb_table_cursor.c Modified: lib/mrb/mrb_table_cursor.c (+15 -0) =================================================================== --- lib/mrb/mrb_table_cursor.c 2015-02-05 11:09:38 +0900 (4b9690d) +++ lib/mrb/mrb_table_cursor.c 2015-02-05 11:44:01 +0900 (d23f33e) @@ -127,6 +127,19 @@ mrb_grn_table_cursor_next(mrb_state *mrb, mrb_value self) return mrb_fixnum_value(id); } +static mrb_value +mrb_grn_table_cursor_count(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + int n_records = 0; + + while (grn_table_cursor_next(ctx, DATA_PTR(self)) != GRN_ID_NIL) { + n_records++; + } + + return mrb_fixnum_value(n_records); +} + void grn_mrb_table_cursor_init(grn_ctx *ctx) { @@ -148,5 +161,7 @@ grn_mrb_table_cursor_init(grn_ctx *ctx) mrb_grn_table_cursor_close, MRB_ARGS_NONE()); mrb_define_method(mrb, klass, "next", mrb_grn_table_cursor_next, MRB_ARGS_NONE()); + mrb_define_method(mrb, klass, "count", + mrb_grn_table_cursor_count, MRB_ARGS_NONE()); } #endif -------------- next part -------------- HTML����������������������������...Download