Kouhei Sutou
null+****@clear*****
Sun Dec 28 21:22:34 JST 2014
Kouhei Sutou 2014-12-28 21:22:34 +0900 (Sun, 28 Dec 2014) New Revision: ea2aa21e966164a77b70b17ba07efef8b8b68940 https://github.com/groonga/groonga/commit/ea2aa21e966164a77b70b17ba07efef8b8b68940 Message: mrb: add HashTable Added files: lib/mrb/mrb_hash_table.c lib/mrb/mrb_hash_table.h Modified files: lib/ctx_impl_mrb.c lib/mrb/mrb_converter.c lib/mrb/sources.am Modified: lib/ctx_impl_mrb.c (+2 -0) =================================================================== --- lib/ctx_impl_mrb.c 2014-12-28 21:19:39 +0900 (0f9ef2a) +++ lib/ctx_impl_mrb.c 2014-12-28 21:22:34 +0900 (6d0a435) @@ -32,6 +32,7 @@ #include "mrb/mrb_object.h" #include "mrb/mrb_database.h" #include "mrb/mrb_table.h" +#include "mrb/mrb_hash_table.h" #include "mrb/mrb_patricia_trie.h" #include "mrb/mrb_column.h" #include "mrb/mrb_fixed_size_column.h" @@ -103,6 +104,7 @@ grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx) grn_mrb_object_init(ctx); grn_mrb_database_init(ctx); grn_mrb_table_init(ctx); + grn_mrb_hash_table_init(ctx); grn_mrb_patricia_trie_init(ctx); grn_mrb_column_init(ctx); grn_mrb_fixed_size_column_init(ctx); Modified: lib/mrb/mrb_converter.c (+3 -0) =================================================================== --- lib/mrb/mrb_converter.c 2014-12-28 21:19:39 +0900 (034727b) +++ lib/mrb/mrb_converter.c 2014-12-28 21:22:34 +0900 (6ecfabf) @@ -58,6 +58,9 @@ grn_mrb_class_from_grn_obj(mrb_state *mrb, grn_obj *object) case GRN_EXPR : klass = mrb_class_get_under(mrb, data->module, "Expression"); break; + case GRN_TABLE_HASH_KEY : + klass = mrb_class_get_under(mrb, data->module, "HashTable"); + break; case GRN_TABLE_PAT_KEY : klass = mrb_class_get_under(mrb, data->module, "PatriciaTrie"); break; Added: lib/mrb/mrb_hash_table.c (+60 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_hash_table.c 2014-12-28 21:22:34 +0900 (a5a4e79) @@ -0,0 +1,60 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2014 Brazil + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "../grn_ctx_impl.h" + +#ifdef GRN_WITH_MRUBY +#include <mruby.h> +#include <mruby/class.h> +#include <mruby/data.h> + +#include "mrb_hash_table.h" + +static struct mrb_data_type mrb_grn_hash_table_type = { + "Groonga::HashTable", + NULL +}; + +static mrb_value +mrb_grn_hash_table_initialize(mrb_state *mrb, mrb_value self) +{ + mrb_value mrb_hash_table_ptr; + + mrb_get_args(mrb, "o", &mrb_hash_table_ptr); + DATA_TYPE(self) = &mrb_grn_hash_table_type; + DATA_PTR(self) = mrb_cptr(mrb_hash_table_ptr); + return self; +} + +void +grn_mrb_hash_table_init(grn_ctx *ctx) +{ + grn_mrb_data *data = &(ctx->impl->mrb); + mrb_state *mrb = data->state; + struct RClass *module = data->module; + struct RClass *table_class; + struct RClass *klass; + + table_class = mrb_class_get_under(mrb, module, "Table"); + klass = mrb_define_class_under(mrb, module, "HashTable", table_class); + MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA); + + mrb_define_method(mrb, klass, "initialize", + mrb_grn_hash_table_initialize, MRB_ARGS_REQ(1)); +} +#endif Added: lib/mrb/mrb_hash_table.h (+34 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_hash_table.h 2014-12-28 21:22:34 +0900 (223267b) @@ -0,0 +1,34 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2014 Brazil + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef GRN_MRB_HASH_TABLE_H +#define GRN_MRB_HASH_TABLE_H + +#include "../grn_ctx.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void grn_mrb_hash_table_init(grn_ctx *ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* GRN_MRB_HASH_TABLE_H */ Modified: lib/mrb/sources.am (+2 -0) =================================================================== --- lib/mrb/sources.am 2014-12-28 21:19:39 +0900 (34d9763) +++ lib/mrb/sources.am 2014-12-28 21:22:34 +0900 (22b3a97) @@ -17,6 +17,8 @@ libgrnmrb_la_SOURCES = \ mrb_expr.h \ mrb_fixed_size_column.c \ mrb_fixed_size_column.h \ + mrb_hash_table.c \ + mrb_hash_table.h \ mrb_id.c \ mrb_id.h \ mrb_index_column.c \ -------------- next part -------------- HTML����������������������������...Download