ruby-qdbm 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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/Gemfile +13 -0
- data/README.md +37 -0
- data/Rakefile +65 -0
- data/ext/curia/MANIFEST +5 -0
- data/ext/curia/extconf.rb +18 -0
- data/ext/curia/mod_curia.c +491 -0
- data/ext/depot/MANIFEST +5 -0
- data/ext/depot/extconf.rb +18 -0
- data/ext/depot/mod_depot.c +488 -0
- data/ext/villa/MANIFEST +5 -0
- data/ext/villa/extconf.rb +18 -0
- data/ext/villa/mod_villa.c +704 -0
- data/lib/curia.rb +598 -0
- data/lib/depot.rb +594 -0
- data/lib/villa.rb +816 -0
- data/myrbdoc +194 -0
- data/overview +6 -0
- data/rbapidoc/curia.rb.html +430 -0
- data/rbapidoc/depot.rb.html +426 -0
- data/rbapidoc/index.html +46 -0
- data/rbapidoc/villa.rb.html +551 -0
- data/rbspex-ja.html +284 -0
- data/rbspex.html +284 -0
- data/ruby-qdbm.gemspec +36 -0
- metadata +114 -0
data/rbspex-ja.html
ADDED
@@ -0,0 +1,284 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
|
3
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
|
6
|
+
|
7
|
+
<head>
|
8
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
9
|
+
<meta http-equiv="Content-Style-Type" content="text/css" />
|
10
|
+
<meta name="author" content="Mikio Hirabayashi" />
|
11
|
+
<meta name="keywords" content="QDBM, Ruby, Depot, Curia, Villa" />
|
12
|
+
<meta name="description" content="specifications of Ruby API of QDBM" />
|
13
|
+
<link rel="contents" href="./" />
|
14
|
+
<link rel="alternate" href="rbspex.html" hreflang="en" title="the English version" />
|
15
|
+
<link rev="made" href="mailto:mikio@fallabs.com" />
|
16
|
+
<title>Specifications of QDBM for Ruby (Japanese)</title>
|
17
|
+
<style type="text/css">html { margin: 0em 0em; padding: 0em 0em; background: #eeeeee none; }
|
18
|
+
body { margin: 2em 2em; padding: 0em 0em;
|
19
|
+
background: #eeeeee none; color: #111111;
|
20
|
+
font-style: normal; font-weight: normal; }
|
21
|
+
h1 { margin-top: 1.8em; margin-bottom: 1.3em; font-weight: bold; }
|
22
|
+
h2 { margin-top: 1.8em; margin-bottom: 1.1em; font-weight: bold;
|
23
|
+
border-left: solid 0.6em #445555; border-bottom: solid 1pt #bbbbbb;
|
24
|
+
padding: 0.5em 0.5em; width: 60%; }
|
25
|
+
h3 { margin-top: 1.8em; margin-bottom: 0.8em; font-weight: bold; }
|
26
|
+
hr { margin-top: 2.5em; margin-bottom: 1.5em; height: 1pt;
|
27
|
+
color: #999999; background-color: #999999; border: none; }
|
28
|
+
div.note,div.navi { text-align: right; }
|
29
|
+
div.logo { text-align: center; margin: 3em 0em; }
|
30
|
+
div.logo img { border: inset 2pt #ccccdd; }
|
31
|
+
p { margin: 0.8em 0em; line-height: 140%; }
|
32
|
+
p,dd { text-indent: 0.8em; }
|
33
|
+
div,pre { margin-left: 1.7em; margin-right: 1.7em; }
|
34
|
+
pre { background-color: #ddddee; padding: 0.2em; border: 1pt solid #bbbbcc; font-size: smaller; }
|
35
|
+
kbd { color: #111111; font-style: normal; font-weight: bold; }
|
36
|
+
a { color: #0022aa; text-decoration: none; }
|
37
|
+
a:hover,a:focus { color: #0033ee; text-decoration: underline; }
|
38
|
+
a.head { color: #111111; text-decoration: none; }
|
39
|
+
table { padding: 1pt 2pt 1pt 2pt; border: none; margin-left: 1.7em; border-collapse: collapse; }
|
40
|
+
th { padding: 1pt 4pt 1pt 4pt; border-style: none;
|
41
|
+
text-align: left; vertical-align: bottom; }
|
42
|
+
td { padding: 1pt 4pt 1pt 4pt; border: 1pt solid #333333;
|
43
|
+
text-align: left; vertical-align: top; }
|
44
|
+
ul,ol,dl { line-height: 140%; }
|
45
|
+
dt { margin-left: 1.2em; }
|
46
|
+
dd { margin-left: 2.0em; }
|
47
|
+
ul.lines { list-style-type: none; }
|
48
|
+
@media print {
|
49
|
+
html,body { margin: 0em 0em; background-color: #ffffff; color: #000000; }
|
50
|
+
h1 { padding: 8em 0em 0.5em 0em; text-align: center; }
|
51
|
+
h2 { page-break-before: always; }
|
52
|
+
div.note { text-align: center; }
|
53
|
+
div.navi,div.logo { display: none }
|
54
|
+
hr { display: none; }
|
55
|
+
pre { margin: 0.8em 0.8em; background-color: #ffffff;
|
56
|
+
border: 1pt solid #aaaaaa; font-size: smaller; }
|
57
|
+
a,kbd { color: #000000; text-decoration: none; }
|
58
|
+
h1,h2,h3 { font-family: sans-serif; }
|
59
|
+
p,div,li,dt,dd { font-family: serif; }
|
60
|
+
pre,kbd { font-family: monospace; }
|
61
|
+
dd { font-size: smaller; }
|
62
|
+
}
|
63
|
+
</style>
|
64
|
+
</head>
|
65
|
+
|
66
|
+
<body>
|
67
|
+
|
68
|
+
<h1>QDBM付属Ruby用API仕様書</h1>
|
69
|
+
|
70
|
+
<div class="note">Copyright (C) 2000-2006 Mikio Hirabayashi</div>
|
71
|
+
<div class="note">Last Update: Thu, 26 Oct 2006 15:00:20 +0900</div>
|
72
|
+
<div class="navi">[<a href="rbapidoc/index.html">API</a>] [<a href="rbspex.html" hreflang="en">English</a>]</div>
|
73
|
+
|
74
|
+
<hr />
|
75
|
+
|
76
|
+
<h2>目次</h2>
|
77
|
+
|
78
|
+
<ol>
|
79
|
+
<li><a href="#overview">概要</a></li>
|
80
|
+
<li><a href="#installation">インストール</a></li>
|
81
|
+
<li><a href="#examples">サンプルコード</a></li>
|
82
|
+
<li><a href="#bugs">バグ</a></li>
|
83
|
+
</ol>
|
84
|
+
|
85
|
+
<hr />
|
86
|
+
|
87
|
+
<h2><a name="overview" id="overview" class="head">概要</a></h2>
|
88
|
+
|
89
|
+
<p>QDBMにはRuby言語用のAPIがある。QDBMの基本APIと拡張APIと上級APIの関数群をRubyのクラス機構を用いてカプセル化したものである。また、Rubyのマルチスレッド機能においてスレッドセーフである。</p>
|
90
|
+
|
91
|
+
<p>クラス `Depot' か `Curia' か `Villa' のコンストラクタ `new' を呼び出してデータベースを開き、その戻り値のオブジェクトをハンドルにする。データベースを閉じるにはメソッド `close' を呼ぶ。ファイナライザは利用されないが、`new' のイテレータを用いることでデータベースの閉じ忘れを防ぐことができる。メソッド `put' はレコードを追加するために用いる。メソッド `out' はレコードを削除するために用いる。メソッド `get' はレコードを検索するために用いる。その他にも、C言語のAPIとほぼ同じ操作を利用することができる。各クラスは例外クラス `EANY' およびそのサブクラスを定数として持つ。それらは各メソッドが失敗した際に投げられる。</p>
|
92
|
+
|
93
|
+
<p>これらのクラスは `Enumerable' モジュールをMix-inしているので、`find' や `sort' といったメソッドが利用できる。また、`Hash' クラスに似せて '[]=' や '[]' 等のメソッドを定義しているので、普通のハッシュのように利用することができる。</p>
|
94
|
+
|
95
|
+
<p>データベースに格納するレコードのキーと値は文字列として扱われるが、バイナリデータをそのまま格納することも可能である。ただし、`Villa' は直列化可能かつ比較可能な任意のオブジェクトを格納することができる。`Depot' はファイルを用いてハッシュデータベースを実現し、`Curia' はディレクトリと複数のファイルを用いてハッシュデータベースを実現し、`Villa' はファイルを用いてB+木データベースを実現する。`Depot' は最も高速である。`Curia' は最もスケーラブルである。`Villa' はカーソルによって順序に基づく参照を可能にする。</p>
|
96
|
+
|
97
|
+
<p>`put' で既存のレコードの上書きがキャンセルされた際や `get' で存在しないレコードが検索された際には例外によって操作の失敗が通知されるが、それが鬱陶しい場合は `silent' フラグを真にするとよい。その場合は失敗が戻り値によって通知される。</p>
|
98
|
+
|
99
|
+
<p>APIの詳細に関しては、サブディレクトリ `<a href="rbapidoc/">rbapidoc</a>' の文書を参照すること。</p>
|
100
|
+
|
101
|
+
<hr />
|
102
|
+
|
103
|
+
<h2><a name="installation" id="installation" class="head">インストール</a></h2>
|
104
|
+
|
105
|
+
<p>Rubyの1.6.5以降のバージョンがインストールされ、QDBMが `/usr/local' 以下にインストールされていることが必要である。</p>
|
106
|
+
|
107
|
+
<p>インストール作業は、サブディレクトリ `ruby' をカレントディレクトリにして行う。</p>
|
108
|
+
|
109
|
+
<pre>cd ruby
|
110
|
+
</pre>
|
111
|
+
|
112
|
+
<p>ビルド環境を設定する。</p>
|
113
|
+
|
114
|
+
<pre>./configure
|
115
|
+
</pre>
|
116
|
+
|
117
|
+
<p>プログラムをビルドする。</p>
|
118
|
+
|
119
|
+
<pre>make
|
120
|
+
</pre>
|
121
|
+
|
122
|
+
<p>プログラムの自己診断テストを行う。</p>
|
123
|
+
|
124
|
+
<pre>make check
|
125
|
+
</pre>
|
126
|
+
|
127
|
+
<p>プログラムをインストールする。作業は `root' ユーザで行う。</p>
|
128
|
+
|
129
|
+
<pre>make install
|
130
|
+
</pre>
|
131
|
+
|
132
|
+
<p>一連の作業が終ると、Rubyのインストールディレクトリに応じた適当な場所に `depot.rb'、`mod_depot.so' 、`curia.rb' 、`mod_curia.so' 、`villa.rb' 、`mod_villa.so' 等のライブラリがインストールされ、コマンド `rbdptest' と `rbcrtest' と `rbvltest' が `/usr/local/bin' にインストールされる。</p>
|
133
|
+
|
134
|
+
<p>アンインストールするには、`./configure' をした後の状態で以下のコマンドを実行する。作業は `root' ユーザで行う。</p>
|
135
|
+
|
136
|
+
<pre>make uninstall
|
137
|
+
</pre>
|
138
|
+
|
139
|
+
<hr />
|
140
|
+
|
141
|
+
<h2><a name="examples" id="examples" class="head">サンプルコード</a></h2>
|
142
|
+
|
143
|
+
<p>名前と対応させて電話番号を格納し、それを検索するアプリケーションのサンプルコードを以下に示す。</p>
|
144
|
+
|
145
|
+
<pre>require 'depot'
|
146
|
+
|
147
|
+
NAME = "mikio"
|
148
|
+
NUMBER = "000-1234-5678"
|
149
|
+
DBNAME = "book"
|
150
|
+
|
151
|
+
def main
|
152
|
+
depot = nil
|
153
|
+
begin
|
154
|
+
|
155
|
+
# データベースを開く
|
156
|
+
depot = Depot::new(DBNAME, Depot::OWRITER | Depot::OCREAT)
|
157
|
+
|
158
|
+
# レコードを格納する
|
159
|
+
depot.put(NAME, NUMBER)
|
160
|
+
|
161
|
+
# レコードを取得する
|
162
|
+
printf("Name: %s\n", NAME)
|
163
|
+
printf("Number: %s\n", depot.get(NAME))
|
164
|
+
|
165
|
+
rescue Depot::EANY
|
166
|
+
printf("%s\n", $!)
|
167
|
+
return 1
|
168
|
+
ensure
|
169
|
+
|
170
|
+
# データベースを閉じる
|
171
|
+
if(depot)
|
172
|
+
begin
|
173
|
+
depot.close()
|
174
|
+
rescue Depot::EANY
|
175
|
+
printf("%s\n", $!)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
return 0
|
181
|
+
end
|
182
|
+
|
183
|
+
exit(main());
|
184
|
+
</pre>
|
185
|
+
|
186
|
+
<p>上記の例を `Hash' クラスに似せたインタフェースとイテレータを用いて書き直した例を以下に示す。</p>
|
187
|
+
|
188
|
+
<pre>require 'depot'
|
189
|
+
|
190
|
+
NAME = "mikio"
|
191
|
+
NUMBER = "000-1234-5678"
|
192
|
+
DBNAME = "book"
|
193
|
+
|
194
|
+
def main
|
195
|
+
begin
|
196
|
+
|
197
|
+
# データベースを開いて自動的に閉じる
|
198
|
+
Depot::new(DBNAME, Depot::OWRITER | Depot::OCREAT) do |depot|
|
199
|
+
|
200
|
+
# レコードを格納する
|
201
|
+
depot[NAME] = NUMBER
|
202
|
+
|
203
|
+
# レコードを取得する
|
204
|
+
printf("Name: %s\n", NAME)
|
205
|
+
printf("Number: %s\n", depot[NAME])
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
rescue Depot::EANY
|
210
|
+
printf("%s\n", $!)
|
211
|
+
return 1
|
212
|
+
end
|
213
|
+
return 0
|
214
|
+
end
|
215
|
+
|
216
|
+
exit(main());
|
217
|
+
</pre>
|
218
|
+
|
219
|
+
<p>`Villa' クラスを用いて文字列の前方一致検索を行う例を以下に示す。</p>
|
220
|
+
|
221
|
+
<pre>require 'villa'
|
222
|
+
|
223
|
+
DBNAME = "words"
|
224
|
+
PREFIX = "apple"
|
225
|
+
|
226
|
+
def main
|
227
|
+
begin
|
228
|
+
|
229
|
+
# データベースを開いて自動的に閉じる
|
230
|
+
Villa::new(DBNAME, Villa::OWRITER | Villa::OCREAT) do |villa|
|
231
|
+
|
232
|
+
# レコードを格納する
|
233
|
+
villa.put("applet", "little application", Villa::DDUP)
|
234
|
+
villa.put("aurora", "polar wonderwork", Villa::DDUP)
|
235
|
+
villa.put("apple", "delicious fruit", Villa::DDUP)
|
236
|
+
villa.put("amigo", "good friend", Villa::DDUP)
|
237
|
+
villa.put("apple", "big city", Villa::DDUP)
|
238
|
+
|
239
|
+
begin
|
240
|
+
|
241
|
+
# カーソルを候補の先頭に置く
|
242
|
+
villa.curjump(PREFIX)
|
243
|
+
|
244
|
+
# カーソルを走査する
|
245
|
+
while(true)
|
246
|
+
key = villa.curkey()
|
247
|
+
(key.index(PREFIX) == 0) || break
|
248
|
+
val = villa.curval()
|
249
|
+
printf("%s: %s\n", key, val)
|
250
|
+
villa.curnext()
|
251
|
+
end
|
252
|
+
|
253
|
+
rescue Villa::ENOITEM
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
rescue Villa::EANY
|
259
|
+
printf("%s\n", $!)
|
260
|
+
return 1
|
261
|
+
end
|
262
|
+
return 0
|
263
|
+
end
|
264
|
+
|
265
|
+
exit(main());
|
266
|
+
</pre>
|
267
|
+
|
268
|
+
<hr />
|
269
|
+
|
270
|
+
<h2><a name="bugs" id="bugs" class="head">バグ</a></h2>
|
271
|
+
|
272
|
+
<p>標準添付ライブラリの `DBM' クラスのインタフェースと微妙に違うところがある。</p>
|
273
|
+
|
274
|
+
<p>もしもRubyハッカー達の手にかかれば、より効率的な実装がなされるだろう。</p>
|
275
|
+
|
276
|
+
<p>インタフェースを簡潔にするため、Ruby用のCuriaにはラージオブジェクトを扱う機能はない。</p>
|
277
|
+
|
278
|
+
<hr />
|
279
|
+
|
280
|
+
</body>
|
281
|
+
|
282
|
+
</html>
|
283
|
+
|
284
|
+
<!-- END OF FILE -->
|
data/rbspex.html
ADDED
@@ -0,0 +1,284 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
|
3
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
6
|
+
|
7
|
+
<head>
|
8
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
9
|
+
<meta http-equiv="Content-Style-Type" content="text/css" />
|
10
|
+
<meta name="author" content="Mikio Hirabayashi" />
|
11
|
+
<meta name="keywords" content="QDBM, Ruby, Depot, Curia, Villa" />
|
12
|
+
<meta name="description" content="specifications of Ruby API of QDBM" />
|
13
|
+
<link rel="contents" href="./" />
|
14
|
+
<link rel="alternate" href="rbspex-ja.html" hreflang="ja" title="the Japanese version" />
|
15
|
+
<link rev="made" href="mailto:mikio@fallabs.com" />
|
16
|
+
<title>Specifications of QDBM for Ruby</title>
|
17
|
+
<style type="text/css">html { margin: 0em 0em; padding: 0em 0em; background: #eeeeee none; }
|
18
|
+
body { margin: 2em 2em; padding: 0em 0em;
|
19
|
+
background: #eeeeee none; color: #111111;
|
20
|
+
font-style: normal; font-weight: normal; }
|
21
|
+
h1 { margin-top: 1.8em; margin-bottom: 1.3em; font-weight: bold; }
|
22
|
+
h2 { margin-top: 1.8em; margin-bottom: 1.1em; font-weight: bold;
|
23
|
+
border-left: solid 0.6em #445555; border-bottom: solid 1pt #bbbbbb;
|
24
|
+
padding: 0.5em 0.5em; width: 60%; }
|
25
|
+
h3 { margin-top: 1.8em; margin-bottom: 0.8em; font-weight: bold; }
|
26
|
+
hr { margin-top: 2.5em; margin-bottom: 1.5em; height: 1pt;
|
27
|
+
color: #999999; background-color: #999999; border: none; }
|
28
|
+
div.note,div.navi { text-align: right; }
|
29
|
+
div.logo { text-align: center; margin: 3em 0em; }
|
30
|
+
div.logo img { border: inset 2pt #ccccdd; }
|
31
|
+
p { margin: 0.8em 0em; line-height: 140%; }
|
32
|
+
p,dd { text-indent: 0.8em; }
|
33
|
+
div,pre { margin-left: 1.7em; margin-right: 1.7em; }
|
34
|
+
pre { background-color: #ddddee; padding: 0.2em; border: 1pt solid #bbbbcc; font-size: smaller; }
|
35
|
+
kbd { color: #111111; font-style: normal; font-weight: bold; }
|
36
|
+
a { color: #0022aa; text-decoration: none; }
|
37
|
+
a:hover,a:focus { color: #0033ee; text-decoration: underline; }
|
38
|
+
a.head { color: #111111; text-decoration: none; }
|
39
|
+
table { padding: 1pt 2pt 1pt 2pt; border: none; margin-left: 1.7em; border-collapse: collapse; }
|
40
|
+
th { padding: 1pt 4pt 1pt 4pt; border-style: none;
|
41
|
+
text-align: left; vertical-align: bottom; }
|
42
|
+
td { padding: 1pt 4pt 1pt 4pt; border: 1pt solid #333333;
|
43
|
+
text-align: left; vertical-align: top; }
|
44
|
+
ul,ol,dl { line-height: 140%; }
|
45
|
+
dt { margin-left: 1.2em; }
|
46
|
+
dd { margin-left: 2.0em; }
|
47
|
+
ul.lines { list-style-type: none; }
|
48
|
+
@media print {
|
49
|
+
html,body { margin: 0em 0em; background-color: #ffffff; color: #000000; }
|
50
|
+
h1 { padding: 8em 0em 0.5em 0em; text-align: center; }
|
51
|
+
h2 { page-break-before: always; }
|
52
|
+
div.note { text-align: center; }
|
53
|
+
div.navi,div.logo { display: none }
|
54
|
+
hr { display: none; }
|
55
|
+
pre { margin: 0.8em 0.8em; background-color: #ffffff;
|
56
|
+
border: 1pt solid #aaaaaa; font-size: smaller; }
|
57
|
+
a,kbd { color: #000000; text-decoration: none; }
|
58
|
+
h1,h2,h3 { font-family: sans-serif; }
|
59
|
+
p,div,li,dt,dd { font-family: serif; }
|
60
|
+
pre,kbd { font-family: monospace; }
|
61
|
+
dd { font-size: smaller; }
|
62
|
+
}
|
63
|
+
</style>
|
64
|
+
</head>
|
65
|
+
|
66
|
+
<body>
|
67
|
+
|
68
|
+
<h1>Specifications of QDBM for Ruby</h1>
|
69
|
+
|
70
|
+
<div class="note">Copyright (C) 2000-2006 Mikio Hirabayashi</div>
|
71
|
+
<div class="note">Last Update: Thu, 26 Oct 2006 15:00:20 +0900</div>
|
72
|
+
<div class="navi">[<a href="rbapidoc/index.html">API</a>] [<a href="rbspex-ja.html" hreflang="ja">Japanese</a>]</div>
|
73
|
+
|
74
|
+
<hr />
|
75
|
+
|
76
|
+
<h2>Table of Contents</h2>
|
77
|
+
|
78
|
+
<ol>
|
79
|
+
<li><a href="#overview">Overview</a></li>
|
80
|
+
<li><a href="#installation">Installation</a></li>
|
81
|
+
<li><a href="#examples">Examples</a></li>
|
82
|
+
<li><a href="#bugs">Bugs</a></li>
|
83
|
+
</ol>
|
84
|
+
|
85
|
+
<hr />
|
86
|
+
|
87
|
+
<h2><a name="overview" id="overview" class="head">Overview</a></h2>
|
88
|
+
|
89
|
+
<p>QDBM provides API for Ruby. This encapsulates the basic API, the extended API and the advanced API of QDBM. These APIs are safe on multi thread environment of Ruby.</p>
|
90
|
+
|
91
|
+
<p>You call the constructor `new' of the class `Depot', `Curia' or `Villa' to open a database file or directory and get the handle. The method `close' is used in order to close the database. Although a finalizer is not used, an iterator of `new' method save you from neglecting to call `close'. The method `put' is used in order to store a record. The method `out' is used in order to delete a record. The method `get' is used in order to retrieve a record. Besides, most operations like ones of the APIs for C are available. Each class has class constants which are `EANY' and its sub classes. They are thrown when each method fails.</p>
|
92
|
+
|
93
|
+
<p>Because these classes perform Mix-in of the module `Enumerable', you can use such methods as `find', `sort', and so on. Moreover, they implements such methods: `[]=', `[]', and so on like the class `Hash', you can use a database like a usual hash.</p>
|
94
|
+
|
95
|
+
<p>Although keys and values of storing records are treated as strings, binary data can be stored as they are. But, `Villa' can store any serializable and comparable objects. `Depot' realizes a hash database with a file. `Curia' realizes a hash database with a directory and multiple files. `Villa' realizes a B+ tree database with a file. `Depot' is fastest. `Curia' is most scalable. `Villa' provides cursor supporting ordering access.</p>
|
96
|
+
|
97
|
+
<p>When `put' overwriting an existing record is cancelled or `get' retrieving a missing record, failure of the operation is noticed by exception. If you dislike such behavior, set the `silent' flag to be true. Then, failure of the operation is noticed by the return value.</p>
|
98
|
+
|
99
|
+
<p>For more information about the APIs, read documents in the sub directory `<a href="rbapidoc/">rbapidoc</a>'.</p>
|
100
|
+
|
101
|
+
<hr />
|
102
|
+
|
103
|
+
<h2><a name="installation" id="installation" class="head">Installation</a></h2>
|
104
|
+
|
105
|
+
<p>Make sure that Ruby 1.6.5 or later version is installed and make sure that QDBM is installed under `/usr/local'.</p>
|
106
|
+
|
107
|
+
<p>Change the current working directory to the sub directory named `ruby'.</p>
|
108
|
+
|
109
|
+
<pre>cd ruby
|
110
|
+
</pre>
|
111
|
+
|
112
|
+
<p>Run the configuration script.</p>
|
113
|
+
|
114
|
+
<pre>./configure
|
115
|
+
</pre>
|
116
|
+
|
117
|
+
<p>Build programs.</p>
|
118
|
+
|
119
|
+
<pre>make
|
120
|
+
</pre>
|
121
|
+
|
122
|
+
<p>Perform self-diagnostic test.</p>
|
123
|
+
|
124
|
+
<pre>make check
|
125
|
+
</pre>
|
126
|
+
|
127
|
+
<p>Install programs. This operation must be carried out by the root user.</p>
|
128
|
+
|
129
|
+
<pre>make install
|
130
|
+
</pre>
|
131
|
+
|
132
|
+
<p>When a series of work finishes, `depot.rb', `mod_depot.so', `curia.rb', `mod_curia.so', `villa.rb', `mod_villa.so', and so on are installed under an appropriate directory according to the install directory of Ruby. Executable commands `rbdptest', `rbcrtest', and `rbvltest' will be installed in `/usr/local/bin'.</p>
|
133
|
+
|
134
|
+
<p>To uninstall them, execute the following command after `./configure'. This operation must be carried out by the root user.</p>
|
135
|
+
|
136
|
+
<pre>make uninstall
|
137
|
+
</pre>
|
138
|
+
|
139
|
+
<hr />
|
140
|
+
|
141
|
+
<h2><a name="examples" id="examples" class="head">Examples</a></h2>
|
142
|
+
|
143
|
+
<p>The following example stores and retrieves a phone number, using the name as the key.</p>
|
144
|
+
|
145
|
+
<pre>require 'depot'
|
146
|
+
|
147
|
+
NAME = "mikio"
|
148
|
+
NUMBER = "000-1234-5678"
|
149
|
+
DBNAME = "book"
|
150
|
+
|
151
|
+
def main
|
152
|
+
depot = nil
|
153
|
+
begin
|
154
|
+
|
155
|
+
# open the database
|
156
|
+
depot = Depot::new(DBNAME, Depot::OWRITER | Depot::OCREAT)
|
157
|
+
|
158
|
+
# store the record
|
159
|
+
depot.put(NAME, NUMBER)
|
160
|
+
|
161
|
+
# retrieve the record
|
162
|
+
printf("Name: %s\n", NAME)
|
163
|
+
printf("Number: %s\n", depot.get(NAME))
|
164
|
+
|
165
|
+
rescue Depot::EANY
|
166
|
+
printf("%s\n", $!)
|
167
|
+
return 1
|
168
|
+
ensure
|
169
|
+
|
170
|
+
# close the database
|
171
|
+
if(depot)
|
172
|
+
begin
|
173
|
+
depot.close()
|
174
|
+
rescue Depot::EANY
|
175
|
+
printf("%s\n", $!)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
return 0
|
181
|
+
end
|
182
|
+
|
183
|
+
exit(main());
|
184
|
+
</pre>
|
185
|
+
|
186
|
+
<p>The following example is a transcription of the one above, using hash-like interface and iterator.</p>
|
187
|
+
|
188
|
+
<pre>require 'depot'
|
189
|
+
|
190
|
+
NAME = "mikio"
|
191
|
+
NUMBER = "000-1234-5678"
|
192
|
+
DBNAME = "book"
|
193
|
+
|
194
|
+
def main
|
195
|
+
begin
|
196
|
+
|
197
|
+
# open the database and close it automatically
|
198
|
+
Depot::new(DBNAME, Depot::OWRITER | Depot::OCREAT) do |depot|
|
199
|
+
|
200
|
+
# store the record
|
201
|
+
depot[NAME] = NUMBER
|
202
|
+
|
203
|
+
# retrieve the record
|
204
|
+
printf("Name: %s\n", NAME)
|
205
|
+
printf("Number: %s\n", depot[NAME])
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
rescue Depot::EANY
|
210
|
+
printf("%s\n", $!)
|
211
|
+
return 1
|
212
|
+
end
|
213
|
+
return 0
|
214
|
+
end
|
215
|
+
|
216
|
+
exit(main());
|
217
|
+
</pre>
|
218
|
+
|
219
|
+
<p>The following example performs forward matching search for strings, using the class `Villa'.</p>
|
220
|
+
|
221
|
+
<pre>require 'villa'
|
222
|
+
|
223
|
+
DBNAME = "words"
|
224
|
+
PREFIX = "apple"
|
225
|
+
|
226
|
+
def main
|
227
|
+
begin
|
228
|
+
|
229
|
+
# open the database and close it automatically
|
230
|
+
Villa::new(DBNAME, Villa::OWRITER | Villa::OCREAT) do |villa|
|
231
|
+
|
232
|
+
# store records
|
233
|
+
villa.put("applet", "little application", Villa::DDUP)
|
234
|
+
villa.put("aurora", "polar wonderwork", Villa::DDUP)
|
235
|
+
villa.put("apple", "delicious fruit", Villa::DDUP)
|
236
|
+
villa.put("amigo", "good friend", Villa::DDUP)
|
237
|
+
villa.put("apple", "big city", Villa::DDUP)
|
238
|
+
|
239
|
+
begin
|
240
|
+
|
241
|
+
# set the cursor at the top of candidates
|
242
|
+
villa.curjump(PREFIX)
|
243
|
+
|
244
|
+
# scan with the cursor
|
245
|
+
while(true)
|
246
|
+
key = villa.curkey()
|
247
|
+
(key.index(PREFIX) == 0) || break
|
248
|
+
val = villa.curval()
|
249
|
+
printf("%s: %s\n", key, val)
|
250
|
+
villa.curnext()
|
251
|
+
end
|
252
|
+
|
253
|
+
rescue Villa::ENOITEM
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
rescue Villa::EANY
|
259
|
+
printf("%s\n", $!)
|
260
|
+
return 1
|
261
|
+
end
|
262
|
+
return 0
|
263
|
+
end
|
264
|
+
|
265
|
+
exit(main());
|
266
|
+
</pre>
|
267
|
+
|
268
|
+
<hr />
|
269
|
+
|
270
|
+
<h2><a name="bugs" id="bugs" class="head">Bugs</a></h2>
|
271
|
+
|
272
|
+
<p>This API are subtly different from the interface of standard library `DBM'.</p>
|
273
|
+
|
274
|
+
<p>This API can be implemented more effectively by Ruby hackers.</p>
|
275
|
+
|
276
|
+
<p>For the sake of simplicity of interface, Curia for Ruby does not feature handling large objects.</p>
|
277
|
+
|
278
|
+
<hr />
|
279
|
+
|
280
|
+
</body>
|
281
|
+
|
282
|
+
</html>
|
283
|
+
|
284
|
+
<!-- END OF FILE -->
|