groonga 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.ja.rdoc +18 -3
- data/NEWS.rdoc +18 -3
- data/README.ja.rdoc +2 -0
- data/README.rdoc +2 -0
- data/Rakefile +14 -5
- data/TUTORIAL.ja.rdoc +82 -16
- data/benchmark/{read-write-small-many-items.rb → read-write-many-small-items.rb} +26 -23
- data/benchmark/{write-small-many-items.rb → write-many-small-items.rb} +26 -23
- data/example/bookmark.rb +49 -5
- data/ext/rb-grn-array.c +11 -1
- data/ext/rb-grn-column.c +132 -5
- data/ext/rb-grn-context.c +85 -80
- data/ext/rb-grn-database.c +182 -9
- data/ext/rb-grn-expression-builder.c +69 -0
- data/ext/rb-grn-expression.c +314 -0
- data/ext/rb-grn-fix-size-column.c +68 -89
- data/ext/rb-grn-hash.c +14 -5
- data/ext/rb-grn-index-column.c +14 -55
- data/ext/rb-grn-object.c +206 -75
- data/ext/rb-grn-operation.c +92 -0
- data/ext/rb-grn-patricia-trie.c +10 -32
- data/ext/rb-grn-query.c +9 -9
- data/ext/rb-grn-table-cursor.c +19 -80
- data/ext/rb-grn-table-key-support.c +33 -39
- data/ext/rb-grn-table.c +436 -79
- data/ext/rb-grn-type.c +10 -3
- data/ext/rb-grn-utils.c +131 -4
- data/ext/rb-grn-variable-size-column.c +36 -0
- data/ext/rb-grn-variable.c +90 -0
- data/ext/rb-grn.h +109 -56
- data/ext/rb-groonga.c +4 -0
- data/extconf.rb +39 -13
- data/html/index.html +2 -2
- data/lib/groonga.rb +22 -0
- data/lib/groonga/expression-builder.rb +141 -0
- data/lib/groonga/record.rb +25 -1
- data/lib/groonga/schema.rb +418 -0
- data/test/test-column.rb +11 -23
- data/test/test-context.rb +1 -1
- data/test/test-database.rb +60 -19
- data/test/test-expression-builder.rb +114 -0
- data/test/test-expression.rb +55 -0
- data/test/test-fix-size-column.rb +53 -0
- data/test/test-hash.rb +10 -3
- data/test/test-index-column.rb +24 -0
- data/test/test-patricia-trie.rb +9 -0
- data/test/test-procedure.rb +5 -5
- data/test/test-record.rb +71 -4
- data/test/test-schema.rb +207 -0
- data/test/test-table.rb +94 -12
- data/test/test-type.rb +18 -11
- data/test/test-variable-size-column.rb +53 -0
- data/test/test-variable.rb +28 -0
- metadata +18 -5
@@ -0,0 +1,69 @@
|
|
1
|
+
/* -*- c-file-style: "ruby" -*- */
|
2
|
+
/*
|
3
|
+
Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
|
5
|
+
This library is free software; you can redistribute it and/or
|
6
|
+
modify it under the terms of the GNU Lesser General Public
|
7
|
+
License version 2.1 as published by the Free Software Foundation.
|
8
|
+
|
9
|
+
This library is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public
|
15
|
+
License along with this library; if not, write to the Free Software
|
16
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "rb-grn.h"
|
20
|
+
|
21
|
+
VALUE rb_cGrnRecordExpressionBuilder;
|
22
|
+
VALUE rb_cGrnColumnExpressionBuilder;
|
23
|
+
|
24
|
+
VALUE
|
25
|
+
rb_grn_record_expression_builder_new (VALUE table, VALUE name)
|
26
|
+
{
|
27
|
+
return rb_funcall(rb_cGrnRecordExpressionBuilder,
|
28
|
+
rb_intern("new"), 2, table, name);
|
29
|
+
}
|
30
|
+
|
31
|
+
VALUE
|
32
|
+
rb_grn_column_expression_builder_new (VALUE column, VALUE name, VALUE query)
|
33
|
+
{
|
34
|
+
return rb_funcall(rb_cGrnColumnExpressionBuilder,
|
35
|
+
rb_intern("new"), 3, column, name, query);
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE
|
39
|
+
build (VALUE self)
|
40
|
+
{
|
41
|
+
return rb_funcall(self, rb_intern("build"), 0);
|
42
|
+
}
|
43
|
+
|
44
|
+
static VALUE
|
45
|
+
build_block (VALUE self)
|
46
|
+
{
|
47
|
+
return rb_funcall(rb_block_proc(), rb_intern("call"), 1, self);
|
48
|
+
}
|
49
|
+
|
50
|
+
VALUE
|
51
|
+
rb_grn_record_expression_builder_build (VALUE self)
|
52
|
+
{
|
53
|
+
return rb_iterate(build, self, build_block, self);
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE
|
57
|
+
rb_grn_column_expression_builder_build (VALUE self)
|
58
|
+
{
|
59
|
+
return rb_iterate(build, self, build_block, self);
|
60
|
+
}
|
61
|
+
|
62
|
+
void
|
63
|
+
rb_grn_init_expression_builder (VALUE mGrn)
|
64
|
+
{
|
65
|
+
rb_cGrnRecordExpressionBuilder =
|
66
|
+
rb_const_get(mGrn, rb_intern("RecordExpressionBuilder"));
|
67
|
+
rb_cGrnColumnExpressionBuilder =
|
68
|
+
rb_const_get(mGrn, rb_intern("ColumnExpressionBuilder"));
|
69
|
+
}
|
@@ -0,0 +1,314 @@
|
|
1
|
+
/* -*- c-file-style: "ruby" -*- */
|
2
|
+
/*
|
3
|
+
Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
|
5
|
+
This library is free software; you can redistribute it and/or
|
6
|
+
modify it under the terms of the GNU Lesser General Public
|
7
|
+
License version 2.1 as published by the Free Software Foundation.
|
8
|
+
|
9
|
+
This library is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public
|
15
|
+
License along with this library; if not, write to the Free Software
|
16
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "rb-grn.h"
|
20
|
+
|
21
|
+
#define SELF(object) ((RbGrnExpression *)DATA_PTR(object))
|
22
|
+
|
23
|
+
VALUE rb_cGrnExpression;
|
24
|
+
|
25
|
+
void
|
26
|
+
rb_grn_expression_finalizer (grn_ctx *context, grn_obj *object,
|
27
|
+
RbGrnExpression *rb_grn_expression)
|
28
|
+
{
|
29
|
+
if (!context)
|
30
|
+
return;
|
31
|
+
|
32
|
+
grn_obj_close(context, rb_grn_expression->value);
|
33
|
+
}
|
34
|
+
|
35
|
+
void
|
36
|
+
rb_grn_expression_bind (RbGrnExpression *rb_grn_expression,
|
37
|
+
grn_ctx *context, grn_obj *expression)
|
38
|
+
{
|
39
|
+
RbGrnObject *rb_grn_object;
|
40
|
+
|
41
|
+
rb_grn_object = RB_GRN_OBJECT(rb_grn_expression);
|
42
|
+
|
43
|
+
rb_grn_expression->value = grn_obj_open(context, GRN_BULK, 0,
|
44
|
+
rb_grn_object->range_id);
|
45
|
+
}
|
46
|
+
|
47
|
+
void
|
48
|
+
rb_grn_expression_deconstruct (RbGrnExpression *rb_grn_expression,
|
49
|
+
grn_obj **expression,
|
50
|
+
grn_ctx **context,
|
51
|
+
grn_id *domain_id,
|
52
|
+
grn_obj **domain,
|
53
|
+
grn_obj **value,
|
54
|
+
grn_id *range_id,
|
55
|
+
grn_obj **range)
|
56
|
+
{
|
57
|
+
RbGrnObject *rb_grn_object;
|
58
|
+
|
59
|
+
rb_grn_object = RB_GRN_OBJECT(rb_grn_expression);
|
60
|
+
rb_grn_object_deconstruct(rb_grn_object, expression, context,
|
61
|
+
domain_id, domain,
|
62
|
+
range_id, range);
|
63
|
+
|
64
|
+
if (value)
|
65
|
+
*value = rb_grn_expression->value;
|
66
|
+
}
|
67
|
+
|
68
|
+
static VALUE
|
69
|
+
rb_grn_expression_initialize (int argc, VALUE *argv, VALUE self)
|
70
|
+
{
|
71
|
+
grn_ctx *context = NULL;
|
72
|
+
grn_obj *expression;
|
73
|
+
VALUE options, rb_context, rb_name, rb_query, rb_table, rb_default_column;
|
74
|
+
char *name = NULL, *query = NULL;
|
75
|
+
unsigned name_size = 0, query_size = 0;
|
76
|
+
|
77
|
+
rb_scan_args(argc, argv, "01", &options);
|
78
|
+
rb_grn_scan_options(options,
|
79
|
+
"context", &rb_context,
|
80
|
+
"name", &rb_name,
|
81
|
+
"query", &rb_query,
|
82
|
+
"table", &rb_table,
|
83
|
+
"default_column", &rb_default_column,
|
84
|
+
NULL);
|
85
|
+
|
86
|
+
context = rb_grn_context_ensure(&rb_context);
|
87
|
+
|
88
|
+
if (!NIL_P(rb_name)) {
|
89
|
+
name = StringValuePtr(rb_name);
|
90
|
+
name_size = RSTRING_LEN(rb_name);
|
91
|
+
}
|
92
|
+
|
93
|
+
if (!NIL_P(rb_query)) {
|
94
|
+
query = StringValuePtr(rb_query);
|
95
|
+
query_size = RSTRING_LEN(rb_query);
|
96
|
+
}
|
97
|
+
|
98
|
+
if (query) {
|
99
|
+
grn_obj *table;
|
100
|
+
grn_obj *default_column = NULL;
|
101
|
+
|
102
|
+
table = RVAL2GRNOBJECT(rb_table, &context);
|
103
|
+
default_column = RVAL2GRNBULK(rb_default_column, context, default_column);
|
104
|
+
expression = grn_expr_create_from_str(context, name, name_size,
|
105
|
+
query, query_size,
|
106
|
+
table, default_column);
|
107
|
+
} else {
|
108
|
+
expression = grn_expr_create(context, name, name_size);
|
109
|
+
}
|
110
|
+
rb_grn_object_assign(Qnil, self, rb_context, context, expression);
|
111
|
+
rb_grn_context_check(context, self);
|
112
|
+
|
113
|
+
return Qnil;
|
114
|
+
}
|
115
|
+
|
116
|
+
static VALUE
|
117
|
+
rb_grn_expression_define_variable (int argc, VALUE *argv, VALUE self)
|
118
|
+
{
|
119
|
+
grn_ctx *context = NULL;
|
120
|
+
grn_obj *expression, *variable;
|
121
|
+
char *name = NULL;
|
122
|
+
unsigned name_size = 0;
|
123
|
+
VALUE options, rb_name, rb_domain, rb_variable;
|
124
|
+
|
125
|
+
rb_scan_args(argc, argv, "01", &options);
|
126
|
+
|
127
|
+
rb_grn_expression_deconstruct(SELF(self), &expression, &context,
|
128
|
+
NULL, NULL,
|
129
|
+
NULL, NULL, NULL);
|
130
|
+
|
131
|
+
rb_grn_scan_options(options,
|
132
|
+
"name", &rb_name,
|
133
|
+
"domain", &rb_domain,
|
134
|
+
NULL);
|
135
|
+
|
136
|
+
if (!NIL_P(rb_name)) {
|
137
|
+
name = StringValuePtr(rb_name);
|
138
|
+
name_size = RSTRING_LEN(rb_name);
|
139
|
+
}
|
140
|
+
|
141
|
+
variable = grn_expr_add_var(context, expression, name, name_size);
|
142
|
+
rb_variable = GRNVARIABLE2RVAL(context, variable);
|
143
|
+
|
144
|
+
if (RVAL2CBOOL(rb_obj_is_kind_of(rb_domain, rb_cGrnTable))) {
|
145
|
+
grn_id domain_id;
|
146
|
+
domain_id = NUM2UINT(rb_funcall(rb_domain, rb_intern("id"), 0));
|
147
|
+
GRN_RECORD_INIT(variable, 0, domain_id);
|
148
|
+
}
|
149
|
+
|
150
|
+
return rb_variable;
|
151
|
+
}
|
152
|
+
|
153
|
+
static VALUE
|
154
|
+
rb_grn_expression_get_value (VALUE self, VALUE rb_offset)
|
155
|
+
{
|
156
|
+
grn_ctx *context = NULL;
|
157
|
+
grn_obj *value, *expression;
|
158
|
+
int offset;
|
159
|
+
|
160
|
+
rb_grn_expression_deconstruct(SELF(self), &expression, &context,
|
161
|
+
NULL, NULL,
|
162
|
+
NULL, NULL, NULL);
|
163
|
+
|
164
|
+
offset = NUM2INT(rb_offset);
|
165
|
+
value = grn_expr_get_value(context, expression, offset);
|
166
|
+
return GRNBULK2RVAL(context, value, self);
|
167
|
+
}
|
168
|
+
|
169
|
+
static VALUE
|
170
|
+
rb_grn_expression_append_object (VALUE self, VALUE rb_object)
|
171
|
+
{
|
172
|
+
grn_ctx *context = NULL;
|
173
|
+
grn_obj *expression, *object;
|
174
|
+
|
175
|
+
rb_grn_expression_deconstruct(SELF(self), &expression, &context,
|
176
|
+
NULL, NULL,
|
177
|
+
NULL, NULL, NULL);
|
178
|
+
|
179
|
+
object = RVAL2GRNOBJECT(rb_object, &context);
|
180
|
+
grn_expr_append_obj(context, expression, object);
|
181
|
+
rb_grn_context_check(context, self);
|
182
|
+
return self;
|
183
|
+
}
|
184
|
+
|
185
|
+
static VALUE
|
186
|
+
rb_grn_expression_append_constant (VALUE self, VALUE rb_constant)
|
187
|
+
{
|
188
|
+
grn_ctx *context = NULL;
|
189
|
+
grn_obj *expression, *constant = NULL;
|
190
|
+
|
191
|
+
rb_grn_expression_deconstruct(SELF(self), &expression, &context,
|
192
|
+
NULL, NULL, NULL,
|
193
|
+
NULL, NULL);
|
194
|
+
|
195
|
+
RVAL2GRNOBJ(rb_constant, context, &constant);
|
196
|
+
grn_expr_append_const(context, expression, constant);
|
197
|
+
grn_obj_close(context, constant);
|
198
|
+
rb_grn_context_check(context, self);
|
199
|
+
return self;
|
200
|
+
}
|
201
|
+
|
202
|
+
static VALUE
|
203
|
+
rb_grn_expression_append_operation (VALUE self, VALUE rb_operation,
|
204
|
+
VALUE rb_n_arguments)
|
205
|
+
{
|
206
|
+
grn_ctx *context = NULL;
|
207
|
+
grn_obj *expression;
|
208
|
+
grn_operator operation;
|
209
|
+
int n_arguments = 0;
|
210
|
+
|
211
|
+
rb_grn_expression_deconstruct(SELF(self), &expression, &context,
|
212
|
+
NULL, NULL,
|
213
|
+
NULL, NULL, NULL);
|
214
|
+
|
215
|
+
operation = NUM2INT(rb_operation);
|
216
|
+
n_arguments = NUM2INT(rb_n_arguments);
|
217
|
+
grn_expr_append_op(context, expression, operation, n_arguments);
|
218
|
+
rb_grn_context_check(context, self);
|
219
|
+
return Qnil;
|
220
|
+
}
|
221
|
+
|
222
|
+
static VALUE
|
223
|
+
rb_grn_expression_execute (VALUE self)
|
224
|
+
{
|
225
|
+
grn_ctx *context = NULL;
|
226
|
+
grn_obj *expression, *result;
|
227
|
+
|
228
|
+
rb_grn_expression_deconstruct(SELF(self), &expression, &context,
|
229
|
+
NULL, NULL,
|
230
|
+
NULL, NULL, NULL);
|
231
|
+
|
232
|
+
result = grn_expr_exec(context, expression);
|
233
|
+
return GRNOBJ2RVAL(Qnil, context, result, self);
|
234
|
+
}
|
235
|
+
|
236
|
+
static VALUE
|
237
|
+
rb_grn_expression_compile (VALUE self)
|
238
|
+
{
|
239
|
+
grn_ctx *context = NULL;
|
240
|
+
grn_obj *expression;
|
241
|
+
grn_rc rc;
|
242
|
+
|
243
|
+
rb_grn_expression_deconstruct(SELF(self), &expression, &context,
|
244
|
+
NULL, NULL,
|
245
|
+
NULL, NULL, NULL);
|
246
|
+
|
247
|
+
rc = grn_expr_compile(context, expression);
|
248
|
+
rb_grn_context_check(context, self);
|
249
|
+
rb_grn_rc_check(rc, self);
|
250
|
+
|
251
|
+
return Qnil;
|
252
|
+
}
|
253
|
+
|
254
|
+
static VALUE
|
255
|
+
rb_grn_expression_array_reference (VALUE self, VALUE rb_name_or_offset)
|
256
|
+
{
|
257
|
+
grn_ctx *context = NULL;
|
258
|
+
grn_obj *expression, *variable, *value;
|
259
|
+
char *name = NULL;
|
260
|
+
unsigned name_size = 0;
|
261
|
+
int offset;
|
262
|
+
|
263
|
+
rb_grn_expression_deconstruct(SELF(self), &expression, &context,
|
264
|
+
NULL, NULL,
|
265
|
+
NULL, NULL, NULL);
|
266
|
+
|
267
|
+
switch (TYPE(rb_name_or_offset)) {
|
268
|
+
case T_STRING:
|
269
|
+
name = RSTRING_PTR(rb_name_or_offset);
|
270
|
+
name_size = RSTRING_LEN(rb_name_or_offset);
|
271
|
+
variable = grn_expr_get_var(context, expression, name, name_size);
|
272
|
+
return GRNBULK2RVAL(context, variable, self);
|
273
|
+
break;
|
274
|
+
case T_FIXNUM:
|
275
|
+
offset = NUM2INT(rb_name_or_offset);
|
276
|
+
value = grn_expr_get_var_by_offset(context, expression, offset);
|
277
|
+
return GRNBULK2RVAL(context, value, self);
|
278
|
+
break;
|
279
|
+
default:
|
280
|
+
rb_raise(rb_eArgError, "xxx");
|
281
|
+
break;
|
282
|
+
}
|
283
|
+
|
284
|
+
return Qnil;
|
285
|
+
}
|
286
|
+
|
287
|
+
void
|
288
|
+
rb_grn_init_expression (VALUE mGrn)
|
289
|
+
{
|
290
|
+
rb_cGrnExpression = rb_define_class_under(mGrn, "Expression", rb_cGrnObject);
|
291
|
+
|
292
|
+
rb_define_method(rb_cGrnExpression, "initialize",
|
293
|
+
rb_grn_expression_initialize, -1);
|
294
|
+
|
295
|
+
rb_define_method(rb_cGrnExpression, "define_variable",
|
296
|
+
rb_grn_expression_define_variable, -1);
|
297
|
+
rb_define_method(rb_cGrnExpression, "append_object",
|
298
|
+
rb_grn_expression_append_object, 1);
|
299
|
+
rb_define_method(rb_cGrnExpression, "append_constant",
|
300
|
+
rb_grn_expression_append_constant, 1);
|
301
|
+
rb_define_method(rb_cGrnExpression, "append_operation",
|
302
|
+
rb_grn_expression_append_operation, 2);
|
303
|
+
|
304
|
+
rb_define_method(rb_cGrnExpression, "execute",
|
305
|
+
rb_grn_expression_execute, 0);
|
306
|
+
rb_define_method(rb_cGrnExpression, "compile",
|
307
|
+
rb_grn_expression_compile, 0);
|
308
|
+
|
309
|
+
rb_define_method(rb_cGrnExpression, "value",
|
310
|
+
rb_grn_expression_get_value, 1);
|
311
|
+
|
312
|
+
rb_define_method(rb_cGrnExpression, "[]",
|
313
|
+
rb_grn_expression_array_reference, 1);
|
314
|
+
}
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
#include "rb-grn.h"
|
20
20
|
|
21
|
-
#define SELF(object) ((
|
21
|
+
#define SELF(object) ((RbGrnColumn *)DATA_PTR(object))
|
22
22
|
|
23
23
|
VALUE rb_cGrnFixSizeColumn;
|
24
24
|
|
@@ -28,87 +28,6 @@ VALUE rb_cGrnFixSizeColumn;
|
|
28
28
|
* 固定長データ用のカラム。
|
29
29
|
*/
|
30
30
|
|
31
|
-
void
|
32
|
-
rb_grn_fix_size_column_unbind (RbGrnFixSizeColumn *rb_grn_fix_size_column)
|
33
|
-
{
|
34
|
-
RbGrnObject *rb_grn_object;
|
35
|
-
grn_ctx *context;
|
36
|
-
|
37
|
-
rb_grn_object = RB_GRN_OBJECT(rb_grn_fix_size_column);
|
38
|
-
context = rb_grn_object->context;
|
39
|
-
|
40
|
-
if (context)
|
41
|
-
grn_obj_close(context, rb_grn_fix_size_column->value);
|
42
|
-
|
43
|
-
rb_grn_object_unbind(rb_grn_object);
|
44
|
-
}
|
45
|
-
|
46
|
-
static void
|
47
|
-
rb_grn_fix_size_column_free (void *object)
|
48
|
-
{
|
49
|
-
RbGrnFixSizeColumn *rb_grn_fix_size_column = object;
|
50
|
-
|
51
|
-
rb_grn_fix_size_column_unbind(rb_grn_fix_size_column);
|
52
|
-
xfree(rb_grn_fix_size_column);
|
53
|
-
}
|
54
|
-
|
55
|
-
VALUE
|
56
|
-
rb_grn_fix_size_column_alloc (VALUE klass)
|
57
|
-
{
|
58
|
-
return Data_Wrap_Struct(klass, NULL, rb_grn_fix_size_column_free, NULL);
|
59
|
-
}
|
60
|
-
|
61
|
-
void
|
62
|
-
rb_grn_fix_size_column_bind (RbGrnFixSizeColumn *rb_grn_fix_size_column,
|
63
|
-
grn_ctx *context, grn_obj *column,
|
64
|
-
rb_grn_boolean owner)
|
65
|
-
{
|
66
|
-
RbGrnObject *rb_grn_object;
|
67
|
-
|
68
|
-
rb_grn_object = RB_GRN_OBJECT(rb_grn_fix_size_column);
|
69
|
-
rb_grn_object_bind(rb_grn_object, context, column, owner);
|
70
|
-
rb_grn_object->unbind =
|
71
|
-
RB_GRN_UNBIND_FUNCTION(rb_grn_fix_size_column_unbind);
|
72
|
-
|
73
|
-
rb_grn_fix_size_column->value = grn_obj_open(context, GRN_BULK, 0,
|
74
|
-
rb_grn_object->range_id);
|
75
|
-
}
|
76
|
-
|
77
|
-
void
|
78
|
-
rb_grn_fix_size_column_assign (VALUE self, VALUE rb_context,
|
79
|
-
grn_ctx *context, grn_obj *column,
|
80
|
-
rb_grn_boolean owner)
|
81
|
-
{
|
82
|
-
RbGrnFixSizeColumn *rb_grn_fix_size_column;
|
83
|
-
|
84
|
-
rb_grn_fix_size_column = ALLOC(RbGrnFixSizeColumn);
|
85
|
-
DATA_PTR(self) = rb_grn_fix_size_column;
|
86
|
-
rb_grn_fix_size_column_bind(rb_grn_fix_size_column, context, column, owner);
|
87
|
-
|
88
|
-
rb_iv_set(self, "context", rb_context);
|
89
|
-
}
|
90
|
-
|
91
|
-
void
|
92
|
-
rb_grn_fix_size_column_deconstruct (RbGrnFixSizeColumn *rb_grn_fix_size_column,
|
93
|
-
grn_obj **column,
|
94
|
-
grn_ctx **context,
|
95
|
-
grn_id *domain_id,
|
96
|
-
grn_obj **domain,
|
97
|
-
grn_obj **value,
|
98
|
-
grn_id *range_id,
|
99
|
-
grn_obj **range)
|
100
|
-
{
|
101
|
-
RbGrnObject *rb_grn_object;
|
102
|
-
|
103
|
-
rb_grn_object = RB_GRN_OBJECT(rb_grn_fix_size_column);
|
104
|
-
rb_grn_object_deconstruct(rb_grn_object, column, context,
|
105
|
-
domain_id, domain,
|
106
|
-
range_id, range);
|
107
|
-
|
108
|
-
if (value)
|
109
|
-
*value = rb_grn_fix_size_column->value;
|
110
|
-
}
|
111
|
-
|
112
31
|
/*
|
113
32
|
* call-seq:
|
114
33
|
* column[id] -> 値
|
@@ -124,9 +43,9 @@ rb_grn_fix_size_column_array_reference (VALUE self, VALUE rb_id)
|
|
124
43
|
grn_obj *range;
|
125
44
|
grn_obj *value;
|
126
45
|
|
127
|
-
|
128
|
-
|
129
|
-
|
46
|
+
rb_grn_column_deconstruct(SELF(self), &fix_size_column, &context,
|
47
|
+
NULL, NULL,
|
48
|
+
&value, NULL, &range);
|
130
49
|
|
131
50
|
id = NUM2UINT(rb_id);
|
132
51
|
GRN_BULK_REWIND(value);
|
@@ -153,9 +72,9 @@ rb_grn_fix_size_column_array_set (VALUE self, VALUE rb_id, VALUE rb_value)
|
|
153
72
|
grn_rc rc;
|
154
73
|
grn_id id;
|
155
74
|
|
156
|
-
|
157
|
-
|
158
|
-
|
75
|
+
rb_grn_column_deconstruct(SELF(self), &column, &context,
|
76
|
+
&domain_id, &domain,
|
77
|
+
&value, &range_id, &range);
|
159
78
|
|
160
79
|
id = NUM2UINT(rb_id);
|
161
80
|
|
@@ -206,15 +125,75 @@ rb_grn_fix_size_column_array_set (VALUE self, VALUE rb_id, VALUE rb_value)
|
|
206
125
|
return Qnil;
|
207
126
|
}
|
208
127
|
|
128
|
+
static VALUE
|
129
|
+
rb_grn_fix_size_column_integer_set (int argc, VALUE *argv, VALUE self, int flags)
|
130
|
+
{
|
131
|
+
grn_ctx *context = NULL;
|
132
|
+
grn_obj *column;
|
133
|
+
grn_obj *value;
|
134
|
+
grn_rc rc;
|
135
|
+
grn_id id;
|
136
|
+
VALUE rb_id, rb_delta;
|
137
|
+
|
138
|
+
rb_scan_args(argc, argv, "11", &rb_id, &rb_delta);
|
139
|
+
|
140
|
+
rb_grn_column_deconstruct(SELF(self), &column, &context,
|
141
|
+
NULL, NULL,
|
142
|
+
&value, NULL, NULL);
|
143
|
+
|
144
|
+
id = NUM2UINT(rb_id);
|
145
|
+
if (NIL_P(rb_delta))
|
146
|
+
rb_delta = INT2NUM(1);
|
147
|
+
|
148
|
+
GRN_BULK_REWIND(value);
|
149
|
+
RVAL2GRNBULK(rb_delta, context, value);
|
150
|
+
|
151
|
+
rc = grn_obj_set_value(context, column, id, value, flags);
|
152
|
+
rb_grn_context_check(context, self);
|
153
|
+
rb_grn_rc_check(rc, self);
|
154
|
+
|
155
|
+
return Qnil;
|
156
|
+
}
|
157
|
+
|
158
|
+
/*
|
159
|
+
* call-seq:
|
160
|
+
* column.increment!(id, delta=nil)
|
161
|
+
*
|
162
|
+
* _column_の_id_に対応する値を_delta_だけ増加する。_delta_
|
163
|
+
* が+nil+の場合は1増加する。
|
164
|
+
*/
|
165
|
+
static VALUE
|
166
|
+
rb_grn_fix_size_column_increment (int argc, VALUE *argv, VALUE self)
|
167
|
+
{
|
168
|
+
return rb_grn_fix_size_column_integer_set(argc, argv, self, GRN_OBJ_INCR);
|
169
|
+
}
|
170
|
+
|
171
|
+
/*
|
172
|
+
* call-seq:
|
173
|
+
* column.decrement!(id, delta=nil)
|
174
|
+
*
|
175
|
+
* _column_の_id_に対応する値を_delta_だけ減少する。_delta_
|
176
|
+
* が+nil+の場合は1減少する。
|
177
|
+
*/
|
178
|
+
static VALUE
|
179
|
+
rb_grn_fix_size_column_decrement (int argc, VALUE *argv, VALUE self)
|
180
|
+
{
|
181
|
+
return rb_grn_fix_size_column_integer_set(argc, argv, self, GRN_OBJ_DECR);
|
182
|
+
}
|
183
|
+
|
209
184
|
void
|
210
185
|
rb_grn_init_fix_size_column (VALUE mGrn)
|
211
186
|
{
|
212
187
|
rb_cGrnFixSizeColumn =
|
213
188
|
rb_define_class_under(mGrn, "FixSizeColumn", rb_cGrnColumn);
|
214
|
-
rb_define_alloc_func(rb_cGrnFixSizeColumn, rb_grn_fix_size_column_alloc);
|
215
189
|
|
216
190
|
rb_define_method(rb_cGrnFixSizeColumn, "[]",
|
217
191
|
rb_grn_fix_size_column_array_reference, 1);
|
218
192
|
rb_define_method(rb_cGrnFixSizeColumn, "[]=",
|
219
193
|
rb_grn_fix_size_column_array_set, 2);
|
194
|
+
|
195
|
+
rb_define_method(rb_cGrnFixSizeColumn, "increment!",
|
196
|
+
rb_grn_fix_size_column_increment, -1);
|
197
|
+
rb_define_method(rb_cGrnFixSizeColumn, "decrement!",
|
198
|
+
rb_grn_fix_size_column_decrement, -1);
|
220
199
|
}
|