tokyomessenger 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +504 -0
- data/README.rdoc +224 -0
- data/Rakefile +72 -0
- data/benchmarks/balancer.rb +101 -0
- data/benchmarks/bulk_db.rb +92 -0
- data/benchmarks/bulk_table.rb +104 -0
- data/benchmarks/db.rb +131 -0
- data/benchmarks/table.rb +186 -0
- data/ext/a.h +496 -0
- data/ext/extconf.rb +27 -0
- data/ext/md5.c +381 -0
- data/ext/md5.h +101 -0
- data/ext/tc_myconf.c +493 -0
- data/ext/tc_myconf.h +543 -0
- data/ext/tcadb.c +4339 -0
- data/ext/tcadb.h +533 -0
- data/ext/tcbdb.c +4180 -0
- data/ext/tcbdb.h +1086 -0
- data/ext/tcfdb.c +2746 -0
- data/ext/tcfdb.h +842 -0
- data/ext/tchdb.c +5153 -0
- data/ext/tchdb.h +856 -0
- data/ext/tcrdb.c +2637 -0
- data/ext/tcrdb.h +785 -0
- data/ext/tctdb.c +6199 -0
- data/ext/tctdb.h +1070 -0
- data/ext/tcutil.c +10528 -0
- data/ext/tcutil.h +4166 -0
- data/ext/tokyo_messenger.c +147 -0
- data/ext/tokyo_messenger.h +49 -0
- data/ext/tokyo_messenger_db.c +227 -0
- data/ext/tokyo_messenger_db.h +8 -0
- data/ext/tokyo_messenger_module.c +453 -0
- data/ext/tokyo_messenger_module.h +10 -0
- data/ext/tokyo_messenger_query.c +226 -0
- data/ext/tokyo_messenger_query.h +9 -0
- data/ext/tokyo_messenger_table.c +319 -0
- data/ext/tokyo_messenger_table.h +8 -0
- data/ext/tt_myconf.c +169 -0
- data/ext/tt_myconf.h +408 -0
- data/ext/ttutil.c +1509 -0
- data/ext/ttutil.h +480 -0
- data/lib/tokyo_messenger/balancer.rb +188 -0
- data/spec/ext.lua +4 -0
- data/spec/plu_db.rb +538 -0
- data/spec/spec.rb +1 -0
- data/spec/spec_base.rb +17 -0
- data/spec/start_tyrants.sh +36 -0
- data/spec/stop_tyrants.sh +9 -0
- data/spec/tokyo_tyrant_balancer_db_spec.rb +160 -0
- data/spec/tokyo_tyrant_balancer_table_spec.rb +177 -0
- data/spec/tokyo_tyrant_query_spec.rb +159 -0
- data/spec/tokyo_tyrant_spec.rb +254 -0
- data/spec/tokyo_tyrant_table_spec.rb +301 -0
- metadata +117 -0
data/ext/tchdb.h
ADDED
@@ -0,0 +1,856 @@
|
|
1
|
+
/*************************************************************************************************
|
2
|
+
* The hash database API of Tokyo Cabinet
|
3
|
+
* Copyright (C) 2006-2009 Mikio Hirabayashi
|
4
|
+
* This file is part of Tokyo Cabinet.
|
5
|
+
* Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
|
6
|
+
* the GNU Lesser General Public License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope
|
8
|
+
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
10
|
+
* License for more details.
|
11
|
+
* You should have received a copy of the GNU Lesser General Public License along with Tokyo
|
12
|
+
* Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
13
|
+
* Boston, MA 02111-1307 USA.
|
14
|
+
*************************************************************************************************/
|
15
|
+
|
16
|
+
|
17
|
+
#ifndef _TCHDB_H /* duplication check */
|
18
|
+
#define _TCHDB_H
|
19
|
+
|
20
|
+
#include "tcutil.h"
|
21
|
+
|
22
|
+
/*************************************************************************************************
|
23
|
+
* API
|
24
|
+
*************************************************************************************************/
|
25
|
+
|
26
|
+
|
27
|
+
typedef struct { /* type of structure for a hash database */
|
28
|
+
void *mmtx; /* mutex for method */
|
29
|
+
void *rmtxs; /* mutexes for records */
|
30
|
+
void *dmtx; /* mutex for the while database */
|
31
|
+
void *tmtx; /* mutex for transaction */
|
32
|
+
void *wmtx; /* mutex for write ahead logging */
|
33
|
+
void *eckey; /* key for thread specific error code */
|
34
|
+
char *rpath; /* real path for locking */
|
35
|
+
uint8_t type; /* database type */
|
36
|
+
uint8_t flags; /* additional flags */
|
37
|
+
uint64_t bnum; /* number of the bucket array */
|
38
|
+
uint8_t apow; /* power of record alignment */
|
39
|
+
uint8_t fpow; /* power of free block pool number */
|
40
|
+
uint8_t opts; /* options */
|
41
|
+
char *path; /* path of the database file */
|
42
|
+
int fd; /* file descriptor of the database file */
|
43
|
+
uint32_t omode; /* open mode */
|
44
|
+
uint64_t rnum; /* number of the records */
|
45
|
+
uint64_t fsiz; /* size of the database file */
|
46
|
+
uint64_t frec; /* offset of the first record */
|
47
|
+
uint64_t dfcur; /* offset of the cursor for defragmentation */
|
48
|
+
uint64_t iter; /* offset of the iterator */
|
49
|
+
char *map; /* pointer to the mapped memory */
|
50
|
+
uint64_t msiz; /* size of the mapped memory */
|
51
|
+
uint64_t xmsiz; /* size of the extra mapped memory */
|
52
|
+
uint64_t xfsiz; /* extra size of the file for mapped memory */
|
53
|
+
uint32_t *ba32; /* 32-bit bucket array */
|
54
|
+
uint64_t *ba64; /* 64-bit bucket array */
|
55
|
+
uint32_t align; /* record alignment */
|
56
|
+
uint32_t runit; /* record reading unit */
|
57
|
+
bool zmode; /* whether compression is used */
|
58
|
+
int32_t fbpmax; /* maximum number of the free block pool */
|
59
|
+
void *fbpool; /* free block pool */
|
60
|
+
int32_t fbpnum; /* number of the free block pool */
|
61
|
+
int32_t fbpmis; /* number of missing retrieval of the free block pool */
|
62
|
+
bool async; /* whether asynchronous storing is called */
|
63
|
+
TCXSTR *drpool; /* delayed record pool */
|
64
|
+
TCXSTR *drpdef; /* deferred records of the delayed record pool */
|
65
|
+
uint64_t drpoff; /* offset of the delayed record pool */
|
66
|
+
TCMDB *recc; /* cache for records */
|
67
|
+
uint32_t rcnum; /* maximum number of cached records */
|
68
|
+
TCCODEC enc; /* pointer to the encoding function */
|
69
|
+
void *encop; /* opaque object for the encoding functions */
|
70
|
+
TCCODEC dec; /* pointer to the decoding function */
|
71
|
+
void *decop; /* opaque object for the decoding functions */
|
72
|
+
int ecode; /* last happened error code */
|
73
|
+
bool fatal; /* whether a fatal error occured */
|
74
|
+
uint64_t inode; /* inode number */
|
75
|
+
time_t mtime; /* modification time */
|
76
|
+
uint32_t dfunit; /* unit step number of auto defragmentation */
|
77
|
+
uint32_t dfcnt; /* counter of auto defragmentation */
|
78
|
+
bool tran; /* whether in the transaction */
|
79
|
+
int walfd; /* file descriptor of write ahead logging */
|
80
|
+
uint64_t walend; /* end offset of write ahead logging */
|
81
|
+
int dbgfd; /* file descriptor for debugging */
|
82
|
+
int64_t cnt_writerec; /* tesing counter for record write times */
|
83
|
+
int64_t cnt_reuserec; /* tesing counter for record reuse times */
|
84
|
+
int64_t cnt_moverec; /* tesing counter for record move times */
|
85
|
+
int64_t cnt_readrec; /* tesing counter for record read times */
|
86
|
+
int64_t cnt_searchfbp; /* tesing counter for FBP search times */
|
87
|
+
int64_t cnt_insertfbp; /* tesing counter for FBP insert times */
|
88
|
+
int64_t cnt_splicefbp; /* tesing counter for FBP splice times */
|
89
|
+
int64_t cnt_dividefbp; /* tesing counter for FBP divide times */
|
90
|
+
int64_t cnt_mergefbp; /* tesing counter for FBP merge times */
|
91
|
+
int64_t cnt_reducefbp; /* tesing counter for FBP reduce times */
|
92
|
+
int64_t cnt_appenddrp; /* tesing counter for DRP append times */
|
93
|
+
int64_t cnt_deferdrp; /* tesing counter for DRP defer times */
|
94
|
+
int64_t cnt_flushdrp; /* tesing counter for DRP flush times */
|
95
|
+
int64_t cnt_adjrecc; /* tesing counter for record cache adjust times */
|
96
|
+
int64_t cnt_defrag; /* tesing counter for defragmentation times */
|
97
|
+
int64_t cnt_shiftrec; /* tesing counter for record shift times */
|
98
|
+
int64_t cnt_trunc; /* tesing counter for truncation times */
|
99
|
+
} TCHDB;
|
100
|
+
|
101
|
+
enum { /* enumeration for additional flags */
|
102
|
+
HDBFOPEN = 1 << 0, /* whether opened */
|
103
|
+
HDBFFATAL = 1 << 1 /* whetehr with fatal error */
|
104
|
+
};
|
105
|
+
|
106
|
+
enum { /* enumeration for tuning options */
|
107
|
+
HDBTLARGE = 1 << 0, /* use 64-bit bucket array */
|
108
|
+
HDBTDEFLATE = 1 << 1, /* compress each record with Deflate */
|
109
|
+
HDBTBZIP = 1 << 2, /* compress each record with BZIP2 */
|
110
|
+
HDBTTCBS = 1 << 3, /* compress each record with TCBS */
|
111
|
+
HDBTEXCODEC = 1 << 4 /* compress each record with custom functions */
|
112
|
+
};
|
113
|
+
|
114
|
+
enum { /* enumeration for open modes */
|
115
|
+
HDBOREADER = 1 << 0, /* open as a reader */
|
116
|
+
HDBOWRITER = 1 << 1, /* open as a writer */
|
117
|
+
HDBOCREAT = 1 << 2, /* writer creating */
|
118
|
+
HDBOTRUNC = 1 << 3, /* writer truncating */
|
119
|
+
HDBONOLCK = 1 << 4, /* open without locking */
|
120
|
+
HDBOLCKNB = 1 << 5, /* lock without blocking */
|
121
|
+
HDBOTSYNC = 1 << 6 /* synchronize every transaction */
|
122
|
+
};
|
123
|
+
|
124
|
+
|
125
|
+
/* Get the message string corresponding to an error code.
|
126
|
+
`ecode' specifies the error code.
|
127
|
+
The return value is the message string of the error code. */
|
128
|
+
const char *tchdberrmsg(int ecode);
|
129
|
+
|
130
|
+
|
131
|
+
/* Create a hash database object.
|
132
|
+
The return value is the new hash database object. */
|
133
|
+
TCHDB *tchdbnew(void);
|
134
|
+
|
135
|
+
|
136
|
+
/* Delete a hash database object.
|
137
|
+
`hdb' specifies the hash database object.
|
138
|
+
If the database is not closed, it is closed implicitly. Note that the deleted object and its
|
139
|
+
derivatives can not be used anymore. */
|
140
|
+
void tchdbdel(TCHDB *hdb);
|
141
|
+
|
142
|
+
|
143
|
+
/* Get the last happened error code of a hash database object.
|
144
|
+
`hdb' specifies the hash database object.
|
145
|
+
The return value is the last happened error code.
|
146
|
+
The following error codes are defined: `TCESUCCESS' for success, `TCETHREAD' for threading
|
147
|
+
error, `TCEINVALID' for invalid operation, `TCENOFILE' for file not found, `TCENOPERM' for no
|
148
|
+
permission, `TCEMETA' for invalid meta data, `TCERHEAD' for invalid record header, `TCEOPEN'
|
149
|
+
for open error, `TCECLOSE' for close error, `TCETRUNC' for trunc error, `TCESYNC' for sync
|
150
|
+
error, `TCESTAT' for stat error, `TCESEEK' for seek error, `TCEREAD' for read error,
|
151
|
+
`TCEWRITE' for write error, `TCEMMAP' for mmap error, `TCELOCK' for lock error, `TCEUNLINK'
|
152
|
+
for unlink error, `TCERENAME' for rename error, `TCEMKDIR' for mkdir error, `TCERMDIR' for
|
153
|
+
rmdir error, `TCEKEEP' for existing record, `TCENOREC' for no record found, and `TCEMISC' for
|
154
|
+
miscellaneous error. */
|
155
|
+
int tchdbecode(TCHDB *hdb);
|
156
|
+
|
157
|
+
|
158
|
+
/* Set mutual exclusion control of a hash database object for threading.
|
159
|
+
`hdb' specifies the hash database object which is not opened.
|
160
|
+
If successful, the return value is true, else, it is false.
|
161
|
+
Note that the mutual exclusion control is needed if the object is shared by plural threads and
|
162
|
+
this function should be called before the database is opened. */
|
163
|
+
bool tchdbsetmutex(TCHDB *hdb);
|
164
|
+
|
165
|
+
|
166
|
+
/* Set the tuning parameters of a hash database object.
|
167
|
+
`hdb' specifies the hash database object which is not opened.
|
168
|
+
`bnum' specifies the number of elements of the bucket array. If it is not more than 0, the
|
169
|
+
default value is specified. The default value is 131071. Suggested size of the bucket array
|
170
|
+
is about from 0.5 to 4 times of the number of all records to be stored.
|
171
|
+
`apow' specifies the size of record alignment by power of 2. If it is negative, the default
|
172
|
+
value is specified. The default value is 4 standing for 2^4=16.
|
173
|
+
`fpow' specifies the maximum number of elements of the free block pool by power of 2. If it
|
174
|
+
is negative, the default value is specified. The default value is 10 standing for 2^10=1024.
|
175
|
+
`opts' specifies options by bitwise-or: `HDBTLARGE' specifies that the size of the database
|
176
|
+
can be larger than 2GB by using 64-bit bucket array, `HDBTDEFLATE' specifies that each record
|
177
|
+
is compressed with Deflate encoding, `HDBTBZIP' specifies that each record is compressed with
|
178
|
+
BZIP2 encoding, `HDBTTCBS' specifies that each record is compressed with TCBS encoding.
|
179
|
+
If successful, the return value is true, else, it is false.
|
180
|
+
Note that the tuning parameters should be set before the database is opened. */
|
181
|
+
bool tchdbtune(TCHDB *hdb, int64_t bnum, int8_t apow, int8_t fpow, uint8_t opts);
|
182
|
+
|
183
|
+
|
184
|
+
/* Set the caching parameters of a hash database object.
|
185
|
+
`hdb' specifies the hash database object which is not opened.
|
186
|
+
`rcnum' specifies the maximum number of records to be cached. If it is not more than 0, the
|
187
|
+
record cache is disabled. It is disabled by default.
|
188
|
+
If successful, the return value is true, else, it is false.
|
189
|
+
Note that the caching parameters should be set before the database is opened. */
|
190
|
+
bool tchdbsetcache(TCHDB *hdb, int32_t rcnum);
|
191
|
+
|
192
|
+
|
193
|
+
/* Set the size of the extra mapped memory of a hash database object.
|
194
|
+
`hdb' specifies the hash database object which is not opened.
|
195
|
+
`xmsiz' specifies the size of the extra mapped memory. If it is not more than 0, the extra
|
196
|
+
mapped memory is disabled. The default size is 67108864.
|
197
|
+
If successful, the return value is true, else, it is false.
|
198
|
+
Note that the mapping parameters should be set before the database is opened. */
|
199
|
+
bool tchdbsetxmsiz(TCHDB *hdb, int64_t xmsiz);
|
200
|
+
|
201
|
+
|
202
|
+
/* Set the unit step number of auto defragmentation of a hash database object.
|
203
|
+
`hdb' specifies the hash database object which is not opened.
|
204
|
+
`dfunit' specifie the unit step number. If it is not more than 0, the auto defragmentation
|
205
|
+
is disabled. It is disabled by default.
|
206
|
+
If successful, the return value is true, else, it is false.
|
207
|
+
Note that the defragmentation parameters should be set before the database is opened. */
|
208
|
+
bool tchdbsetdfunit(TCHDB *hdb, int32_t dfunit);
|
209
|
+
|
210
|
+
|
211
|
+
/* Open a database file and connect a hash database object.
|
212
|
+
`hdb' specifies the hash database object which is not opened.
|
213
|
+
`path' specifies the path of the database file.
|
214
|
+
`omode' specifies the connection mode: `HDBOWRITER' as a writer, `HDBOREADER' as a reader.
|
215
|
+
If the mode is `HDBOWRITER', the following may be added by bitwise-or: `HDBOCREAT', which
|
216
|
+
means it creates a new database if not exist, `HDBOTRUNC', which means it creates a new
|
217
|
+
database regardless if one exists, `HDBOTSYNC', which means every transaction synchronizes
|
218
|
+
updated contents with the device. Both of `HDBOREADER' and `HDBOWRITER' can be added to by
|
219
|
+
bitwise-or: `HDBONOLCK', which means it opens the database file without file locking, or
|
220
|
+
`HDBOLCKNB', which means locking is performed without blocking.
|
221
|
+
If successful, the return value is true, else, it is false. */
|
222
|
+
bool tchdbopen(TCHDB *hdb, const char *path, int omode);
|
223
|
+
|
224
|
+
|
225
|
+
/* Close a hash database object.
|
226
|
+
`hdb' specifies the hash database object.
|
227
|
+
If successful, the return value is true, else, it is false.
|
228
|
+
Update of a database is assured to be written when the database is closed. If a writer opens
|
229
|
+
a database but does not close it appropriately, the database will be broken. */
|
230
|
+
bool tchdbclose(TCHDB *hdb);
|
231
|
+
|
232
|
+
|
233
|
+
/* Store a record into a hash database object.
|
234
|
+
`hdb' specifies the hash database object connected as a writer.
|
235
|
+
`kbuf' specifies the pointer to the region of the key.
|
236
|
+
`ksiz' specifies the size of the region of the key.
|
237
|
+
`vbuf' specifies the pointer to the region of the value.
|
238
|
+
`vsiz' specifies the size of the region of the value.
|
239
|
+
If successful, the return value is true, else, it is false.
|
240
|
+
If a record with the same key exists in the database, it is overwritten. */
|
241
|
+
bool tchdbput(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
|
242
|
+
|
243
|
+
|
244
|
+
/* Store a string record into a hash database object.
|
245
|
+
`hdb' specifies the hash database object connected as a writer.
|
246
|
+
`kstr' specifies the string of the key.
|
247
|
+
`vstr' specifies the string of the value.
|
248
|
+
If successful, the return value is true, else, it is false.
|
249
|
+
If a record with the same key exists in the database, it is overwritten. */
|
250
|
+
bool tchdbput2(TCHDB *hdb, const char *kstr, const char *vstr);
|
251
|
+
|
252
|
+
|
253
|
+
/* Store a new record into a hash database object.
|
254
|
+
`hdb' specifies the hash database object connected as a writer.
|
255
|
+
`kbuf' specifies the pointer to the region of the key.
|
256
|
+
`ksiz' specifies the size of the region of the key.
|
257
|
+
`vbuf' specifies the pointer to the region of the value.
|
258
|
+
`vsiz' specifies the size of the region of the value.
|
259
|
+
If successful, the return value is true, else, it is false.
|
260
|
+
If a record with the same key exists in the database, this function has no effect. */
|
261
|
+
bool tchdbputkeep(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
|
262
|
+
|
263
|
+
|
264
|
+
/* Store a new string record into a hash database object.
|
265
|
+
`hdb' specifies the hash database object connected as a writer.
|
266
|
+
`kstr' specifies the string of the key.
|
267
|
+
`vstr' specifies the string of the value.
|
268
|
+
If successful, the return value is true, else, it is false.
|
269
|
+
If a record with the same key exists in the database, this function has no effect. */
|
270
|
+
bool tchdbputkeep2(TCHDB *hdb, const char *kstr, const char *vstr);
|
271
|
+
|
272
|
+
|
273
|
+
/* Concatenate a value at the end of the existing record in a hash database object.
|
274
|
+
`hdb' specifies the hash database object connected as a writer.
|
275
|
+
`kbuf' specifies the pointer to the region of the key.
|
276
|
+
`ksiz' specifies the size of the region of the key.
|
277
|
+
`vbuf' specifies the pointer to the region of the value.
|
278
|
+
`vsiz' specifies the size of the region of the value.
|
279
|
+
If successful, the return value is true, else, it is false.
|
280
|
+
If there is no corresponding record, a new record is created. */
|
281
|
+
bool tchdbputcat(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
|
282
|
+
|
283
|
+
|
284
|
+
/* Concatenate a string value at the end of the existing record in a hash database object.
|
285
|
+
`hdb' specifies the hash database object connected as a writer.
|
286
|
+
`kstr' specifies the string of the key.
|
287
|
+
`vstr' specifies the string of the value.
|
288
|
+
If successful, the return value is true, else, it is false.
|
289
|
+
If there is no corresponding record, a new record is created. */
|
290
|
+
bool tchdbputcat2(TCHDB *hdb, const char *kstr, const char *vstr);
|
291
|
+
|
292
|
+
|
293
|
+
/* Store a record into a hash database object in asynchronous fashion.
|
294
|
+
`hdb' specifies the hash database object connected as a writer.
|
295
|
+
`kbuf' specifies the pointer to the region of the key.
|
296
|
+
`ksiz' specifies the size of the region of the key.
|
297
|
+
`vbuf' specifies the pointer to the region of the value.
|
298
|
+
`vsiz' specifies the size of the region of the value.
|
299
|
+
If successful, the return value is true, else, it is false.
|
300
|
+
If a record with the same key exists in the database, it is overwritten. Records passed to
|
301
|
+
this function are accumulated into the inner buffer and wrote into the file at a blast. */
|
302
|
+
bool tchdbputasync(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
|
303
|
+
|
304
|
+
|
305
|
+
/* Store a string record into a hash database object in asynchronous fashion.
|
306
|
+
`hdb' specifies the hash database object connected as a writer.
|
307
|
+
`kstr' specifies the string of the key.
|
308
|
+
`vstr' specifies the string of the value.
|
309
|
+
If successful, the return value is true, else, it is false.
|
310
|
+
If a record with the same key exists in the database, it is overwritten. Records passed to
|
311
|
+
this function are accumulated into the inner buffer and wrote into the file at a blast. */
|
312
|
+
bool tchdbputasync2(TCHDB *hdb, const char *kstr, const char *vstr);
|
313
|
+
|
314
|
+
|
315
|
+
/* Remove a record of a hash database object.
|
316
|
+
`hdb' specifies the hash database object connected as a writer.
|
317
|
+
`kbuf' specifies the pointer to the region of the key.
|
318
|
+
`ksiz' specifies the size of the region of the key.
|
319
|
+
If successful, the return value is true, else, it is false. */
|
320
|
+
bool tchdbout(TCHDB *hdb, const void *kbuf, int ksiz);
|
321
|
+
|
322
|
+
|
323
|
+
/* Remove a string record of a hash database object.
|
324
|
+
`hdb' specifies the hash database object connected as a writer.
|
325
|
+
`kstr' specifies the string of the key.
|
326
|
+
If successful, the return value is true, else, it is false. */
|
327
|
+
bool tchdbout2(TCHDB *hdb, const char *kstr);
|
328
|
+
|
329
|
+
|
330
|
+
/* Retrieve a record in a hash database object.
|
331
|
+
`hdb' specifies the hash database object.
|
332
|
+
`kbuf' specifies the pointer to the region of the key.
|
333
|
+
`ksiz' specifies the size of the region of the key.
|
334
|
+
`sp' specifies the pointer to the variable into which the size of the region of the return
|
335
|
+
value is assigned.
|
336
|
+
If successful, the return value is the pointer to the region of the value of the corresponding
|
337
|
+
record. `NULL' is returned if no record corresponds.
|
338
|
+
Because an additional zero code is appended at the end of the region of the return value,
|
339
|
+
the return value can be treated as a character string. Because the region of the return
|
340
|
+
value is allocated with the `malloc' call, it should be released with the `free' call when
|
341
|
+
it is no longer in use. */
|
342
|
+
void *tchdbget(TCHDB *hdb, const void *kbuf, int ksiz, int *sp);
|
343
|
+
|
344
|
+
|
345
|
+
/* Retrieve a string record in a hash database object.
|
346
|
+
`hdb' specifies the hash database object.
|
347
|
+
`kstr' specifies the string of the key.
|
348
|
+
If successful, the return value is the string of the value of the corresponding record.
|
349
|
+
`NULL' is returned if no record corresponds.
|
350
|
+
Because the region of the return value is allocated with the `malloc' call, it should be
|
351
|
+
released with the `free' call when it is no longer in use. */
|
352
|
+
char *tchdbget2(TCHDB *hdb, const char *kstr);
|
353
|
+
|
354
|
+
|
355
|
+
/* Retrieve a record in a hash database object and write the value into a buffer.
|
356
|
+
`hdb' specifies the hash database object.
|
357
|
+
`kbuf' specifies the pointer to the region of the key.
|
358
|
+
`ksiz' specifies the size of the region of the key.
|
359
|
+
`vbuf' specifies the pointer to the buffer into which the value of the corresponding record is
|
360
|
+
written.
|
361
|
+
`max' specifies the size of the buffer.
|
362
|
+
If successful, the return value is the size of the written data, else, it is -1. -1 is
|
363
|
+
returned if no record corresponds to the specified key.
|
364
|
+
Note that an additional zero code is not appended at the end of the region of the writing
|
365
|
+
buffer. */
|
366
|
+
int tchdbget3(TCHDB *hdb, const void *kbuf, int ksiz, void *vbuf, int max);
|
367
|
+
|
368
|
+
|
369
|
+
/* Get the size of the value of a record in a hash database object.
|
370
|
+
`hdb' specifies the hash database object.
|
371
|
+
`kbuf' specifies the pointer to the region of the key.
|
372
|
+
`ksiz' specifies the size of the region of the key.
|
373
|
+
If successful, the return value is the size of the value of the corresponding record, else,
|
374
|
+
it is -1. */
|
375
|
+
int tchdbvsiz(TCHDB *hdb, const void *kbuf, int ksiz);
|
376
|
+
|
377
|
+
|
378
|
+
/* Get the size of the value of a string record in a hash database object.
|
379
|
+
`hdb' specifies the hash database object.
|
380
|
+
`kstr' specifies the string of the key.
|
381
|
+
If successful, the return value is the size of the value of the corresponding record, else,
|
382
|
+
it is -1. */
|
383
|
+
int tchdbvsiz2(TCHDB *hdb, const char *kstr);
|
384
|
+
|
385
|
+
|
386
|
+
/* Initialize the iterator of a hash database object.
|
387
|
+
`hdb' specifies the hash database object.
|
388
|
+
If successful, the return value is true, else, it is false.
|
389
|
+
The iterator is used in order to access the key of every record stored in a database. */
|
390
|
+
bool tchdbiterinit(TCHDB *hdb);
|
391
|
+
|
392
|
+
|
393
|
+
/* Get the next key of the iterator of a hash database object.
|
394
|
+
`hdb' specifies the hash database object.
|
395
|
+
`sp' specifies the pointer to the variable into which the size of the region of the return
|
396
|
+
value is assigned.
|
397
|
+
If successful, the return value is the pointer to the region of the next key, else, it is
|
398
|
+
`NULL'. `NULL' is returned when no record is to be get out of the iterator.
|
399
|
+
Because an additional zero code is appended at the end of the region of the return value, the
|
400
|
+
return value can be treated as a character string. Because the region of the return value is
|
401
|
+
allocated with the `malloc' call, it should be released with the `free' call when it is no
|
402
|
+
longer in use. It is possible to access every record by iteration of calling this function.
|
403
|
+
It is allowed to update or remove records whose keys are fetched while the iteration.
|
404
|
+
However, it is not assured if updating the database is occurred while the iteration. Besides,
|
405
|
+
the order of this traversal access method is arbitrary, so it is not assured that the order of
|
406
|
+
storing matches the one of the traversal access. */
|
407
|
+
void *tchdbiternext(TCHDB *hdb, int *sp);
|
408
|
+
|
409
|
+
|
410
|
+
/* Get the next key string of the iterator of a hash database object.
|
411
|
+
`hdb' specifies the hash database object.
|
412
|
+
If successful, the return value is the string of the next key, else, it is `NULL'. `NULL' is
|
413
|
+
returned when no record is to be get out of the iterator.
|
414
|
+
Because the region of the return value is allocated with the `malloc' call, it should be
|
415
|
+
released with the `free' call when it is no longer in use. It is possible to access every
|
416
|
+
record by iteration of calling this function. However, it is not assured if updating the
|
417
|
+
database is occurred while the iteration. Besides, the order of this traversal access method
|
418
|
+
is arbitrary, so it is not assured that the order of storing matches the one of the traversal
|
419
|
+
access. */
|
420
|
+
char *tchdbiternext2(TCHDB *hdb);
|
421
|
+
|
422
|
+
|
423
|
+
/* Get the next extensible objects of the iterator of a hash database object.
|
424
|
+
`hdb' specifies the hash database object.
|
425
|
+
`kxstr' specifies the object into which the next key is wrote down.
|
426
|
+
`vxstr' specifies the object into which the next value is wrote down.
|
427
|
+
If successful, the return value is true, else, it is false. False is returned when no record
|
428
|
+
is to be get out of the iterator. */
|
429
|
+
bool tchdbiternext3(TCHDB *hdb, TCXSTR *kxstr, TCXSTR *vxstr);
|
430
|
+
|
431
|
+
|
432
|
+
/* Get forward matching keys in a hash database object.
|
433
|
+
`hdb' specifies the hash database object.
|
434
|
+
`pbuf' specifies the pointer to the region of the prefix.
|
435
|
+
`psiz' specifies the size of the region of the prefix.
|
436
|
+
`max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
|
437
|
+
specified.
|
438
|
+
The return value is a list object of the corresponding keys. This function does never fail.
|
439
|
+
It returns an empty list even if no key corresponds.
|
440
|
+
Because the object of the return value is created with the function `tclistnew', it should be
|
441
|
+
deleted with the function `tclistdel' when it is no longer in use. Note that this function
|
442
|
+
may be very slow because every key in the database is scanned. */
|
443
|
+
TCLIST *tchdbfwmkeys(TCHDB *hdb, const void *pbuf, int psiz, int max);
|
444
|
+
|
445
|
+
|
446
|
+
/* Get forward matching string keys in a hash database object.
|
447
|
+
`hdb' specifies the hash database object.
|
448
|
+
`pstr' specifies the string of the prefix.
|
449
|
+
`max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
|
450
|
+
specified.
|
451
|
+
The return value is a list object of the corresponding keys. This function does never fail.
|
452
|
+
It returns an empty list even if no key corresponds.
|
453
|
+
Because the object of the return value is created with the function `tclistnew', it should be
|
454
|
+
deleted with the function `tclistdel' when it is no longer in use. Note that this function
|
455
|
+
may be very slow because every key in the database is scanned. */
|
456
|
+
TCLIST *tchdbfwmkeys2(TCHDB *hdb, const char *pstr, int max);
|
457
|
+
|
458
|
+
|
459
|
+
/* Add an integer to a record in a hash database object.
|
460
|
+
`hdb' specifies the hash database object connected as a writer.
|
461
|
+
`kbuf' specifies the pointer to the region of the key.
|
462
|
+
`ksiz' specifies the size of the region of the key.
|
463
|
+
`num' specifies the additional value.
|
464
|
+
If successful, the return value is the summation value, else, it is `INT_MIN'.
|
465
|
+
If the corresponding record exists, the value is treated as an integer and is added to. If no
|
466
|
+
record corresponds, a new record of the additional value is stored. */
|
467
|
+
int tchdbaddint(TCHDB *hdb, const void *kbuf, int ksiz, int num);
|
468
|
+
|
469
|
+
|
470
|
+
/* Add a real number to a record in a hash database object.
|
471
|
+
`hdb' specifies the hash database object connected as a writer.
|
472
|
+
`kbuf' specifies the pointer to the region of the key.
|
473
|
+
`ksiz' specifies the size of the region of the key.
|
474
|
+
`num' specifies the additional value.
|
475
|
+
If successful, the return value is the summation value, else, it is Not-a-Number.
|
476
|
+
If the corresponding record exists, the value is treated as a real number and is added to. If
|
477
|
+
no record corresponds, a new record of the additional value is stored. */
|
478
|
+
double tchdbadddouble(TCHDB *hdb, const void *kbuf, int ksiz, double num);
|
479
|
+
|
480
|
+
|
481
|
+
/* Synchronize updated contents of a hash database object with the file and the device.
|
482
|
+
`hdb' specifies the hash database object connected as a writer.
|
483
|
+
If successful, the return value is true, else, it is false.
|
484
|
+
This function is useful when another process connects to the same database file. */
|
485
|
+
bool tchdbsync(TCHDB *hdb);
|
486
|
+
|
487
|
+
|
488
|
+
/* Optimize the file of a hash database object.
|
489
|
+
`hdb' specifies the hash database object connected as a writer.
|
490
|
+
`bnum' specifies the number of elements of the bucket array. If it is not more than 0, the
|
491
|
+
default value is specified. The default value is two times of the number of records.
|
492
|
+
`apow' specifies the size of record alignment by power of 2. If it is negative, the current
|
493
|
+
setting is not changed.
|
494
|
+
`fpow' specifies the maximum number of elements of the free block pool by power of 2. If it
|
495
|
+
is negative, the current setting is not changed.
|
496
|
+
`opts' specifies options by bitwise-or: `HDBTLARGE' specifies that the size of the database
|
497
|
+
can be larger than 2GB by using 64-bit bucket array, `HDBTDEFLATE' specifies that each record
|
498
|
+
is compressed with Deflate encoding, `HDBTBZIP' specifies that each record is compressed with
|
499
|
+
BZIP2 encoding, `HDBTTCBS' specifies that each record is compressed with TCBS encoding. If it
|
500
|
+
is `UINT8_MAX', the current setting is not changed.
|
501
|
+
If successful, the return value is true, else, it is false.
|
502
|
+
This function is useful to reduce the size of the database file with data fragmentation by
|
503
|
+
successive updating. */
|
504
|
+
bool tchdboptimize(TCHDB *hdb, int64_t bnum, int8_t apow, int8_t fpow, uint8_t opts);
|
505
|
+
|
506
|
+
|
507
|
+
/* Remove all records of a hash database object.
|
508
|
+
`hdb' specifies the hash database object connected as a writer.
|
509
|
+
If successful, the return value is true, else, it is false. */
|
510
|
+
bool tchdbvanish(TCHDB *hdb);
|
511
|
+
|
512
|
+
|
513
|
+
/* Copy the database file of a hash database object.
|
514
|
+
`hdb' specifies the hash database object.
|
515
|
+
`path' specifies the path of the destination file. If it begins with `@', the trailing
|
516
|
+
substring is executed as a command line.
|
517
|
+
If successful, the return value is true, else, it is false. False is returned if the executed
|
518
|
+
command returns non-zero code.
|
519
|
+
The database file is assured to be kept synchronized and not modified while the copying or
|
520
|
+
executing operation is in progress. So, this function is useful to create a backup file of
|
521
|
+
the database file. */
|
522
|
+
bool tchdbcopy(TCHDB *hdb, const char *path);
|
523
|
+
|
524
|
+
|
525
|
+
/* Begin the transaction of a hash database object.
|
526
|
+
`hdb' specifies the hash database object connected as a writer.
|
527
|
+
If successful, the return value is true, else, it is false.
|
528
|
+
The database is locked by the thread while the transaction so that only one transaction can be
|
529
|
+
activated with a database object at the same time. Thus, the serializable isolation level is
|
530
|
+
assumed if every database operation is performed in the transaction. All updated regions are
|
531
|
+
kept track of by write ahead logging while the transaction. If the database is closed during
|
532
|
+
transaction, the transaction is aborted implicitly. */
|
533
|
+
bool tchdbtranbegin(TCHDB *hdb);
|
534
|
+
|
535
|
+
|
536
|
+
/* Commit the transaction of a hash database object.
|
537
|
+
`hdb' specifies the hash database object connected as a writer.
|
538
|
+
If successful, the return value is true, else, it is false.
|
539
|
+
Update in the transaction is fixed when it is committed successfully. */
|
540
|
+
bool tchdbtrancommit(TCHDB *hdb);
|
541
|
+
|
542
|
+
|
543
|
+
/* Abort the transaction of a hash database object.
|
544
|
+
`hdb' specifies the hash database object connected as a writer.
|
545
|
+
If successful, the return value is true, else, it is false.
|
546
|
+
Update in the transaction is discarded when it is aborted. The state of the database is
|
547
|
+
rollbacked to before transaction. */
|
548
|
+
bool tchdbtranabort(TCHDB *hdb);
|
549
|
+
|
550
|
+
|
551
|
+
/* Get the file path of a hash database object.
|
552
|
+
`hdb' specifies the hash database object.
|
553
|
+
The return value is the path of the database file or `NULL' if the object does not connect to
|
554
|
+
any database file. */
|
555
|
+
const char *tchdbpath(TCHDB *hdb);
|
556
|
+
|
557
|
+
|
558
|
+
/* Get the number of records of a hash database object.
|
559
|
+
`hdb' specifies the hash database object.
|
560
|
+
The return value is the number of records or 0 if the object does not connect to any database
|
561
|
+
file. */
|
562
|
+
uint64_t tchdbrnum(TCHDB *hdb);
|
563
|
+
|
564
|
+
|
565
|
+
/* Get the size of the database file of a hash database object.
|
566
|
+
`hdb' specifies the hash database object.
|
567
|
+
The return value is the size of the database file or 0 if the object does not connect to any
|
568
|
+
database file. */
|
569
|
+
uint64_t tchdbfsiz(TCHDB *hdb);
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
/*************************************************************************************************
|
574
|
+
* features for experts
|
575
|
+
*************************************************************************************************/
|
576
|
+
|
577
|
+
|
578
|
+
/* Set the error code of a hash database object.
|
579
|
+
`hdb' specifies the hash database object.
|
580
|
+
`ecode' specifies the error code.
|
581
|
+
`file' specifies the file name of the code.
|
582
|
+
`line' specifies the line number of the code.
|
583
|
+
`func' specifies the function name of the code. */
|
584
|
+
void tchdbsetecode(TCHDB *hdb, int ecode, const char *filename, int line, const char *func);
|
585
|
+
|
586
|
+
|
587
|
+
/* Set the type of a hash database object.
|
588
|
+
`hdb' specifies the hash database object.
|
589
|
+
`type' specifies the database type. */
|
590
|
+
void tchdbsettype(TCHDB *hdb, uint8_t type);
|
591
|
+
|
592
|
+
|
593
|
+
/* Set the file descriptor for debugging output.
|
594
|
+
`hdb' specifies the hash database object.
|
595
|
+
`fd' specifies the file descriptor for debugging output. */
|
596
|
+
void tchdbsetdbgfd(TCHDB *hdb, int fd);
|
597
|
+
|
598
|
+
|
599
|
+
/* Get the file descriptor for debugging output.
|
600
|
+
`hdb' specifies the hash database object.
|
601
|
+
The return value is the file descriptor for debugging output. */
|
602
|
+
int tchdbdbgfd(TCHDB *hdb);
|
603
|
+
|
604
|
+
|
605
|
+
/* Check whether mutual exclusion control is set to a hash database object.
|
606
|
+
`hdb' specifies the hash database object.
|
607
|
+
If mutual exclusion control is set, it is true, else it is false. */
|
608
|
+
bool tchdbhasmutex(TCHDB *hdb);
|
609
|
+
|
610
|
+
|
611
|
+
/* Synchronize updating contents on memory of a hash database object.
|
612
|
+
`hdb' specifies the hash database object connected as a writer.
|
613
|
+
`phys' specifies whether to synchronize physically.
|
614
|
+
If successful, the return value is true, else, it is false. */
|
615
|
+
bool tchdbmemsync(TCHDB *hdb, bool phys);
|
616
|
+
|
617
|
+
|
618
|
+
/* Get the number of elements of the bucket array of a hash database object.
|
619
|
+
`hdb' specifies the hash database object.
|
620
|
+
The return value is the number of elements of the bucket array or 0 if the object does not
|
621
|
+
connect to any database file. */
|
622
|
+
uint64_t tchdbbnum(TCHDB *hdb);
|
623
|
+
|
624
|
+
|
625
|
+
/* Get the record alignment of a hash database object.
|
626
|
+
`hdb' specifies the hash database object.
|
627
|
+
The return value is the record alignment or 0 if the object does not connect to any database
|
628
|
+
file. */
|
629
|
+
uint32_t tchdbalign(TCHDB *hdb);
|
630
|
+
|
631
|
+
|
632
|
+
/* Get the maximum number of the free block pool of a a hash database object.
|
633
|
+
`hdb' specifies the hash database object.
|
634
|
+
The return value is the maximum number of the free block pool or 0 if the object does not
|
635
|
+
connect to any database file. */
|
636
|
+
uint32_t tchdbfbpmax(TCHDB *hdb);
|
637
|
+
|
638
|
+
|
639
|
+
/* Get the size of the extra mapped memory of a hash database object.
|
640
|
+
`hdb' specifies the hash database object.
|
641
|
+
The return value is the size of the extra mapped memory or 0 if the object does not connect to
|
642
|
+
any database file. */
|
643
|
+
uint64_t tchdbxmsiz(TCHDB *hdb);
|
644
|
+
|
645
|
+
|
646
|
+
/* Get the inode number of the database file of a hash database object.
|
647
|
+
`hdb' specifies the hash database object.
|
648
|
+
The return value is the inode number of the database file or 0 if the object does not connect
|
649
|
+
to any database file. */
|
650
|
+
uint64_t tchdbinode(TCHDB *hdb);
|
651
|
+
|
652
|
+
|
653
|
+
/* Get the modification time of the database file of a hash database object.
|
654
|
+
`hdb' specifies the hash database object.
|
655
|
+
The return value is the inode number of the database file or 0 if the object does not connect
|
656
|
+
to any database file. */
|
657
|
+
time_t tchdbmtime(TCHDB *hdb);
|
658
|
+
|
659
|
+
|
660
|
+
/* Get the connection mode of a hash database object.
|
661
|
+
`hdb' specifies the hash database object.
|
662
|
+
The return value is the connection mode. */
|
663
|
+
int tchdbomode(TCHDB *hdb);
|
664
|
+
|
665
|
+
|
666
|
+
/* Get the database type of a hash database object.
|
667
|
+
`hdb' specifies the hash database object.
|
668
|
+
The return value is the database type. */
|
669
|
+
uint8_t tchdbtype(TCHDB *hdb);
|
670
|
+
|
671
|
+
|
672
|
+
/* Get the additional flags of a hash database object.
|
673
|
+
`hdb' specifies the hash database object.
|
674
|
+
The return value is the additional flags. */
|
675
|
+
uint8_t tchdbflags(TCHDB *hdb);
|
676
|
+
|
677
|
+
|
678
|
+
/* Get the options of a hash database object.
|
679
|
+
`hdb' specifies the hash database object.
|
680
|
+
The return value is the options. */
|
681
|
+
uint8_t tchdbopts(TCHDB *hdb);
|
682
|
+
|
683
|
+
|
684
|
+
/* Get the pointer to the opaque field of a hash database object.
|
685
|
+
`hdb' specifies the hash database object.
|
686
|
+
The return value is the pointer to the opaque field whose size is 128 bytes. */
|
687
|
+
char *tchdbopaque(TCHDB *hdb);
|
688
|
+
|
689
|
+
|
690
|
+
/* Get the number of used elements of the bucket array of a hash database object.
|
691
|
+
`hdb' specifies the hash database object.
|
692
|
+
The return value is the number of used elements of the bucket array or 0 if the object does
|
693
|
+
not connect to any database file. */
|
694
|
+
uint64_t tchdbbnumused(TCHDB *hdb);
|
695
|
+
|
696
|
+
|
697
|
+
/* Set the custom codec functions of a hash database object.
|
698
|
+
`hdb' specifies the hash database object.
|
699
|
+
`enc' specifies the pointer to the custom encoding function. It receives four parameters.
|
700
|
+
The first parameter is the pointer to the region. The second parameter is the size of the
|
701
|
+
region. The third parameter is the pointer to the variable into which the size of the region
|
702
|
+
of the return value is assigned. The fourth parameter is the pointer to the optional opaque
|
703
|
+
object. It returns the pointer to the result object allocated with `malloc' call if
|
704
|
+
successful, else, it returns `NULL'.
|
705
|
+
`encop' specifies an arbitrary pointer to be given as a parameter of the encoding function.
|
706
|
+
If it is not needed, `NULL' can be specified.
|
707
|
+
`dec' specifies the pointer to the custom decoding function.
|
708
|
+
`decop' specifies an arbitrary pointer to be given as a parameter of the decoding function.
|
709
|
+
If it is not needed, `NULL' can be specified.
|
710
|
+
If successful, the return value is true, else, it is false.
|
711
|
+
Note that the custom codec functions should be set before the database is opened and should be
|
712
|
+
set every time the database is being opened. */
|
713
|
+
bool tchdbsetcodecfunc(TCHDB *hdb, TCCODEC enc, void *encop, TCCODEC dec, void *decop);
|
714
|
+
|
715
|
+
|
716
|
+
/* Get the custom codec functions of a hash database object.
|
717
|
+
`hdb' specifies the hash database object.
|
718
|
+
`ep' specifies the pointer to a variable into which the pointer to the custom encoding
|
719
|
+
function is assigned
|
720
|
+
`eop' specifies the pointer to a variable into which the arbitrary pointer to be given to the
|
721
|
+
encoding function is assigned.
|
722
|
+
`dp' specifies the pointer to a variable into which the pointer to the custom decoding
|
723
|
+
function is assigned
|
724
|
+
`dop' specifies the pointer to a variable into which the arbitrary pointer to be given to the
|
725
|
+
decoding function is assigned. */
|
726
|
+
void tchdbcodecfunc(TCHDB *hdb, TCCODEC *ep, void **eop, TCCODEC *dp, void **dop);
|
727
|
+
|
728
|
+
|
729
|
+
/* Get the unit step number of auto defragmentation of a hash database object.
|
730
|
+
`hdb' specifies the hash database object.
|
731
|
+
The return value is the unit step number of auto defragmentation. */
|
732
|
+
uint32_t tchdbdfunit(TCHDB *hdb);
|
733
|
+
|
734
|
+
|
735
|
+
/* Perform dynamic defragmentation of a hash database object.
|
736
|
+
`hdb' specifies the hash database object connected as a writer.
|
737
|
+
`step' specifie the number of steps. If it is not more than 0, the whole file is defragmented
|
738
|
+
gradually without keeping a continuous lock.
|
739
|
+
If successful, the return value is true, else, it is false. */
|
740
|
+
bool tchdbdefrag(TCHDB *hdb, int64_t step);
|
741
|
+
|
742
|
+
|
743
|
+
/* Clear the cache of a hash tree database object.
|
744
|
+
`hdb' specifies the hash tree database object.
|
745
|
+
If successful, the return value is true, else, it is false. */
|
746
|
+
bool tchdbcacheclear(TCHDB *hdb);
|
747
|
+
|
748
|
+
|
749
|
+
/* Store a record into a hash database object with a duplication handler.
|
750
|
+
`hdb' specifies the hash database object connected as a writer.
|
751
|
+
`kbuf' specifies the pointer to the region of the key.
|
752
|
+
`ksiz' specifies the size of the region of the key.
|
753
|
+
`vbuf' specifies the pointer to the region of the value. `NULL' means that record addition is
|
754
|
+
ommited if there is no corresponding record.
|
755
|
+
`vsiz' specifies the size of the region of the value.
|
756
|
+
`proc' specifies the pointer to the callback function to process duplication. It receives
|
757
|
+
four parameters. The first parameter is the pointer to the region of the value. The second
|
758
|
+
parameter is the size of the region of the value. The third parameter is the pointer to the
|
759
|
+
variable into which the size of the region of the return value is assigned. The fourth
|
760
|
+
parameter is the pointer to the optional opaque object. It returns the pointer to the result
|
761
|
+
object allocated with `malloc'. It is released by the caller. If it is `NULL', the record is
|
762
|
+
not modified. If it is `(void *)-1', the record is removed.
|
763
|
+
`op' specifies an arbitrary pointer to be given as a parameter of the callback function. If
|
764
|
+
it is not needed, `NULL' can be specified.
|
765
|
+
If successful, the return value is true, else, it is false.
|
766
|
+
Note that the callback function can not perform any database operation because the function
|
767
|
+
is called in the critical section guarded by the same locks of database operations. */
|
768
|
+
bool tchdbputproc(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz,
|
769
|
+
TCPDPROC proc, void *op);
|
770
|
+
|
771
|
+
|
772
|
+
/* Retrieve the next record of a record in a hash database object.
|
773
|
+
`hdb' specifies the hash database object.
|
774
|
+
`kbuf' specifies the pointer to the region of the key. If it is `NULL', the first record is
|
775
|
+
retrieved.
|
776
|
+
`ksiz' specifies the size of the region of the key.
|
777
|
+
`sp' specifies the pointer to the variable into which the size of the region of the return
|
778
|
+
value is assigned.
|
779
|
+
If successful, the return value is the pointer to the region of the key of the next record.
|
780
|
+
`NULL' is returned if no record corresponds.
|
781
|
+
Because an additional zero code is appended at the end of the region of the return value,
|
782
|
+
the return value can be treated as a character string. Because the region of the return
|
783
|
+
value is allocated with the `malloc' call, it should be released with the `free' call when
|
784
|
+
it is no longer in use. */
|
785
|
+
void *tchdbgetnext(TCHDB *hdb, const void *kbuf, int ksiz, int *sp);
|
786
|
+
|
787
|
+
|
788
|
+
/* Retrieve the next string record in a hash database object.
|
789
|
+
`hdb' specifies the hash database object.
|
790
|
+
`kstr' specifies the string of the key. If it is `NULL', the first record is retrieved.
|
791
|
+
If successful, the return value is the string of the key of the next record. `NULL' is
|
792
|
+
returned if no record corresponds.
|
793
|
+
Because the region of the return value is allocated with the `malloc' call, it should be
|
794
|
+
released with the `free' call when it is no longer in use. */
|
795
|
+
char *tchdbgetnext2(TCHDB *hdb, const char *kstr);
|
796
|
+
|
797
|
+
|
798
|
+
/* Retrieve the key and the value of the next record of a record in a hash database object.
|
799
|
+
`hdb' specifies the hash database object.
|
800
|
+
`kbuf' specifies the pointer to the region of the key.
|
801
|
+
`ksiz' specifies the size of the region of the key.
|
802
|
+
`sp' specifies the pointer to the variable into which the size of the region of the return
|
803
|
+
value is assigned.
|
804
|
+
`vbp' specifies the pointer to the variable into which the pointer to the value is assigned.
|
805
|
+
`vsp' specifies the pointer to the variable into which the size of the value is assigned.
|
806
|
+
If successful, the return value is the pointer to the region of the key of the next
|
807
|
+
record.
|
808
|
+
Because the region of the return value is allocated with the `malloc' call, it should be
|
809
|
+
released with the `free' call when it is no longer in use. The retion pointed to by `vbp'
|
810
|
+
should not be released. */
|
811
|
+
char *tchdbgetnext3(TCHDB *hdb, const char *kbuf, int ksiz, int *sp, const char **vbp, int *vsp);
|
812
|
+
|
813
|
+
|
814
|
+
/* Move the iterator to the record corresponding a key of a hash database object.
|
815
|
+
`hdb' specifies the hash database object.
|
816
|
+
`kbuf' specifies the pointer to the region of the key.
|
817
|
+
`ksiz' specifies the size of the region of the key.
|
818
|
+
If successful, the return value is true, else, it is false. False is returned if there is
|
819
|
+
no record corresponding the condition. */
|
820
|
+
bool tchdbiterinit2(TCHDB *hdb, const void *kbuf, int ksiz);
|
821
|
+
|
822
|
+
|
823
|
+
/* Move the iterator to the record corresponding a key string of a hash database object.
|
824
|
+
`hdb' specifies the hash database object.
|
825
|
+
`kstr' specifies the string of the key.
|
826
|
+
If successful, the return value is true, else, it is false. False is returned if there is
|
827
|
+
no record corresponding the condition. */
|
828
|
+
bool tchdbiterinit3(TCHDB *hdb, const char *kstr);
|
829
|
+
|
830
|
+
|
831
|
+
/* Process each record atomically of a hash database object.
|
832
|
+
`hdb' specifies the hash database object.
|
833
|
+
`iter' specifies the pointer to the iterator function called for each record. It receives
|
834
|
+
five parameters. The first parameter is the pointer to the region of the key. The second
|
835
|
+
parameter is the size of the region of the key. The third parameter is the pointer to the
|
836
|
+
region of the value. The fourth parameter is the size of the region of the value. The fifth
|
837
|
+
parameter is the pointer to the optional opaque object. It returns true to continue iteration
|
838
|
+
or false to stop iteration.
|
839
|
+
`op' specifies an arbitrary pointer to be given as a parameter of the iterator function. If
|
840
|
+
it is not needed, `NULL' can be specified.
|
841
|
+
If successful, the return value is true, else, it is false.
|
842
|
+
Note that the callback function can not perform any database operation because the function
|
843
|
+
is called in the critical section guarded by the same locks of database operations. */
|
844
|
+
bool tchdbforeach(TCHDB *hdb, TCITER iter, void *op);
|
845
|
+
|
846
|
+
|
847
|
+
/* Void the transaction of a hash database object.
|
848
|
+
`hdb' specifies the hash database object connected as a writer.
|
849
|
+
If successful, the return value is true, else, it is false.
|
850
|
+
This function should be called only when no update in the transaction. */
|
851
|
+
bool tchdbtranvoid(TCHDB *hdb);
|
852
|
+
|
853
|
+
#endif /* duplication check */
|
854
|
+
|
855
|
+
|
856
|
+
/* END OF FILE */
|