ruby-qdbm 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,426 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <meta http-equiv="Content-Style-Type" content="text/css" />
7
+ <link rel="contents" href="./" />
8
+ <link rev="made" href="mailto:mikio@fallabs.com" />
9
+ <title>depot (QDBM for Ruby)</title>
10
+ <style type="text/css">html { margin: 0em 0em; padding 0em 0em; background: #eeeeee none; }
11
+ body { background-color: #eeeeee; color: #111111; padding: 1.5em 2em; margin: 0em 0em;
12
+ border-left: double 3.0em #eedddd; border-right: solid 1.0em #eedddd;
13
+ font-style: normal; font-weight: normal; font-family: serif; }
14
+ h1 { margin-top: 0.8em; margin-bottom: 1.3em; font-weight: bold; font-family: sans-serif; }
15
+ h2 { margin-top: 1.8em; margin-bottom: 1.1em; font-weight: bold; font-family: sans-serif; }
16
+ h3 { margin-top: 1.8em; margin-bottom: 0.8em; font-weight: bold; font-family: sans-serif; }
17
+ p,ul,ol,dl { line-height: 140%; }
18
+ em { color: #111111; font-style: italic; font-weight: normal; font-family: serif; }
19
+ kbd { color: #111111; font-style: normal; font-weight: bold; font-family: monospace; }
20
+ a { color: #0022aa; text-decoration: none; }
21
+ a:hover { color: #0033ee; text-decoration: underline; }
22
+ a.head { color: #111111; text-decoration: none; }
23
+ .note { text-align: right; }
24
+ </style>
25
+ </head>
26
+ <body>
27
+ <div class="note">[<a href="index.html">Back</a>]</div>
28
+ <h1>API of depot</h1>
29
+ <hr />
30
+ <dl>
31
+ <dt><kbd>require 'depot'</kbd></dt>
32
+ <dd>
33
+ The library `depot' should be included in application codes.
34
+ An instance of the class `Depot' is used as a database handle.
35
+ `Depot' performs Mix-in of `Enumerable'.
36
+ Each method of `Depot' throws an exception of `Depot::EANY' or its sub classes when an error
37
+ occurs: `Depot::ENOERR', `Depot::EFATAL', `Depot::EMODE', `Depot::EBROKEN', `Depot::EKEEP',
38
+ `Depot::ENOITEM', `Depot::EALLOC', `Depot::EMAP', `Depot::EOPEN', `Depot::ECLOSE',
39
+ `Depot::ETRUNC', `Depot::ESYNC', `Depot::ESTAT', `Depot::ESEEK', `Depot::EREAD',
40
+ `Depot::EWRITE', `Depot::ELOCK', `Depot::EUNLINK', `Depot::EMKDIR', `Depot::ERMDIR' and
41
+ `Depot::EMISC'.
42
+ </dd>
43
+ </dl>
44
+ <dl>
45
+ <dt><kbd>depot = Depot::new(name, omode, bnum)</kbd></dt>
46
+ <dd>
47
+ Constructor: Get a database handle.
48
+ `name' specifies the name of a database file.
49
+ `omode' specifies the connection mode: `Depot::OWRITER' as a writer, `Depot::OREADER' as a
50
+ reader. If the mode is `Depot::OWRITER', the following may be added by bitwise or:
51
+ `Depot::OCREAT', which means it creates a new database if not exist, `Depot::OTRUNC', which
52
+ means it creates a new database regardless if one exists. Both of `Depot::OREADER' and
53
+ `Depot::OWRITER' can be added to by bitwise or: `Depot::ONOLCK', which means it opens a
54
+ database file without file locking, or `Depot::OLCKNB', which means locking is performed
55
+ without blocking. `Depot::OCREAT' can be added to by bitwise or: `Depot::OSPARSE', which
56
+ means it creates a database file as a sparse file. If it is omitted, `Depot::OREADER' is
57
+ specified.
58
+ `bnum' specifies the number of elements of the bucket array. If it is omitted or not more
59
+ than 0, the default value is specified. The size of a bucket array is determined on
60
+ creating, and can not be changed except for by optimization of the database. Suggested
61
+ size of a bucket array is about from 0.5 to 4 times of the number of all records to store.
62
+ The return value is the database handle.
63
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
64
+ If a block parameter is given, this method works as an iterator. A database handle is
65
+ opened and passed via the first argument of the block. The database handle is surely
66
+ closed when the block is over.
67
+ While connecting as a writer, an exclusive lock is invoked to the database file.
68
+ While connecting as a reader, a shared lock is invoked to the database file. The thread
69
+ blocks until the lock is achieved. If `Depot::ONOLCK' is used, the application is
70
+ responsible for exclusion control.
71
+ </dd>
72
+ </dl>
73
+ <dl>
74
+ <dt><kbd>depot = Depot::open(name, omode, bnum)</kbd></dt>
75
+ <dd>
76
+ Constructor: An alias of `new'.
77
+ </dd>
78
+ </dl>
79
+ <dl>
80
+ <dt><kbd>bool = depot.close()</kbd></dt>
81
+ <dd>
82
+ Method: Close the database handle.
83
+ The return value is always true.
84
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
85
+ Because the region of a closed handle is released, it becomes impossible to use the handle.
86
+ Updating a database is assured to be written when the handle is closed. If a writer opens
87
+ a database but does not close it appropriately, the database will be broken.
88
+ </dd>
89
+ </dl>
90
+ <dl>
91
+ <dt><kbd>depot.silent = bool</kbd></dt>
92
+ <dd>
93
+ Method: Set the flag whether to repress frequent exceptions.
94
+ The return value is the assigned value.
95
+ </dd>
96
+ </dl>
97
+ <dl>
98
+ <dt><kbd>bool = depot.put(key, val, dmode)</kbd></dt>
99
+ <dd>
100
+ Method: Store a record.
101
+ `key' specifies a key. Although it must be an instance of String, binary data is okey.
102
+ `val' specifies a value. Although it must be an instance of String, binary data is okey.
103
+ `dmode' specifies behavior when the key overlaps, by the following values: `Depot::DOVER',
104
+ which means the specified value overwrites the existing one, `Depot::DKEEP', which means
105
+ the existing value is kept, `Depot::DCAT', which means the specified value is concatenated
106
+ at the end of the existing value. If it is omitted, `Depot::DOVER' is specified.
107
+ The return value is always true. However, if the silent flag is true and replace is
108
+ cancelled, false is returned instead of exception.
109
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs or replace
110
+ is cancelled.
111
+ </dd>
112
+ </dl>
113
+ <dl>
114
+ <dt><kbd>bool = depot.store(key, val)</kbd></dt>
115
+ <dd>
116
+ Method: An alias of `put'.
117
+ </dd>
118
+ </dl>
119
+ <dl>
120
+ <dt><kbd>depot[key] = val</kbd></dt>
121
+ <dd>
122
+ Method: An alias of `put'.
123
+ </dd>
124
+ </dl>
125
+ <dl>
126
+ <dt><kbd>bool = depot.out(key)</kbd></dt>
127
+ <dd>
128
+ Method: Delete a record.
129
+ `key' specifies a key. Although it must be an instance of String, binary data is okey.
130
+ The return value is always true. However, if the silent flag is true and no record
131
+ corresponds, false is returned instead of exception.
132
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs or no record
133
+ corresponds.
134
+ </dd>
135
+ </dl>
136
+ <dl>
137
+ <dt><kbd>bool = depot.delete(key)</kbd></dt>
138
+ <dd>
139
+ Method: An alias of `out'.
140
+ </dd>
141
+ </dl>
142
+ <dl>
143
+ <dt><kbd>bool = depot.clear()</kbd></dt>
144
+ <dd>
145
+ Method: Delete all records.
146
+ The return value is always true.
147
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
148
+ </dd>
149
+ </dl>
150
+ <dl>
151
+ <dt><kbd>str = depot.get(key, start, max)</kbd></dt>
152
+ <dd>
153
+ Method: Retrieve a record.
154
+ `key' specifies a key. Although it must be an instance of String, binary data is okey.
155
+ `start' specifies the offset address of the beginning of the region of the value to be read.
156
+ If it is negative or omitted, the offset is specified as 0.
157
+ `max' specifies the max size to be read. If it is negative or omitted, the size to read is
158
+ unlimited.
159
+ The return value is an instance of the value of the corresponding record. If the silent flag
160
+ is true and no record corresponds, nil is returned instead of exception.
161
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs, no record
162
+ corresponds, or the size of the value of the corresponding record is less than `max'.
163
+ </dd>
164
+ </dl>
165
+ <dl>
166
+ <dt><kbd>str = depot.fetch(key, defval)</kbd></dt>
167
+ <dd>
168
+ Method: Retrieve a record.
169
+ `key' specifies a key. Although it must be an instance of String, binary data is okey.
170
+ `defval' specifies the default value used when no record corresponds. If it is omitted, nil
171
+ is specified.
172
+ The return value is an instance of the value of the corresponding record, or the default
173
+ value if no record corresponds.
174
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
175
+ </dd>
176
+ </dl>
177
+ <dl>
178
+ <dt><kbd>str = depot[key]</kbd></dt>
179
+ <dd>
180
+ Method: An alias of `fetch'.
181
+ </dd>
182
+ </dl>
183
+ <dl>
184
+ <dt><kbd>num = depot.vsiz(key)</kbd></dt>
185
+ <dd>
186
+ Method: Get the size of the value of a record.
187
+ `key' specifies a key. Although it must be an instance of String, binary data is okey.
188
+ The return value is the size of the value of the corresponding record. If the silent flag
189
+ is true and no record corresponds, -1 is returned instead of exception.
190
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs or no record
191
+ corresponds.
192
+ Because this method does not read the entity of a record, it is faster than `get'.
193
+ </dd>
194
+ </dl>
195
+ <dl>
196
+ <dt><kbd>bool = depot.iterinit()</kbd></dt>
197
+ <dd>
198
+ Method: Initialize the iterator of the database handle.
199
+ The return value is always true.
200
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
201
+ The iterator is used in order to access the key of every record stored in a database.
202
+ </dd>
203
+ </dl>
204
+ <dl>
205
+ <dt><kbd>str = depot.iternext()</kbd></dt>
206
+ <dd>
207
+ Method: Get the next key of the iterator.
208
+ The return value is the value of the next key. If the silent flag is true and no record
209
+ corresponds, nil is returned instead of exception.
210
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs or no record
211
+ is to be get out of the iterator.
212
+ It is possible to access every record by iteration of calling this method. However, it is
213
+ not assured if updating the database is occurred while the iteration. Besides, the order
214
+ of this traversal access method is arbitrary, so it is not assured that the order of
215
+ storing matches the one of the traversal access.
216
+ </dd>
217
+ </dl>
218
+ <dl>
219
+ <dt><kbd>bool = depot.setalign(align)</kbd></dt>
220
+ <dd>
221
+ Method: Set alignment of the database handle.
222
+ `align' specifies the basic size of alignment. If it is omitted, alignment is cleared.
223
+ The return value is always true.
224
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
225
+ If alignment is set to a database, the efficiency of overwriting values is improved.
226
+ The size of alignment is suggested to be average size of the values of the records to be
227
+ stored. If alignment is positive, padding whose size is multiple number of the alignment
228
+ is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding
229
+ is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not
230
+ saved in a database, you should specify alignment every opening a database.
231
+ </dd>
232
+ </dl>
233
+ <dl>
234
+ <dt><kbd>bool = depot.setfbpsiz(size);</kbd></dt>
235
+ <dd>
236
+ Method: Set the size of the free block pool.
237
+ `size' specifies the size of the free block pool. If it is undef, the free block pool is not
238
+ used.
239
+ The return value is always true.
240
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
241
+ The default size of the free block pool is 16. If the size is greater, the space efficiency
242
+ of overwriting values is improved with the time efficiency sacrificed.
243
+ </dd>
244
+ </dl>
245
+ <dl>
246
+ <dt><kbd>bool = depot.sync()</kbd></dt>
247
+ <dd>
248
+ Method: Synchronize updating contents with the file and the device.
249
+ The return value is always true.
250
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
251
+ This method is useful when another process uses the connected database file.
252
+ </dd>
253
+ </dl>
254
+ <dl>
255
+ <dt><kbd>bool = depot.optimize(bnum)</kbd></dt>
256
+ <dd>
257
+ Method: Optimize the database.
258
+ `bnum' specifies the number of the elements of the bucket array. If it is omitted or not
259
+ more than 0, the default value is specified.
260
+ The return value is always true.
261
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
262
+ In an alternating succession of deleting and storing with overwrite or concatenate,
263
+ dispensable regions accumulate. This method is useful to do away with them.
264
+ </dd>
265
+ </dl>
266
+ <dl>
267
+ <dt><kbd>num = depot.fsiz()</kbd></dt>
268
+ <dd>
269
+ Method: Get the size of the database file.
270
+ The return value is the size of the database file.
271
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
272
+ </dd>
273
+ </dl>
274
+ <dl>
275
+ <dt><kbd>num = depot.bnum()</kbd></dt>
276
+ <dd>
277
+ Method: Get the number of the elements of the bucket array.
278
+ The return value is the number of the elements of the bucket array
279
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
280
+ </dd>
281
+ </dl>
282
+ <dl>
283
+ <dt><kbd>num = depot.rnum()</kbd></dt>
284
+ <dd>
285
+ Method: Get the number of the records stored in the database.
286
+ The return value is the number of the records stored in the database.
287
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
288
+ </dd>
289
+ </dl>
290
+ <dl>
291
+ <dt><kbd>num = depot.length()</kbd></dt>
292
+ <dd>
293
+ Method: An alias of `rnum'.
294
+ </dd>
295
+ </dl>
296
+ <dl>
297
+ <dt><kbd>num = depot.size()</kbd></dt>
298
+ <dd>
299
+ Method: An alias of `rnum'.
300
+ </dd>
301
+ </dl>
302
+ <dl>
303
+ <dt><kbd>bool = depot.writable()</kbd></dt>
304
+ <dd>
305
+ Method: Check whether the database handle is a writer or not.
306
+ The return value is true if the handle is a writer, false if not.
307
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
308
+ </dd>
309
+ </dl>
310
+ <dl>
311
+ <dt><kbd>bool = depot.fatalerror()</kbd></dt>
312
+ <dd>
313
+ Method: Check whether the database has a fatal error or not.
314
+ The return value is true if the database has a fatal error, false if not.
315
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
316
+ </dd>
317
+ </dl>
318
+ <dl>
319
+ <dt><kbd>depot.each() do |key, val| ... end</kbd></dt>
320
+ <dd>
321
+ Iterator Method: Iterate a process with a pair of a key and a value of each record.
322
+ </dd>
323
+ </dl>
324
+ <dl>
325
+ <dt><kbd>depot.each_pair() do |key, val| ... end</kbd></dt>
326
+ <dd>
327
+ Iterator Method: An alias of `each'.
328
+ </dd>
329
+ </dl>
330
+ <dl>
331
+ <dt><kbd>depot.each_key() do |key| ... end</kbd></dt>
332
+ <dd>
333
+ Iterator Method: Iterate a process with a key of each record.
334
+ </dd>
335
+ </dl>
336
+ <dl>
337
+ <dt><kbd>depot.each_value() do |val| ... end</kbd></dt>
338
+ <dd>
339
+ Iterator Method: Iterate a process with a value of each record.
340
+ </dd>
341
+ </dl>
342
+ <dl>
343
+ <dt><kbd>ary = depot.keys()</kbd></dt>
344
+ <dd>
345
+ Method: Get an array of all keys.
346
+ The return value is an array of all keys.
347
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
348
+ </dd>
349
+ </dl>
350
+ <dl>
351
+ <dt><kbd>ary = depot.values()</kbd></dt>
352
+ <dd>
353
+ Method: Get an array of all values.
354
+ The return value is an array of all values.
355
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs.
356
+ </dd>
357
+ </dl>
358
+ <dl>
359
+ <dt><kbd>str = depot.index(val)</kbd></dt>
360
+ <dd>
361
+ Method: Retrieve a record with a value.
362
+ `val' specifies a value. Although it must be an instance of String, binary data is okey.
363
+ The return value is the key of the record with the specified value.
364
+ An exception of `Depot::EANY' or its sub classes is thrown if an error occurs or no record
365
+ corresponds.
366
+ If two or more records correspond, the first found record is selected.
367
+ </dd>
368
+ </dl>
369
+ <dl>
370
+ <dt><kbd>num = depot.to_int()</kbd></dt>
371
+ <dd>
372
+ Method: An alias of `rnum'.
373
+ </dd>
374
+ </dl>
375
+ <dl>
376
+ <dt><kbd>num = depot.to_i()</kbd></dt>
377
+ <dd>
378
+ Method: An alias of `to_int'.
379
+ </dd>
380
+ </dl>
381
+ <dl>
382
+ <dt><kbd>str = depot.to_str()</kbd></dt>
383
+ <dd>
384
+ Method: Get string standing for the instance.
385
+ </dd>
386
+ </dl>
387
+ <dl>
388
+ <dt><kbd>str = depot.to_s()</kbd></dt>
389
+ <dd>
390
+ Method: An alias of `to_str'.
391
+ </dd>
392
+ </dl>
393
+ <dl>
394
+ <dt><kbd>ary = depot.to_ary()</kbd></dt>
395
+ <dd>
396
+ Method: Get an array of alternation of each pair of a key and a value.
397
+ </dd>
398
+ </dl>
399
+ <dl>
400
+ <dt><kbd>ary = depot.to_a()</kbd></dt>
401
+ <dd>
402
+ Method: An alias of `to_ary'.
403
+ </dd>
404
+ </dl>
405
+ <dl>
406
+ <dt><kbd>hash = depot.to_hash()</kbd></dt>
407
+ <dd>
408
+ Method: Get a hash storing all records.
409
+ </dd>
410
+ </dl>
411
+ <dl>
412
+ <dt><kbd>hash = depot.to_h()</kbd></dt>
413
+ <dd>
414
+ Method: An alias of `to_hash'.
415
+ </dd>
416
+ </dl>
417
+ <dl>
418
+ <dt><kbd>str = depot.inspect()</kbd></dt>
419
+ <dd>
420
+ Method: An alias of `to_str'.
421
+ </dd>
422
+ </dl>
423
+ <hr />
424
+ <div class="note">Generated by ./myrbdoc, 2010/08/05.</div>
425
+ </body>
426
+ </html>
@@ -0,0 +1,46 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <meta http-equiv="Content-Style-Type" content="text/css" />
7
+ <link rel="contents" href="./" />
8
+ <link rev="made" href="mailto:mikio@fallabs.com" />
9
+ <title>INDEX (QDBM for Ruby)</title>
10
+ <style type="text/css">html { margin: 0em 0em; padding 0em 0em; background: #eeeeee none; }
11
+ body { background-color: #eeeeee; color: #111111; padding: 1.5em 2em; margin: 0em 0em;
12
+ border-left: double 3.0em #eedddd; border-right: solid 1.0em #eedddd;
13
+ font-style: normal; font-weight: normal; font-family: serif; }
14
+ h1 { margin-top: 0.8em; margin-bottom: 1.3em; font-weight: bold; font-family: sans-serif; }
15
+ h2 { margin-top: 1.8em; margin-bottom: 1.1em; font-weight: bold; font-family: sans-serif; }
16
+ h3 { margin-top: 1.8em; margin-bottom: 0.8em; font-weight: bold; font-family: sans-serif; }
17
+ p,ul,ol,dl { line-height: 140%; }
18
+ em { color: #111111; font-style: italic; font-weight: normal; font-family: serif; }
19
+ kbd { color: #111111; font-style: normal; font-weight: bold; font-family: monospace; }
20
+ a { color: #0022aa; text-decoration: none; }
21
+ a:hover { color: #0033ee; text-decoration: underline; }
22
+ a.head { color: #111111; text-decoration: none; }
23
+ .note { text-align: right; }
24
+ </style>
25
+ </head>
26
+ <body>
27
+ <div class="note">Ruby Source Documents</div>
28
+ <h1>QDBM for Ruby</h1>
29
+ <hr />
30
+ <h2>Overview</h2>
31
+ <p>QDBM is a library of routines for managing a database. The database is a simple data file containing records, each is a pair of a key and a value. Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. There is neither concept of data tables nor data types. Records are organazed in hash table or B+ tree.</p>
32
+ <p>As for database of hash table, each key must be unique within a database, so it is impossible to store two or more records with a key overlaps. The following access methods are provided to the database: storing a record with a key and a value, deleting a record by a key, retrieving a record by a key. Moreover, traversal access to every key are provided, although the order is arbitrary. These access methods are similar to ones of DBM (or its followers, NDBM and GDBM) library defined in the UNIX standard. QDBM is an alternative for DBM because of its higher performance.</p>
33
+ <p>As for database of B+ tree, records whose keys are duplicated can be stored. Access methods of storing, deleting and retrieving are provided as with the database of hash table. Records are stored in order by a comparing function assigned by a user. It is possible to access each record with the cursor in ascending or descending order. According to this mechanism, forward matching search for strings and range search for integers are realized.</p>
34
+ <p>QDBM provides API for Ruby. This encapsulates the basic API, the extended API and the extended API of QDBM. A database handle can be used like an instance of `Hash'.</p>
35
+ <p>Refer to `<a href="http://fallabs.com/qdbm/">http://fallabs.com/qdbm/</a>' for more information.</p>
36
+ <hr />
37
+ <h2>API</h2>
38
+ <ul>
39
+ <li><a href="depot.rb.html">depot</a></li>
40
+ <li><a href="curia.rb.html">curia</a></li>
41
+ <li><a href="villa.rb.html">villa</a></li>
42
+ </ul>
43
+ <hr />
44
+ <div class="note">Generated by ./myrbdoc, 2010/08/05.</div>
45
+ </body>
46
+ </html>