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/tc_myconf.h
ADDED
@@ -0,0 +1,543 @@
|
|
1
|
+
/*************************************************************************************************
|
2
|
+
* System-dependent configurations 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 _TC_MYCONF_H // duplication check
|
18
|
+
#define _TC_MYCONF_H
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
/*************************************************************************************************
|
23
|
+
* system discrimination
|
24
|
+
*************************************************************************************************/
|
25
|
+
|
26
|
+
|
27
|
+
#if defined(__linux__)
|
28
|
+
|
29
|
+
#define _SYS_LINUX_
|
30
|
+
#define TCSYSNAME "Linux"
|
31
|
+
|
32
|
+
#elif defined(__FreeBSD__)
|
33
|
+
|
34
|
+
#define _SYS_FREEBSD_
|
35
|
+
#define TCSYSNAME "FreeBSD"
|
36
|
+
|
37
|
+
#elif defined(__NetBSD__)
|
38
|
+
|
39
|
+
#define _SYS_NETBSD_
|
40
|
+
#define TCSYSNAME "NetBSD"
|
41
|
+
|
42
|
+
#elif defined(__OpenBSD__)
|
43
|
+
|
44
|
+
#define _SYS_OPENBSD_
|
45
|
+
#define TCSYSNAME "OpenBSD"
|
46
|
+
|
47
|
+
#elif defined(__sun__) || defined(__sun)
|
48
|
+
|
49
|
+
#define _SYS_SUNOS_
|
50
|
+
#define TCSYSNAME "SunOS"
|
51
|
+
|
52
|
+
#elif defined(__hpux)
|
53
|
+
|
54
|
+
#define _SYS_HPUX_
|
55
|
+
#define TCSYSNAME "HP-UX"
|
56
|
+
|
57
|
+
#elif defined(__osf)
|
58
|
+
|
59
|
+
#define _SYS_TRU64_
|
60
|
+
#define TCSYSNAME "Tru64"
|
61
|
+
|
62
|
+
#elif defined(_AIX)
|
63
|
+
|
64
|
+
#define _SYS_AIX_
|
65
|
+
#define TCSYSNAME "AIX"
|
66
|
+
|
67
|
+
#elif defined(__APPLE__) && defined(__MACH__)
|
68
|
+
|
69
|
+
#define _SYS_MACOSX_
|
70
|
+
#define TCSYSNAME "Mac OS X"
|
71
|
+
|
72
|
+
#elif defined(_MSC_VER)
|
73
|
+
|
74
|
+
#define _SYS_MSVC_
|
75
|
+
#define TCSYSNAME "Windows (VC++)"
|
76
|
+
|
77
|
+
#elif defined(_WIN32)
|
78
|
+
|
79
|
+
#define _SYS_MINGW_
|
80
|
+
#define TCSYSNAME "Windows (MinGW)"
|
81
|
+
|
82
|
+
#elif defined(__CYGWIN__)
|
83
|
+
|
84
|
+
#define _SYS_CYGWIN_
|
85
|
+
#define TCSYSNAME "Windows (Cygwin)"
|
86
|
+
|
87
|
+
#else
|
88
|
+
|
89
|
+
#define _SYS_GENERIC_
|
90
|
+
#define TCSYSNAME "Generic"
|
91
|
+
|
92
|
+
#endif
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
/*************************************************************************************************
|
97
|
+
* common settings
|
98
|
+
*************************************************************************************************/
|
99
|
+
|
100
|
+
|
101
|
+
#if defined(NDEBUG)
|
102
|
+
#define TCDODEBUG(TC_expr) \
|
103
|
+
do { \
|
104
|
+
} while(false)
|
105
|
+
#else
|
106
|
+
#define TCDODEBUG(TC_expr) \
|
107
|
+
do { \
|
108
|
+
TC_expr; \
|
109
|
+
} while(false)
|
110
|
+
#endif
|
111
|
+
|
112
|
+
#define TCSWAB16(TC_num) \
|
113
|
+
( \
|
114
|
+
((TC_num & 0x00ffU) << 8) | \
|
115
|
+
((TC_num & 0xff00U) >> 8) \
|
116
|
+
)
|
117
|
+
|
118
|
+
#define TCSWAB32(TC_num) \
|
119
|
+
( \
|
120
|
+
((TC_num & 0x000000ffUL) << 24) | \
|
121
|
+
((TC_num & 0x0000ff00UL) << 8) | \
|
122
|
+
((TC_num & 0x00ff0000UL) >> 8) | \
|
123
|
+
((TC_num & 0xff000000UL) >> 24) \
|
124
|
+
)
|
125
|
+
|
126
|
+
#define TCSWAB64(TC_num) \
|
127
|
+
( \
|
128
|
+
((TC_num & 0x00000000000000ffULL) << 56) | \
|
129
|
+
((TC_num & 0x000000000000ff00ULL) << 40) | \
|
130
|
+
((TC_num & 0x0000000000ff0000ULL) << 24) | \
|
131
|
+
((TC_num & 0x00000000ff000000ULL) << 8) | \
|
132
|
+
((TC_num & 0x000000ff00000000ULL) >> 8) | \
|
133
|
+
((TC_num & 0x0000ff0000000000ULL) >> 24) | \
|
134
|
+
((TC_num & 0x00ff000000000000ULL) >> 40) | \
|
135
|
+
((TC_num & 0xff00000000000000ULL) >> 56) \
|
136
|
+
)
|
137
|
+
|
138
|
+
#if defined(_MYBIGEND) || defined(_MYSWAB)
|
139
|
+
#define TCBIGEND 1
|
140
|
+
#define TCHTOIS(TC_num) TCSWAB16(TC_num)
|
141
|
+
#define TCHTOIL(TC_num) TCSWAB32(TC_num)
|
142
|
+
#define TCHTOILL(TC_num) TCSWAB64(TC_num)
|
143
|
+
#define TCITOHS(TC_num) TCSWAB16(TC_num)
|
144
|
+
#define TCITOHL(TC_num) TCSWAB32(TC_num)
|
145
|
+
#define TCITOHLL(TC_num) TCSWAB64(TC_num)
|
146
|
+
#else
|
147
|
+
#define TCBIGEND 0
|
148
|
+
#define TCHTOIS(TC_num) (TC_num)
|
149
|
+
#define TCHTOIL(TC_num) (TC_num)
|
150
|
+
#define TCHTOILL(TC_num) (TC_num)
|
151
|
+
#define TCITOHS(TC_num) (TC_num)
|
152
|
+
#define TCITOHL(TC_num) (TC_num)
|
153
|
+
#define TCITOHLL(TC_num) (TC_num)
|
154
|
+
#endif
|
155
|
+
|
156
|
+
#if defined(_MYNOUBC)
|
157
|
+
#define TCUBCACHE 0
|
158
|
+
#elif defined(_SYS_LINUX_) || defined(_SYS_FREEBSD_) || defined(_SYS_NETBSD_) || \
|
159
|
+
defined(_SYS_MACOSX_) || defined(_SYS_SUNOS_)
|
160
|
+
#define TCUBCACHE 1
|
161
|
+
#else
|
162
|
+
#define TCUBCACHE 0
|
163
|
+
#endif
|
164
|
+
|
165
|
+
#if defined(_MYNOZLIB)
|
166
|
+
#define TCUSEZLIB 0
|
167
|
+
#else
|
168
|
+
#define TCUSEZLIB 1
|
169
|
+
#endif
|
170
|
+
|
171
|
+
#if defined(_MYNOBZIP)
|
172
|
+
#define TCUSEBZIP 0
|
173
|
+
#else
|
174
|
+
#define TCUSEBZIP 1
|
175
|
+
#endif
|
176
|
+
|
177
|
+
#if defined(_MYEXLZMA)
|
178
|
+
#define TCUSEEXLZMA 1
|
179
|
+
#else
|
180
|
+
#define TCUSEEXLZMA 0
|
181
|
+
#endif
|
182
|
+
|
183
|
+
#if defined(_MYEXLZO)
|
184
|
+
#define TCUSEEXLZO 1
|
185
|
+
#else
|
186
|
+
#define TCUSEEXLZO 0
|
187
|
+
#endif
|
188
|
+
|
189
|
+
#if defined(_MYNOPTHREAD)
|
190
|
+
#define TCUSEPTHREAD 0
|
191
|
+
#else
|
192
|
+
#define TCUSEPTHREAD 1
|
193
|
+
#endif
|
194
|
+
|
195
|
+
#if defined(_MYMICROYIELD)
|
196
|
+
#define TCMICROYIELD 1
|
197
|
+
#else
|
198
|
+
#define TCMICROYIELD 0
|
199
|
+
#endif
|
200
|
+
|
201
|
+
#define MYMALLOC malloc
|
202
|
+
#define MYCALLOC calloc
|
203
|
+
#define MYREALLOC realloc
|
204
|
+
#define MYFREE free
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
/*************************************************************************************************
|
209
|
+
* general headers
|
210
|
+
*************************************************************************************************/
|
211
|
+
|
212
|
+
|
213
|
+
#include <assert.h>
|
214
|
+
#include <ctype.h>
|
215
|
+
#include <errno.h>
|
216
|
+
#include <float.h>
|
217
|
+
#include <limits.h>
|
218
|
+
#include <locale.h>
|
219
|
+
#include <math.h>
|
220
|
+
#include <setjmp.h>
|
221
|
+
#include <stdarg.h>
|
222
|
+
#include <stddef.h>
|
223
|
+
#include <stdio.h>
|
224
|
+
#include <stdlib.h>
|
225
|
+
#include <signal.h>
|
226
|
+
#include <string.h>
|
227
|
+
#include <time.h>
|
228
|
+
|
229
|
+
#include <inttypes.h>
|
230
|
+
#include <stdbool.h>
|
231
|
+
#include <stdint.h>
|
232
|
+
|
233
|
+
#include <unistd.h>
|
234
|
+
#include <sys/param.h>
|
235
|
+
#include <sys/types.h>
|
236
|
+
#include <sys/stat.h>
|
237
|
+
#include <sys/mman.h>
|
238
|
+
#include <sys/time.h>
|
239
|
+
#include <sys/times.h>
|
240
|
+
#include <sys/wait.h>
|
241
|
+
#include <sys/resource.h>
|
242
|
+
#include <fcntl.h>
|
243
|
+
#include <dirent.h>
|
244
|
+
#include </usr/include/regex.h>
|
245
|
+
#include <glob.h>
|
246
|
+
|
247
|
+
#include <pthread.h>
|
248
|
+
|
249
|
+
|
250
|
+
/*************************************************************************************************
|
251
|
+
* miscellaneous hacks
|
252
|
+
*************************************************************************************************/
|
253
|
+
|
254
|
+
|
255
|
+
#if defined(__GNUC__)
|
256
|
+
#define _alignof(TC_a) ((size_t)__alignof__(TC_a))
|
257
|
+
#else
|
258
|
+
#define _alignof(TC_a) sizeof(TC_a)
|
259
|
+
#endif
|
260
|
+
#define _issigned(TC_a) ((TC_a)-1 < 1 ? true : false)
|
261
|
+
#define _maxof(TC_a) \
|
262
|
+
((TC_a)(sizeof(TC_a) == sizeof(int64_t) ? _issigned(TC_a) ? INT64_MAX : UINT64_MAX : \
|
263
|
+
sizeof(TC_a) == sizeof(int32_t) ? _issigned(TC_a) ? INT32_MAX : UINT32_MAX : \
|
264
|
+
sizeof(TC_a) == sizeof(int16_t) ? _issigned(TC_a) ? INT16_MAX : UINT16_MAX : \
|
265
|
+
_issigned(TC_a) ? INT8_MAX : UINT8_MAX))
|
266
|
+
|
267
|
+
#if defined(_SYS_FREEBSD_) || defined(_SYS_NETBSD_) || defined(_SYS_OPENBSD_)
|
268
|
+
#define nan(TC_a) strtod("nan", NULL)
|
269
|
+
#define nanl(TC_a) ((long double)strtod("nan", NULL))
|
270
|
+
#endif
|
271
|
+
|
272
|
+
#if ! defined(PATH_MAX)
|
273
|
+
#if defined(MAXPATHLEN)
|
274
|
+
#define PATH_MAX MAXPATHLEN
|
275
|
+
#else
|
276
|
+
#define PATH_MAX 4096
|
277
|
+
#endif
|
278
|
+
#endif
|
279
|
+
#if ! defined(NAME_MAX)
|
280
|
+
#define NAME_MAX 255
|
281
|
+
#endif
|
282
|
+
|
283
|
+
extern int _tc_dummy_cnt;
|
284
|
+
|
285
|
+
int _tc_dummyfunc(void);
|
286
|
+
|
287
|
+
int _tc_dummyfuncv(int a, ...);
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
/*************************************************************************************************
|
292
|
+
* notation of filesystems
|
293
|
+
*************************************************************************************************/
|
294
|
+
|
295
|
+
|
296
|
+
#define MYPATHCHR '/'
|
297
|
+
#define MYPATHSTR "/"
|
298
|
+
#define MYEXTCHR '.'
|
299
|
+
#define MYEXTSTR "."
|
300
|
+
#define MYCDIRSTR "."
|
301
|
+
#define MYPDIRSTR ".."
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
/*************************************************************************************************
|
306
|
+
* for ZLIB
|
307
|
+
*************************************************************************************************/
|
308
|
+
|
309
|
+
|
310
|
+
enum {
|
311
|
+
_TCZMZLIB,
|
312
|
+
_TCZMRAW,
|
313
|
+
_TCZMGZIP
|
314
|
+
};
|
315
|
+
|
316
|
+
|
317
|
+
extern char *(*_tc_deflate)(const char *, int, int *, int);
|
318
|
+
|
319
|
+
extern char *(*_tc_inflate)(const char *, int, int *, int);
|
320
|
+
|
321
|
+
extern unsigned int (*_tc_getcrc)(const char *, int);
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
/*************************************************************************************************
|
326
|
+
* for BZIP2
|
327
|
+
*************************************************************************************************/
|
328
|
+
|
329
|
+
|
330
|
+
extern char *(*_tc_bzcompress)(const char *, int, int *);
|
331
|
+
|
332
|
+
extern char *(*_tc_bzdecompress)(const char *, int, int *);
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
/*************************************************************************************************
|
337
|
+
* for test of custom codec functions
|
338
|
+
*************************************************************************************************/
|
339
|
+
|
340
|
+
|
341
|
+
void *_tc_recencode(const void *ptr, int size, int *sp, void *op);
|
342
|
+
|
343
|
+
void *_tc_recdecode(const void *ptr, int size, int *sp, void *op);
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
/*************************************************************************************************
|
348
|
+
* for POSIX thread disability
|
349
|
+
*************************************************************************************************/
|
350
|
+
|
351
|
+
|
352
|
+
#if ! TCUSEPTHREAD
|
353
|
+
|
354
|
+
#define pthread_t intptr_t
|
355
|
+
|
356
|
+
#define pthread_once_t intptr_t
|
357
|
+
#undef PTHREAD_ONCE_INIT
|
358
|
+
#define PTHREAD_ONCE_INIT 0
|
359
|
+
#define pthread_once(TC_a, TC_b) _tc_dummyfuncv((intptr_t)(TC_a), (TC_b))
|
360
|
+
|
361
|
+
#define pthread_mutexattr_t intptr_t
|
362
|
+
#undef PTHREAD_MUTEX_RECURSIVE
|
363
|
+
#define PTHREAD_MUTEX_RECURSIVE 0
|
364
|
+
#define pthread_mutexattr_init(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
365
|
+
#define pthread_mutexattr_destroy(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
366
|
+
#define pthread_mutexattr_settype(TC_a, TC_b) _tc_dummyfuncv((intptr_t)(TC_a), (TC_b))
|
367
|
+
|
368
|
+
#define pthread_mutex_t intptr_t
|
369
|
+
#undef PTHREAD_MUTEX_INITIALIZER
|
370
|
+
#define PTHREAD_MUTEX_INITIALIZER 0
|
371
|
+
#define pthread_mutex_init(TC_a, TC_b) _tc_dummyfuncv((intptr_t)(TC_a), (TC_b))
|
372
|
+
#define pthread_mutex_destroy(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
373
|
+
#define pthread_mutex_lock(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
374
|
+
#define pthread_mutex_unlock(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
375
|
+
|
376
|
+
#define pthread_rwlock_t intptr_t
|
377
|
+
#undef PTHREAD_RWLOCK_INITIALIZER
|
378
|
+
#define PTHREAD_RWLOCK_INITIALIZER 0
|
379
|
+
#define pthread_rwlock_init(TC_a, TC_b) _tc_dummyfuncv((intptr_t)(TC_a), (TC_b))
|
380
|
+
#define pthread_rwlock_destroy(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
381
|
+
#define pthread_rwlock_rdlock(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
382
|
+
#define pthread_rwlock_wrlock(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
383
|
+
#define pthread_rwlock_unlock(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
384
|
+
|
385
|
+
#define pthread_key_t intptr_t
|
386
|
+
#define pthread_key_create(TC_a, TC_b) _tc_dummyfuncv((intptr_t)(TC_a), (TC_b))
|
387
|
+
#define pthread_key_delete(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
388
|
+
#define pthread_setspecific(TC_a, TC_b) _tc_dummyfuncv((intptr_t)(TC_a))
|
389
|
+
#define pthread_getspecific(TC_a) _tc_dummyfuncv((intptr_t)(TC_a))
|
390
|
+
|
391
|
+
#define pthread_create(TC_th, TC_attr, TC_func, TC_arg) \
|
392
|
+
(*(TC_th) = 0, (TC_func)(TC_arg), 0)
|
393
|
+
#define pthread_join(TC_th, TC_rv) (*(TC_rv) = NULL, 0)
|
394
|
+
#define pthread_detach(TC_th) 0
|
395
|
+
#define sched_yield() _tc_dummyfunc()
|
396
|
+
|
397
|
+
#endif
|
398
|
+
|
399
|
+
#if TCUSEPTHREAD && TCMICROYIELD
|
400
|
+
#define TCTESTYIELD() \
|
401
|
+
do { \
|
402
|
+
if(((++_tc_dummy_cnt) & (0x20 - 1)) == 0){ \
|
403
|
+
sched_yield(); \
|
404
|
+
if(_tc_dummy_cnt > 0x1000) _tc_dummy_cnt = (uint32_t)time(NULL) % 0x1000; \
|
405
|
+
} \
|
406
|
+
} while(false)
|
407
|
+
#undef assert
|
408
|
+
#define assert(TC_expr) \
|
409
|
+
do { \
|
410
|
+
if(!(TC_expr)){ \
|
411
|
+
fprintf(stderr, "assertion failed: %s\n", #TC_expr); \
|
412
|
+
abort(); \
|
413
|
+
} \
|
414
|
+
TCTESTYIELD(); \
|
415
|
+
} while(false)
|
416
|
+
#define if(TC_cond) \
|
417
|
+
if((((++_tc_dummy_cnt) & (0x100 - 1)) != 0 || (sched_yield() * 0) == 0) && (TC_cond))
|
418
|
+
#define while(TC_cond) \
|
419
|
+
while((((++_tc_dummy_cnt) & (0x100 - 1)) != 0 || (sched_yield() * 0) == 0) && (TC_cond))
|
420
|
+
#else
|
421
|
+
#define TCTESTYIELD() \
|
422
|
+
do { \
|
423
|
+
} while(false)
|
424
|
+
#endif
|
425
|
+
|
426
|
+
#if !defined(_POSIX_PRIORITY_SCHEDULING) && TCUSEPTHREAD
|
427
|
+
#define sched_yield() usleep(1000 * 20)
|
428
|
+
#endif
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
/*************************************************************************************************
|
433
|
+
* utilities for implementation
|
434
|
+
*************************************************************************************************/
|
435
|
+
|
436
|
+
|
437
|
+
#define TCNUMBUFSIZ 32 // size of a buffer for a number
|
438
|
+
|
439
|
+
/* set a buffer for a variable length number */
|
440
|
+
#define TCSETVNUMBUF(TC_len, TC_buf, TC_num) \
|
441
|
+
do { \
|
442
|
+
int _TC_num = (TC_num); \
|
443
|
+
if(_TC_num == 0){ \
|
444
|
+
((signed char *)(TC_buf))[0] = 0; \
|
445
|
+
(TC_len) = 1; \
|
446
|
+
} else { \
|
447
|
+
(TC_len) = 0; \
|
448
|
+
while(_TC_num > 0){ \
|
449
|
+
int _TC_rem = _TC_num & 0x7f; \
|
450
|
+
_TC_num >>= 7; \
|
451
|
+
if(_TC_num > 0){ \
|
452
|
+
((signed char *)(TC_buf))[(TC_len)] = -_TC_rem - 1; \
|
453
|
+
} else { \
|
454
|
+
((signed char *)(TC_buf))[(TC_len)] = _TC_rem; \
|
455
|
+
} \
|
456
|
+
(TC_len)++; \
|
457
|
+
} \
|
458
|
+
} \
|
459
|
+
} while(false)
|
460
|
+
|
461
|
+
/* set a buffer for a variable length number of 64-bit */
|
462
|
+
#define TCSETVNUMBUF64(TC_len, TC_buf, TC_num) \
|
463
|
+
do { \
|
464
|
+
long long int _TC_num = (TC_num); \
|
465
|
+
if(_TC_num == 0){ \
|
466
|
+
((signed char *)(TC_buf))[0] = 0; \
|
467
|
+
(TC_len) = 1; \
|
468
|
+
} else { \
|
469
|
+
(TC_len) = 0; \
|
470
|
+
while(_TC_num > 0){ \
|
471
|
+
int _TC_rem = _TC_num & 0x7f; \
|
472
|
+
_TC_num >>= 7; \
|
473
|
+
if(_TC_num > 0){ \
|
474
|
+
((signed char *)(TC_buf))[(TC_len)] = -_TC_rem - 1; \
|
475
|
+
} else { \
|
476
|
+
((signed char *)(TC_buf))[(TC_len)] = _TC_rem; \
|
477
|
+
} \
|
478
|
+
(TC_len)++; \
|
479
|
+
} \
|
480
|
+
} \
|
481
|
+
} while(false)
|
482
|
+
|
483
|
+
/* read a variable length buffer */
|
484
|
+
#define TCREADVNUMBUF(TC_buf, TC_num, TC_step) \
|
485
|
+
do { \
|
486
|
+
TC_num = 0; \
|
487
|
+
int _TC_base = 1; \
|
488
|
+
int _TC_i = 0; \
|
489
|
+
while(true){ \
|
490
|
+
if(((signed char *)(TC_buf))[_TC_i] >= 0){ \
|
491
|
+
TC_num += ((signed char *)(TC_buf))[_TC_i] * _TC_base; \
|
492
|
+
break; \
|
493
|
+
} \
|
494
|
+
TC_num += _TC_base * (((signed char *)(TC_buf))[_TC_i] + 1) * -1; \
|
495
|
+
_TC_base <<= 7; \
|
496
|
+
_TC_i++; \
|
497
|
+
} \
|
498
|
+
(TC_step) = _TC_i + 1; \
|
499
|
+
} while(false)
|
500
|
+
|
501
|
+
/* read a variable length buffer */
|
502
|
+
#define TCREADVNUMBUF64(TC_buf, TC_num, TC_step) \
|
503
|
+
do { \
|
504
|
+
TC_num = 0; \
|
505
|
+
long long int _TC_base = 1; \
|
506
|
+
int _TC_i = 0; \
|
507
|
+
while(true){ \
|
508
|
+
if(((signed char *)(TC_buf))[_TC_i] >= 0){ \
|
509
|
+
TC_num += ((signed char *)(TC_buf))[_TC_i] * _TC_base; \
|
510
|
+
break; \
|
511
|
+
} \
|
512
|
+
TC_num += _TC_base * (((signed char *)(TC_buf))[_TC_i] + 1) * -1; \
|
513
|
+
_TC_base <<= 7; \
|
514
|
+
_TC_i++; \
|
515
|
+
} \
|
516
|
+
(TC_step) = _TC_i + 1; \
|
517
|
+
} while(false)
|
518
|
+
|
519
|
+
/* calculate the size of a buffer for a variable length number */
|
520
|
+
#define TCCALCVNUMSIZE(TC_num) \
|
521
|
+
((TC_num) < 0x80 ? 1 : (TC_num) < 0x4000 ? 2 : (TC_num) < 0x200000 ? 3 : \
|
522
|
+
(TC_num) < 0x10000000 ? 4 : 5)
|
523
|
+
|
524
|
+
/* compare keys of two records by lexical order */
|
525
|
+
#define TCCMPLEXICAL(TC_rv, TC_aptr, TC_asiz, TC_bptr, TC_bsiz) \
|
526
|
+
do { \
|
527
|
+
(TC_rv) = 0; \
|
528
|
+
int _TC_min = (TC_asiz) < (TC_bsiz) ? (TC_asiz) : (TC_bsiz); \
|
529
|
+
for(int _TC_i = 0; _TC_i < _TC_min; _TC_i++){ \
|
530
|
+
if(((unsigned char *)(TC_aptr))[_TC_i] != ((unsigned char *)(TC_bptr))[_TC_i]){ \
|
531
|
+
(TC_rv) = ((unsigned char *)(TC_aptr))[_TC_i] - ((unsigned char *)(TC_bptr))[_TC_i]; \
|
532
|
+
break; \
|
533
|
+
} \
|
534
|
+
} \
|
535
|
+
if((TC_rv) == 0) (TC_rv) = (TC_asiz) - (TC_bsiz); \
|
536
|
+
} while(false)
|
537
|
+
|
538
|
+
|
539
|
+
|
540
|
+
#endif // duplication check
|
541
|
+
|
542
|
+
|
543
|
+
// END OF FILE
|