groonga 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. data/AUTHORS +1 -0
  2. data/NEWS.ja.rdoc +5 -0
  3. data/NEWS.rdoc +5 -0
  4. data/README.ja.rdoc +53 -0
  5. data/README.rdoc +54 -0
  6. data/Rakefile +209 -0
  7. data/TUTORIAL.ja.rdoc +160 -0
  8. data/benchmark/small-many-items.rb +175 -0
  9. data/example/bookmark.rb +38 -0
  10. data/ext/.gitignore +2 -0
  11. data/ext/rb-grn-accessor.c +52 -0
  12. data/ext/rb-grn-array-cursor.c +28 -0
  13. data/ext/rb-grn-array.c +168 -0
  14. data/ext/rb-grn-column.c +273 -0
  15. data/ext/rb-grn-context.c +333 -0
  16. data/ext/rb-grn-database.c +128 -0
  17. data/ext/rb-grn-encoding.c +163 -0
  18. data/ext/rb-grn-exception.c +1014 -0
  19. data/ext/rb-grn-hash-cursor.c +30 -0
  20. data/ext/rb-grn-hash.c +40 -0
  21. data/ext/rb-grn-logger.c +277 -0
  22. data/ext/rb-grn-object.c +985 -0
  23. data/ext/rb-grn-patricia-trie-cursor.c +30 -0
  24. data/ext/rb-grn-patricia-trie.c +40 -0
  25. data/ext/rb-grn-procedure.c +52 -0
  26. data/ext/rb-grn-query.c +207 -0
  27. data/ext/rb-grn-record.c +33 -0
  28. data/ext/rb-grn-snippet.c +274 -0
  29. data/ext/rb-grn-table-cursor-key-support.c +55 -0
  30. data/ext/rb-grn-table-cursor.c +294 -0
  31. data/ext/rb-grn-table-key-support.c +299 -0
  32. data/ext/rb-grn-table.c +706 -0
  33. data/ext/rb-grn-type.c +114 -0
  34. data/ext/rb-grn-utils.c +578 -0
  35. data/ext/rb-grn.h +346 -0
  36. data/ext/rb-groonga.c +98 -0
  37. data/extconf.rb +171 -0
  38. data/html/bar.svg +153 -0
  39. data/html/developer.html +121 -0
  40. data/html/developer.svg +469 -0
  41. data/html/download.svg +253 -0
  42. data/html/footer.html.erb +28 -0
  43. data/html/head.html.erb +4 -0
  44. data/html/header.html.erb +17 -0
  45. data/html/index.html +153 -0
  46. data/html/install.svg +636 -0
  47. data/html/logo.xcf +0 -0
  48. data/html/ranguba.css +248 -0
  49. data/html/tutorial.svg +559 -0
  50. data/lib/groonga.rb +50 -0
  51. data/lib/groonga/record.rb +98 -0
  52. data/license/GPL +340 -0
  53. data/license/LGPL +504 -0
  54. data/license/RUBY +59 -0
  55. data/pkg-config.rb +328 -0
  56. data/test-unit/Rakefile +35 -0
  57. data/test-unit/TODO +5 -0
  58. data/test-unit/bin/testrb +5 -0
  59. data/test-unit/html/classic.html +15 -0
  60. data/test-unit/html/index.html +25 -0
  61. data/test-unit/html/index.html.ja +27 -0
  62. data/test-unit/lib/test/unit.rb +342 -0
  63. data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
  64. data/test-unit/lib/test/unit/assertions.rb +1149 -0
  65. data/test-unit/lib/test/unit/attribute.rb +125 -0
  66. data/test-unit/lib/test/unit/autorunner.rb +306 -0
  67. data/test-unit/lib/test/unit/collector.rb +43 -0
  68. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  69. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  70. data/test-unit/lib/test/unit/collector/load.rb +135 -0
  71. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  72. data/test-unit/lib/test/unit/color-scheme.rb +86 -0
  73. data/test-unit/lib/test/unit/color.rb +96 -0
  74. data/test-unit/lib/test/unit/diff.rb +538 -0
  75. data/test-unit/lib/test/unit/error.rb +124 -0
  76. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  77. data/test-unit/lib/test/unit/failure.rb +110 -0
  78. data/test-unit/lib/test/unit/fixture.rb +176 -0
  79. data/test-unit/lib/test/unit/notification.rb +125 -0
  80. data/test-unit/lib/test/unit/omission.rb +143 -0
  81. data/test-unit/lib/test/unit/pending.rb +146 -0
  82. data/test-unit/lib/test/unit/priority.rb +161 -0
  83. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  84. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  85. data/test-unit/lib/test/unit/testcase.rb +360 -0
  86. data/test-unit/lib/test/unit/testresult.rb +89 -0
  87. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  88. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  89. data/test-unit/lib/test/unit/ui/console/testrunner.rb +220 -0
  90. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  91. data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
  92. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  93. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  94. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  95. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  96. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  97. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  98. data/test-unit/lib/test/unit/version.rb +7 -0
  99. data/test-unit/sample/adder.rb +13 -0
  100. data/test-unit/sample/subtracter.rb +12 -0
  101. data/test-unit/sample/tc_adder.rb +18 -0
  102. data/test-unit/sample/tc_subtracter.rb +18 -0
  103. data/test-unit/sample/test_user.rb +22 -0
  104. data/test-unit/sample/ts_examples.rb +7 -0
  105. data/test-unit/test/collector/test-descendant.rb +135 -0
  106. data/test-unit/test/collector/test-load.rb +333 -0
  107. data/test-unit/test/collector/test_dir.rb +406 -0
  108. data/test-unit/test/collector/test_objectspace.rb +98 -0
  109. data/test-unit/test/run-test.rb +13 -0
  110. data/test-unit/test/test-attribute.rb +86 -0
  111. data/test-unit/test/test-color-scheme.rb +56 -0
  112. data/test-unit/test/test-color.rb +47 -0
  113. data/test-unit/test/test-diff.rb +477 -0
  114. data/test-unit/test/test-emacs-runner.rb +60 -0
  115. data/test-unit/test/test-fixture.rb +287 -0
  116. data/test-unit/test/test-notification.rb +33 -0
  117. data/test-unit/test/test-omission.rb +81 -0
  118. data/test-unit/test/test-pending.rb +70 -0
  119. data/test-unit/test/test-priority.rb +119 -0
  120. data/test-unit/test/test_assertions.rb +1082 -0
  121. data/test-unit/test/test_error.rb +26 -0
  122. data/test-unit/test/test_failure.rb +33 -0
  123. data/test-unit/test/test_testcase.rb +478 -0
  124. data/test-unit/test/test_testresult.rb +113 -0
  125. data/test-unit/test/test_testsuite.rb +129 -0
  126. data/test-unit/test/testunit-test-util.rb +14 -0
  127. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  128. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  129. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  130. data/test-unit/test/util/test_observable.rb +102 -0
  131. data/test-unit/test/util/test_procwrapper.rb +36 -0
  132. data/test/.gitignore +1 -0
  133. data/test/groonga-test-utils.rb +90 -0
  134. data/test/run-test.rb +54 -0
  135. data/test/test-column.rb +190 -0
  136. data/test/test-context.rb +90 -0
  137. data/test/test-database.rb +62 -0
  138. data/test/test-encoding.rb +33 -0
  139. data/test/test-exception.rb +85 -0
  140. data/test/test-procedure.rb +35 -0
  141. data/test/test-query.rb +22 -0
  142. data/test/test-record.rb +188 -0
  143. data/test/test-snippet.rb +121 -0
  144. data/test/test-table-cursor.rb +51 -0
  145. data/test/test-table.rb +447 -0
  146. data/test/test-type.rb +52 -0
  147. data/test/test-version.rb +31 -0
  148. metadata +213 -0
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # This benchmark is based on Tokyo Cabinet's benchmark at
4
+ # http://alpha.mixi.co.jp/blog/?p=791
5
+ #
6
+ # On my environment at 2009/04/29:
7
+ # % for x in {0..8}; do ruby benchmark/small-many-items.rb $x; done
8
+ # user system total real memory
9
+ # Hash 1.070000 0.140000 1.210000 ( 1.462675) 46.234MB
10
+ # groonga: Hash: memory 1.380000 0.140000 1.520000 ( 1.804040) 23.531MB
11
+ # groonga: Trie: memory 1.780000 0.110000 1.890000 ( 2.136395) 15.520MB
12
+ # groonga: Hash: file 1.380000 0.180000 1.560000 ( 1.879252) 23.535MB
13
+ # groonga: Trie: file 1.650000 0.160000 1.810000 ( 2.257756) 15.523MB
14
+ # TC: Hash: memory 0.680000 0.170000 0.850000 ( 1.038155) 38.246MB
15
+ # TC: Tree: memory 0.640000 0.130000 0.770000 ( 1.029011) 30.609MB
16
+ # TC: Hash: file 1.150000 2.900000 4.050000 ( 4.908274) 0.164MB
17
+ # TC: Tree: file 0.970000 0.210000 1.180000 ( 1.416418) 5.367MB
18
+ #
19
+ # Ruby: Debian GNU/Linux sid at 2009/04/29:
20
+ # ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
21
+ # groonga: HEAD at 2009/04/29: c97c3cf78b8f0761ca48ef211caa155135f89487
22
+ # Ruby/Groonga: trunk at 2009/04/29: r221
23
+ # Tokyo Cabinet: 1.4.17
24
+ # Tokyo Cabinet Ruby: 1.23
25
+
26
+ require 'benchmark'
27
+ require 'tempfile'
28
+
29
+ def memory_usage()
30
+ status = `cat /proc/#{$$}/status`
31
+ lines = status.split("\n")
32
+ lines.each do |line|
33
+ if line =~ /^VmRSS:/
34
+ line.gsub!(/.*:\s*(\d+).*/, '\1')
35
+ return line.to_i / 1024.0
36
+ end
37
+ end
38
+ return -1;
39
+ end
40
+
41
+ n = 500000
42
+
43
+ @items = []
44
+
45
+ def item(label, &block)
46
+ @items << [label, block]
47
+ end
48
+
49
+ def report(index=0)
50
+ width = @items.collect do |label, _|
51
+ label.length
52
+ end.max
53
+
54
+ label, block = @items[index]
55
+ if label.nil?
56
+ puts "unavailable report ID: #{index}"
57
+ puts "available IDs:"
58
+ @items.each_with_index do |(label, block), i|
59
+ puts "#{i}: #{label}"
60
+ end
61
+ exit 1
62
+ end
63
+
64
+ if index.zero?
65
+ puts(" " * (width - 1) + Benchmark::Tms::CAPTION.rstrip + "memory".rjust(14))
66
+ end
67
+ # GC.disable
68
+ before = memory_usage
69
+ result = Benchmark.measure(&block)
70
+ # GC.enable
71
+ GC.start
72
+ size = memory_usage - before
73
+
74
+ formatted_size = "%10.3f" % size
75
+ puts "#{label.ljust(width)} #{result.to_s.strip} #{formatted_size}MB"
76
+ end
77
+
78
+ values = []
79
+ n.times do |i|
80
+ values << "%08d" % i
81
+ end
82
+
83
+ item("Hash") do
84
+ hash = {}
85
+ values.each do |value|
86
+ hash[value] = value
87
+ end
88
+ end
89
+
90
+ begin
91
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
92
+ $LOAD_PATH.unshift(File.join(base_dir, "src"))
93
+ $LOAD_PATH.unshift(File.join(base_dir, "src", "lib"))
94
+
95
+ require 'groonga'
96
+ Groonga::Database.create
97
+
98
+ item("groonga: Hash: memory") do
99
+ hash = Groonga::Hash.create(:key_type => "<shorttext>",
100
+ :value_size => 8)
101
+ values.each do |value|
102
+ hash[value] = value
103
+ end
104
+ end
105
+
106
+ item("groonga: Trie: memory") do
107
+ hash = Groonga::PatriciaTrie.create(:key_type => "<shorttext>",
108
+ :value_size => 8)
109
+ values.each do |value|
110
+ hash[value] = value
111
+ end
112
+ end
113
+
114
+ hash_file = Tempfile.new("groonga-hash")
115
+ item("groonga: Hash: file") do
116
+ hash = Groonga::Hash.create(:key_type => "<shorttext>",
117
+ :value_size => 8,
118
+ :path => hash_file.path)
119
+ values.each do |value|
120
+ hash[value] = value
121
+ end
122
+ end
123
+
124
+ trie_file = Tempfile.new("groonga-trie")
125
+ item("groonga: Trie: file") do
126
+ hash = Groonga::PatriciaTrie.create(:key_type => "<shorttext>",
127
+ :value_size => 8,
128
+ :path => trie_file.path)
129
+ values.each do |value|
130
+ hash[value] = value
131
+ end
132
+ end
133
+ rescue LoadError
134
+ end
135
+
136
+ begin
137
+ require 'tokyocabinet'
138
+
139
+ item("TC: Hash: memory") do
140
+ db = TokyoCabinet::ADB::new
141
+ db.open("*#bnum=#{n}#mode=wct#xmsiz=0")
142
+ values.each do |value|
143
+ db.put(value, value)
144
+ end
145
+ end
146
+
147
+ item("TC: Tree: memory") do
148
+ db = TokyoCabinet::ADB::new
149
+ db.open("+#bnum=#{n}#mode=wct#xmsiz=0")
150
+ values.each do |value|
151
+ db.put(value, value)
152
+ end
153
+ end
154
+
155
+ hash_file = Tempfile.new(["tc-hash", ".tch"])
156
+ item("TC: Hash: file") do
157
+ db = TokyoCabinet::ADB::new
158
+ db.open("#{hash_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
159
+ values.each do |value|
160
+ db.put(value, value)
161
+ end
162
+ end
163
+
164
+ tree_file = Tempfile.new(["tc-tree", ".tcb"])
165
+ item("TC: Tree: file") do
166
+ db = TokyoCabinet::ADB::new
167
+ db.open("#{tree_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
168
+ values.each do |value|
169
+ db.put(value, value)
170
+ end
171
+ end
172
+ rescue LoadError
173
+ end
174
+
175
+ report(Integer(ARGV[0] || 0))
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "rubygems"
5
+ require "groonga"
6
+
7
+ $KCODE = "UTF-8"
8
+ Groonga::Context.default_options = {:encoding => :utf8}
9
+
10
+ path = ARGV[0]
11
+ persistent = !path.nil?
12
+
13
+ Groonga::Database.create(:path => path)
14
+
15
+ items = Groonga::Hash.create(:name => "<items>", :persistent => persistent)
16
+
17
+ items.add("http://ja.wikipedia.org/wiki/Ruby")
18
+ items.add("http://www.ruby-lang.org/")
19
+
20
+ title_column = items.define_column("title", "<text>",
21
+ :persistent => persistent)
22
+
23
+ terms = Groonga::Hash.create(:name => "<terms>",
24
+ :key_type => "<shorttext>",
25
+ :key_normalize => true,
26
+ :persistent => persistent)
27
+ title_index_column = terms.define_column("item_title", items,
28
+ :type => "index",
29
+ :with_position => true,
30
+ :persistent => persistent)
31
+ title_index_column.source = title_column
32
+
33
+ items["http://ja.wikipedia.org/wiki/Ruby"]["title"] = "Ruby"
34
+ items["http://www.ruby-lang.org/"]["title"] = "オブジェクトスクリプト言語Ruby"
35
+
36
+ p terms.collect(&:key)
37
+ p title_index_column.search("Ruby").size
38
+ p title_index_column.search("ruby").size
data/ext/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.so
2
+ *.o
@@ -0,0 +1,52 @@
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) (RVAL2GRNACCESSOR(object))
22
+
23
+ VALUE rb_cGrnAccessor;
24
+
25
+ grn_obj *
26
+ rb_grn_accessor_from_ruby_object (VALUE object)
27
+ {
28
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnAccessor))) {
29
+ rb_raise(rb_eTypeError, "not a groonga accessor");
30
+ }
31
+
32
+ return RVAL2GRNOBJECT(object, NULL);
33
+ }
34
+
35
+ VALUE
36
+ rb_grn_accessor_to_ruby_object (grn_ctx *context, grn_obj *table,
37
+ rb_grn_boolean owner)
38
+ {
39
+ return GRNOBJECT2RVAL(rb_cGrnAccessor, context, table, owner);
40
+ }
41
+
42
+ /*
43
+ * Document-class: Groonga::Accessor < Groonga::Object
44
+ *
45
+ * キー、値、スコアなど種々の値へのアクセスをカプセル化した
46
+ * オブジェクト。Groonga::Table#columnで取得できる。
47
+ */
48
+ void
49
+ rb_grn_init_accessor (VALUE mGrn)
50
+ {
51
+ rb_cGrnAccessor = rb_define_class_under(mGrn, "Accessor", rb_cGrnObject);
52
+ }
@@ -0,0 +1,28 @@
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_cGrnArrayCursor;
22
+
23
+ void
24
+ rb_grn_init_array_cursor (VALUE mGrn)
25
+ {
26
+ rb_cGrnArrayCursor =
27
+ rb_define_class_under(mGrn, "ArrayCursor", rb_cGrnTableCursor);
28
+ }
@@ -0,0 +1,168 @@
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, context) (RVAL2GRNTABLE(object, context))
22
+
23
+ VALUE rb_cGrnArray;
24
+
25
+ /*
26
+ * Document-class: Groonga::Array < Groonga::Table
27
+ *
28
+ * 各レコードにキーが存在しないテーブル。レコードはIDで識別
29
+ * する。
30
+ */
31
+
32
+ /*
33
+ * call-seq:
34
+ * Groonga::Array.create(options={}) -> Groonga::Array
35
+ * Groonga::Array.create(options={}) {|table| ... }
36
+ *
37
+ * キーのないテーブルを生成する。ブロックを指定すると、そのブ
38
+ * ロックに生成したテーブルが渡され、ブロックを抜けると自動的
39
+ * にテーブルが破棄される。
40
+ *
41
+ * _options_に指定可能な値は以下の通り。
42
+ *
43
+ * [+:context+]
44
+ * テーブルが利用するGroonga::Context。省略すると
45
+ * Groonga::Context.defaultを用いる。
46
+ *
47
+ * [+:name+]
48
+ * テーブルの名前。名前をつけると、Groonga::Context#[]に名
49
+ * 前を指定してテーブルを取得することができる。省略すると
50
+ * 無名テーブルになり、テーブルIDでのみ取得できる。
51
+ *
52
+ * [+:path+]
53
+ * テーブルを保存するパス。パスを指定すると永続テーブルとな
54
+ * り、プロセス終了後もレコードは保持され、次回起動時に
55
+ * Groonga::Array.openで保存されたレコードを利用することが
56
+ * できる。省略すると一時テーブルになり、プロセスが終了する
57
+ * とレコードは破棄される。
58
+ *
59
+ * [+:persistent+]
60
+ * +true+を指定すると永続テーブルとなる。+path+を省略した
61
+ * 場合は自動的にパスが付加される。+:context+で指定した
62
+ * Groonga::Contextに結びついているデータベースが一時デー
63
+ * タベースの場合は例外が発生する。
64
+ *
65
+ * [+:value_size+]
66
+ * 値の大きさを指定する。省略すると0になる。
67
+ *
68
+ * 無名一時テーブルを生成する。
69
+ * Groonga::Array.create
70
+ *
71
+ * 無名永続テーブルを生成する。
72
+ * Groonga::Array.create(:path => "/tmp/array.grn")
73
+ *
74
+ * 名前付き永続テーブルを生成する。ただし、ファイル名は気に
75
+ * しない。
76
+ * Groonga::Array.create(:name => "<bookmarks>",
77
+ * :persistent => true)
78
+ *
79
+ * それぞれのレコードに512バイトの値を格納できる無名一時テー
80
+ * ブルを生成する。
81
+ * Groonga::Array.create(:value => 512)
82
+ */
83
+ static VALUE
84
+ rb_grn_array_s_create (int argc, VALUE *argv, VALUE klass)
85
+ {
86
+ grn_ctx *context = NULL;
87
+ grn_obj *table;
88
+ const char *name = NULL, *path = NULL;
89
+ unsigned name_size = 0, value_size = 0;
90
+ grn_obj_flags flags = GRN_TABLE_NO_KEY;
91
+ VALUE rb_table;
92
+ VALUE options, rb_context, rb_name, rb_path, rb_persistent;
93
+ VALUE rb_value_size;
94
+
95
+ rb_scan_args(argc, argv, "01", &options);
96
+
97
+ rb_grn_scan_options(options,
98
+ "context", &rb_context,
99
+ "name", &rb_name,
100
+ "path", &rb_path,
101
+ "persistent", &rb_persistent,
102
+ "value_size", &rb_value_size,
103
+ NULL);
104
+
105
+ context = rb_grn_context_ensure(rb_context);
106
+
107
+ if (!NIL_P(rb_name)) {
108
+ name = StringValuePtr(rb_name);
109
+ name_size = RSTRING_LEN(rb_name);
110
+ }
111
+
112
+ if (!NIL_P(rb_path)) {
113
+ path = StringValueCStr(rb_path);
114
+ flags |= GRN_OBJ_PERSISTENT;
115
+ }
116
+
117
+ if (RVAL2CBOOL(rb_persistent))
118
+ flags |= GRN_OBJ_PERSISTENT;
119
+
120
+ if (!NIL_P(rb_value_size))
121
+ value_size = NUM2UINT(rb_value_size);
122
+
123
+ table = grn_table_create(context, name, name_size, path,
124
+ flags, NULL, value_size);
125
+ rb_table = GRNOBJECT2RVAL(klass, context, table, RB_GRN_TRUE);
126
+ rb_grn_context_check(context, rb_table);
127
+
128
+ if (rb_block_given_p())
129
+ return rb_ensure(rb_yield, rb_table, rb_grn_object_close, rb_table);
130
+ else
131
+ return rb_table;
132
+ }
133
+
134
+ /*
135
+ * call-seq:
136
+ * array.add -> Groonga::Recordまたはnil
137
+ *
138
+ * レコード追加し、追加したレコードを返します。レコードの追
139
+ * 加に失敗した場合は+nil+を返します。
140
+ */
141
+ static VALUE
142
+ rb_grn_array_add (VALUE self)
143
+ {
144
+ grn_ctx *context = NULL;
145
+ grn_obj *table;
146
+ grn_id id;
147
+
148
+ table = SELF(self, &context);
149
+
150
+ id = grn_table_add(context, table);
151
+ rb_grn_context_check(context, self);
152
+
153
+ if (GRN_ID_NIL == id)
154
+ return Qnil;
155
+ else
156
+ return rb_grn_record_new(self, id);
157
+ }
158
+
159
+ void
160
+ rb_grn_init_array (VALUE mGrn)
161
+ {
162
+ rb_cGrnArray = rb_define_class_under(mGrn, "Array", rb_cGrnTable);
163
+
164
+ rb_define_singleton_method(rb_cGrnArray, "create",
165
+ rb_grn_array_s_create, -1);
166
+
167
+ rb_define_method(rb_cGrnArray, "add", rb_grn_array_add, 0);
168
+ }