isomorfeus-ferret 0.17.1 → 0.17.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/ext/isomorfeus_ferret_ext/benchmark.c +9 -20
  3. data/ext/isomorfeus_ferret_ext/benchmarks_all.h +1 -2
  4. data/ext/isomorfeus_ferret_ext/bm_hash.c +1 -2
  5. data/ext/isomorfeus_ferret_ext/bm_store.c +2 -0
  6. data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +4 -2
  7. data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +3 -2
  8. data/ext/isomorfeus_ferret_ext/frb_analysis.c +4 -5
  9. data/ext/isomorfeus_ferret_ext/frb_field_info.c +3 -4
  10. data/ext/isomorfeus_ferret_ext/frb_index.c +118 -160
  11. data/ext/isomorfeus_ferret_ext/frb_lazy_doc.c +14 -16
  12. data/ext/isomorfeus_ferret_ext/frb_search.c +31 -23
  13. data/ext/isomorfeus_ferret_ext/frb_store.c +27 -13
  14. data/ext/isomorfeus_ferret_ext/frb_utils.c +3 -6
  15. data/ext/isomorfeus_ferret_ext/frt_analysis.c +39 -46
  16. data/ext/isomorfeus_ferret_ext/frt_analysis.h +9 -9
  17. data/ext/isomorfeus_ferret_ext/frt_array.c +11 -22
  18. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +3 -6
  19. data/ext/isomorfeus_ferret_ext/frt_doc_field.c +87 -0
  20. data/ext/isomorfeus_ferret_ext/frt_doc_field.h +26 -0
  21. data/ext/isomorfeus_ferret_ext/frt_document.c +4 -97
  22. data/ext/isomorfeus_ferret_ext/frt_document.h +2 -27
  23. data/ext/isomorfeus_ferret_ext/frt_except.c +50 -6
  24. data/ext/isomorfeus_ferret_ext/frt_except.h +3 -2
  25. data/ext/isomorfeus_ferret_ext/frt_field_index.c +13 -32
  26. data/ext/isomorfeus_ferret_ext/frt_field_index.h +0 -6
  27. data/ext/isomorfeus_ferret_ext/frt_field_info.c +69 -0
  28. data/ext/isomorfeus_ferret_ext/frt_field_info.h +49 -0
  29. data/ext/isomorfeus_ferret_ext/frt_field_infos.c +196 -0
  30. data/ext/isomorfeus_ferret_ext/frt_field_infos.h +35 -0
  31. data/ext/isomorfeus_ferret_ext/frt_global.c +10 -4
  32. data/ext/isomorfeus_ferret_ext/frt_global.h +11 -15
  33. data/ext/isomorfeus_ferret_ext/frt_hash.c +8 -8
  34. data/ext/isomorfeus_ferret_ext/frt_hash.h +1 -2
  35. data/ext/isomorfeus_ferret_ext/frt_hashset.c +20 -40
  36. data/ext/isomorfeus_ferret_ext/frt_hashset.h +1 -2
  37. data/ext/isomorfeus_ferret_ext/frt_helper.c +7 -15
  38. data/ext/isomorfeus_ferret_ext/frt_in_stream.c +482 -0
  39. data/ext/isomorfeus_ferret_ext/frt_in_stream.h +241 -0
  40. data/ext/isomorfeus_ferret_ext/frt_ind.c +20 -49
  41. data/ext/isomorfeus_ferret_ext/frt_ind.h +0 -1
  42. data/ext/isomorfeus_ferret_ext/frt_index.c +296 -1857
  43. data/ext/isomorfeus_ferret_ext/frt_index.h +2 -145
  44. data/ext/isomorfeus_ferret_ext/frt_lang.c +5 -10
  45. data/ext/isomorfeus_ferret_ext/frt_lazy_doc.c +29 -0
  46. data/ext/isomorfeus_ferret_ext/frt_lazy_doc.h +19 -0
  47. data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.c +93 -0
  48. data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.h +33 -0
  49. data/ext/isomorfeus_ferret_ext/frt_mdbx_store.c +102 -70
  50. data/ext/isomorfeus_ferret_ext/frt_mempool.c +8 -16
  51. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +23 -46
  52. data/ext/isomorfeus_ferret_ext/frt_multimapper.h +4 -8
  53. data/ext/isomorfeus_ferret_ext/frt_out_stream.c +334 -0
  54. data/ext/isomorfeus_ferret_ext/frt_out_stream.h +198 -0
  55. data/ext/isomorfeus_ferret_ext/frt_posh.c +6 -819
  56. data/ext/isomorfeus_ferret_ext/frt_posh.h +0 -57
  57. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +11 -22
  58. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +1 -2
  59. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +85 -171
  60. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +8 -16
  61. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +1 -2
  62. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +49 -98
  63. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +52 -104
  64. data/ext/isomorfeus_ferret_ext/frt_q_range.c +6 -12
  65. data/ext/isomorfeus_ferret_ext/frt_q_span.c +113 -226
  66. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +1 -2
  67. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +134 -85
  68. data/ext/isomorfeus_ferret_ext/frt_ram_store.h +12 -0
  69. data/ext/isomorfeus_ferret_ext/frt_search.c +82 -164
  70. data/ext/isomorfeus_ferret_ext/frt_similarity.c +11 -22
  71. data/ext/isomorfeus_ferret_ext/frt_similarity.h +1 -2
  72. data/ext/isomorfeus_ferret_ext/frt_store.c +13 -536
  73. data/ext/isomorfeus_ferret_ext/frt_store.h +90 -495
  74. data/ext/isomorfeus_ferret_ext/frt_stream.h +18 -0
  75. data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +8 -16
  76. data/ext/isomorfeus_ferret_ext/frt_win32.h +5 -10
  77. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +12 -11
  78. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +11 -13
  79. data/ext/isomorfeus_ferret_ext/lz4.c +422 -195
  80. data/ext/isomorfeus_ferret_ext/lz4.h +114 -46
  81. data/ext/isomorfeus_ferret_ext/lz4frame.c +421 -242
  82. data/ext/isomorfeus_ferret_ext/lz4frame.h +122 -53
  83. data/ext/isomorfeus_ferret_ext/lz4hc.c +127 -111
  84. data/ext/isomorfeus_ferret_ext/lz4hc.h +14 -14
  85. data/ext/isomorfeus_ferret_ext/lz4xxhash.h +1 -1
  86. data/ext/isomorfeus_ferret_ext/mdbx.c +3762 -2526
  87. data/ext/isomorfeus_ferret_ext/mdbx.h +115 -70
  88. data/ext/isomorfeus_ferret_ext/test.c +40 -87
  89. data/ext/isomorfeus_ferret_ext/test.h +3 -6
  90. data/ext/isomorfeus_ferret_ext/test_1710.c +11 -13
  91. data/ext/isomorfeus_ferret_ext/test_analysis.c +32 -64
  92. data/ext/isomorfeus_ferret_ext/test_array.c +6 -12
  93. data/ext/isomorfeus_ferret_ext/test_bitvector.c +12 -24
  94. data/ext/isomorfeus_ferret_ext/test_document.c +23 -33
  95. data/ext/isomorfeus_ferret_ext/test_except.c +10 -21
  96. data/ext/isomorfeus_ferret_ext/test_fields.c +62 -68
  97. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +15 -24
  98. data/ext/isomorfeus_ferret_ext/test_filter.c +17 -27
  99. data/ext/isomorfeus_ferret_ext/test_global.c +14 -29
  100. data/ext/isomorfeus_ferret_ext/test_hash.c +19 -38
  101. data/ext/isomorfeus_ferret_ext/test_hashset.c +8 -16
  102. data/ext/isomorfeus_ferret_ext/test_helper.c +4 -8
  103. data/ext/isomorfeus_ferret_ext/test_highlighter.c +16 -28
  104. data/ext/isomorfeus_ferret_ext/test_index.c +277 -495
  105. data/ext/isomorfeus_ferret_ext/test_lang.c +7 -14
  106. data/ext/isomorfeus_ferret_ext/test_mdbx_store.c +2 -5
  107. data/ext/isomorfeus_ferret_ext/test_mempool.c +5 -10
  108. data/ext/isomorfeus_ferret_ext/test_multimapper.c +3 -6
  109. data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +9 -18
  110. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +4 -6
  111. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +3 -4
  112. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +9 -15
  113. data/ext/isomorfeus_ferret_ext/test_q_parser.c +8 -16
  114. data/ext/isomorfeus_ferret_ext/test_q_span.c +19 -35
  115. data/ext/isomorfeus_ferret_ext/test_ram_store.c +14 -13
  116. data/ext/isomorfeus_ferret_ext/test_search.c +60 -109
  117. data/ext/isomorfeus_ferret_ext/test_segments.c +8 -13
  118. data/ext/isomorfeus_ferret_ext/test_similarity.c +2 -4
  119. data/ext/isomorfeus_ferret_ext/test_sort.c +14 -24
  120. data/ext/isomorfeus_ferret_ext/test_store.c +96 -115
  121. data/ext/isomorfeus_ferret_ext/test_term.c +9 -15
  122. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -14
  123. data/ext/isomorfeus_ferret_ext/test_test.c +4 -8
  124. data/ext/isomorfeus_ferret_ext/test_threading.c +15 -30
  125. data/ext/isomorfeus_ferret_ext/testhelper.c +11 -21
  126. data/ext/isomorfeus_ferret_ext/testhelper.h +1 -1
  127. data/ext/isomorfeus_ferret_ext/tests_all.h +1 -2
  128. data/lib/isomorfeus/ferret/index/index.rb +1 -12
  129. data/lib/isomorfeus/ferret/version.rb +1 -1
  130. metadata +43 -4
@@ -1,9 +1,6 @@
1
1
  #include "frt_store.h"
2
2
  #include <string.h>
3
3
 
4
- #define VINT_MAX_LEN 10
5
- #define VINT_END FRT_BUFFER_SIZE - VINT_MAX_LEN
6
-
7
4
  /*
8
5
  * TODO: add try finally
9
6
  */
@@ -18,8 +15,8 @@ void frt_with_lock(FrtLock *lock, void (*func)(void *arg), void *arg) {
18
15
  /*
19
16
  * TODO: add try finally
20
17
  */
21
- void frt_with_lock_name(FrtStore *store, const char *lock_name, void (*func)(void *arg), void *arg) {
22
- FrtLock *lock = store->open_lock_i(store, lock_name);
18
+ void frt_with_lock_name(FrtStore *store, const char *folder_name, const char *lock_name, void (*func)(void *arg), void *arg) {
19
+ FrtLock *lock = store->open_lock_i(store, folder_name, lock_name);
23
20
  if (!lock->obtain(lock)) {
24
21
  FRT_RAISE(FRT_LOCK_ERROR, "couldn't obtain lock \"%s\"", lock->name);
25
22
  }
@@ -28,20 +25,17 @@ void frt_with_lock_name(FrtStore *store, const char *lock_name, void (*func)(voi
28
25
  store->close_lock_i(lock);
29
26
  }
30
27
 
31
- FrtLock *frt_open_lock(FrtStore *store, const char *lockname)
32
- {
33
- FrtLock *lock = store->open_lock_i(store, lockname);
28
+ FrtLock *frt_open_lock(FrtStore *store, const char *folder_name, const char *lockname) {
29
+ FrtLock *lock = store->open_lock_i(store, folder_name, lockname);
34
30
  frt_hs_add(store->locks, lock);
35
31
  return lock;
36
32
  }
37
33
 
38
- void frt_close_lock(FrtLock *lock)
39
- {
34
+ void frt_close_lock(FrtLock *lock) {
40
35
  frt_hs_del(lock->store->locks, lock);
41
36
  }
42
37
 
43
- static void frt_close_lock_i(FrtLock *lock)
44
- {
38
+ static void frt_close_lock_i(FrtLock *lock) {
45
39
  lock->store->close_lock_i(lock);
46
40
  }
47
41
 
@@ -87,517 +81,6 @@ void frt_store_close(FrtStore *store) {
87
81
  }
88
82
  }
89
83
 
90
- /**
91
- * Create a newly allocated and initialized OutStream object
92
- *
93
- * @return a newly allocated and initialized OutStream object
94
- */
95
- FrtOutStream *frt_os_new(void) {
96
- FrtOutStream *os = FRT_ALLOC(FrtOutStream);
97
- os->buf.start = 0;
98
- os->buf.pos = 0;
99
- os->buf.len = 0;
100
- return os;
101
- }
102
-
103
- /**
104
- * Flush the countents of the FrtOutStream's buffers
105
- *
106
- * @param the OutStream to flush
107
- */
108
- void frt_os_flush(FrtOutStream *os)
109
- {
110
- os->m->flush_i(os, os->buf.buf, os->buf.pos);
111
- os->buf.start += os->buf.pos;
112
- os->buf.pos = 0;
113
- }
114
-
115
- void frt_os_close(FrtOutStream *os)
116
- {
117
- frt_os_flush(os);
118
- os->m->close_i(os);
119
- free(os);
120
- }
121
-
122
- off_t frt_os_pos(FrtOutStream *os)
123
- {
124
- return os->buf.start + os->buf.pos;
125
- }
126
-
127
- void frt_os_seek(FrtOutStream *os, frt_off_t new_pos)
128
- {
129
- frt_os_flush(os);
130
- os->buf.start = new_pos;
131
- os->m->seek_i(os, new_pos);
132
- }
133
-
134
- /**
135
- * Unsafe alternative to os_write_byte. Only use this method if you know there
136
- * is no chance of buffer overflow.
137
- */
138
- #define write_byte(os, b) os->buf.buf[os->buf.pos++] = (frt_uchar)b
139
-
140
- /**
141
- * Write a single byte +b+ to the OutStream +os+
142
- *
143
- * @param os the OutStream to write to
144
- * @param b the byte to write
145
- * @raise FRT_IO_ERROR if there is an IO error writing to the filesystem
146
- */
147
- void frt_os_write_byte(FrtOutStream *os, frt_uchar b)
148
- {
149
- if (os->buf.pos >= (FRT_BUFFER_SIZE - 1)) {
150
- frt_os_flush(os);
151
- }
152
- write_byte(os, b);
153
- }
154
-
155
- void frt_os_write_bytes(FrtOutStream *os, const frt_uchar *buf, int len)
156
- {
157
- if (len < (FRT_BUFFER_SIZE - os->buf.pos)) {
158
- memcpy(os->buf.buf + os->buf.pos, buf, len);
159
- os->buf.pos += len;
160
- }
161
- else {
162
- frt_os_flush(os);
163
- int pos = 0;
164
- int size;
165
- while (pos < len) {
166
- if (len - pos < FRT_BUFFER_SIZE) {
167
- size = len - pos;
168
- }
169
- else {
170
- size = FRT_BUFFER_SIZE;
171
- }
172
- os->m->flush_i(os, buf + pos, size);
173
- pos += size;
174
- os->buf.start += size;
175
- }
176
- }
177
- }
178
-
179
- /**
180
- * Create a newly allocated and initialized InStream
181
- *
182
- * @return a newly allocated and initialized InStream
183
- */
184
- FrtInStream *frt_is_new(void) {
185
- FrtInStream *is = FRT_ALLOC(FrtInStream);
186
- is->f = FRT_ALLOC_AND_ZERO(FrtInStreamFile);
187
- is->f->ref_cnt = 1;
188
- is->buf.start = 0;
189
- is->buf.pos = 0;
190
- is->buf.len = 0;
191
- is->ref_cnt = 1;
192
- return is;
193
- }
194
-
195
- /**
196
- * Refill the InStream's buffer from the store source (filesystem or memory).
197
- *
198
- * @param is the InStream to refill
199
- * @raise FRT_IO_ERROR if there is a error reading from the filesystem
200
- * @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
201
- */
202
- static void is_refill(FrtInStream *is)
203
- {
204
- frt_off_t start = is->buf.start + is->buf.pos;
205
- frt_off_t last = start + FRT_BUFFER_SIZE;
206
- frt_off_t flen = is->m->length_i(is);
207
-
208
- if (last > flen) { /* don't read past EOF */
209
- last = flen;
210
- }
211
-
212
- is->buf.len = last - start;
213
- if (is->buf.len <= 0) {
214
- FRT_RAISE(FRT_EOF_ERROR, "current pos = %"FRT_OFF_T_PFX"d, "
215
- "file length = %"FRT_OFF_T_PFX"d", start, flen);
216
- }
217
-
218
- is->m->read_i(is, is->buf.buf, is->buf.len);
219
-
220
- is->buf.start = start;
221
- is->buf.pos = 0;
222
- }
223
-
224
- /**
225
- * Unsafe alternative to frt_is_read_byte. Only use this method when you know
226
- * there is no chance that you will read past the end of the InStream's
227
- * buffer.
228
- */
229
- #define read_byte(is) is->buf.buf[is->buf.pos++]
230
-
231
- /**
232
- * Read a singly byte (unsigned char) from the InStream +is+.
233
- *
234
- * @param is the Instream to read from
235
- * @return a single unsigned char read from the InStream +is+
236
- * @raise FRT_IO_ERROR if there is a error reading from the filesystem
237
- * @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
238
- */
239
- frt_uchar frt_is_read_byte(FrtInStream *is)
240
- {
241
- if (is->buf.pos >= is->buf.len) {
242
- is_refill(is);
243
- }
244
-
245
- return read_byte(is);
246
- }
247
-
248
- off_t frt_is_pos(FrtInStream *is)
249
- {
250
- return is->buf.start + is->buf.pos;
251
- }
252
-
253
- frt_uchar *frt_is_read_bytes(FrtInStream *is, frt_uchar *buf, int len)
254
- {
255
- int i;
256
- frt_off_t start;
257
-
258
- if ((is->buf.pos + len) < is->buf.len) {
259
- for (i = 0; i < len; i++) {
260
- buf[i] = read_byte(is);
261
- }
262
- }
263
- else { /* read all-at-once */
264
- start = frt_is_pos(is);
265
- is->m->seek_i(is, start);
266
- is->m->read_i(is, buf, len);
267
-
268
- is->buf.start = start + len; /* adjust stream variables */
269
- is->buf.pos = 0;
270
- is->buf.len = 0; /* trigger refill on read */
271
- }
272
- return buf;
273
- }
274
-
275
- void frt_is_seek(FrtInStream *is, frt_off_t pos) {
276
- if (pos >= is->buf.start && pos < (is->buf.start + is->buf.len)) {
277
- is->buf.pos = pos - is->buf.start; /* seek within buffer */
278
- } else {
279
- is->buf.start = pos;
280
- is->buf.pos = 0;
281
- is->buf.len = 0; /* trigger refill() on read() */
282
- is->m->seek_i(is, pos);
283
- }
284
- }
285
-
286
- void frt_is_close(FrtInStream *is) {
287
- if (is->ref_cnt == 0) {
288
- FRT_RAISE(FRT_STATE_ERROR, "is ref_cnt to low\n");
289
- }
290
-
291
- if (FRT_DEREF(is) == 0) {
292
- if (FRT_DEREF(is->f) == 0) {
293
- is->m->close_i(is);
294
- free(is->f);
295
- }
296
- free(is);
297
- }
298
- }
299
-
300
- FrtInStream *frt_is_clone(FrtInStream *is)
301
- {
302
- if (!(is->f))
303
- return NULL;
304
- FrtInStream *new_is = FRT_ALLOC(FrtInStream);
305
- memcpy(new_is, is, sizeof(FrtInStream));
306
- new_is->ref_cnt = 1;
307
- FRT_REF(new_is->f);
308
- return new_is;
309
- }
310
-
311
- frt_i32 frt_is_read_i32(FrtInStream *is)
312
- {
313
- return ((frt_i32)frt_is_read_byte(is) << 24) |
314
- ((frt_i32)frt_is_read_byte(is) << 16) |
315
- ((frt_i32)frt_is_read_byte(is) << 8) |
316
- ((frt_i32)frt_is_read_byte(is));
317
- }
318
-
319
-
320
- frt_i64 frt_is_read_i64(FrtInStream *is)
321
- {
322
- return ((frt_i64)frt_is_read_byte(is) << 56) |
323
- ((frt_i64)frt_is_read_byte(is) << 48) |
324
- ((frt_i64)frt_is_read_byte(is) << 40) |
325
- ((frt_i64)frt_is_read_byte(is) << 32) |
326
- ((frt_i64)frt_is_read_byte(is) << 24) |
327
- ((frt_i64)frt_is_read_byte(is) << 16) |
328
- ((frt_i64)frt_is_read_byte(is) << 8) |
329
- ((frt_i64)frt_is_read_byte(is));
330
- }
331
-
332
- frt_u32 frt_is_read_u32(FrtInStream *is)
333
- {
334
- return ((frt_u32)frt_is_read_byte(is) << 24) |
335
- ((frt_u32)frt_is_read_byte(is) << 16) |
336
- ((frt_u32)frt_is_read_byte(is) << 8) |
337
- ((frt_u32)frt_is_read_byte(is));
338
- }
339
-
340
- frt_u64 frt_is_read_u64(FrtInStream *is)
341
- {
342
- return ((frt_u64)frt_is_read_byte(is) << 56) |
343
- ((frt_u64)frt_is_read_byte(is) << 48) |
344
- ((frt_u64)frt_is_read_byte(is) << 40) |
345
- ((frt_u64)frt_is_read_byte(is) << 32) |
346
- ((frt_u64)frt_is_read_byte(is) << 24) |
347
- ((frt_u64)frt_is_read_byte(is) << 16) |
348
- ((frt_u64)frt_is_read_byte(is) << 8) |
349
- ((frt_u64)frt_is_read_byte(is));
350
- }
351
-
352
- /* optimized to use unchecked read_byte if there is definitely space */
353
- unsigned int frt_is_read_vint(FrtInStream *is)
354
- {
355
- register unsigned int res, b;
356
- register int shift = 7;
357
-
358
- if (is->buf.pos > (is->buf.len - VINT_MAX_LEN)) {
359
- b = frt_is_read_byte(is);
360
- res = b & 0x7F; /* 0x7F = 0b01111111 */
361
-
362
- while ((b & 0x80) != 0) { /* 0x80 = 0b10000000 */
363
- b = frt_is_read_byte(is);
364
- res |= (b & 0x7F) << shift;
365
- shift += 7;
366
- }
367
- }
368
- else { /* unchecked optimization */
369
- b = read_byte(is);
370
- res = b & 0x7F; /* 0x7F = 0b01111111 */
371
-
372
- while ((b & 0x80) != 0) { /* 0x80 = 0b10000000 */
373
- b = read_byte(is);
374
- res |= (b & 0x7F) << shift;
375
- shift += 7;
376
- }
377
- }
378
-
379
- return res;
380
- }
381
-
382
- /* optimized to use unchecked read_byte if there is definitely space */
383
- off_t frt_is_read_voff_t(FrtInStream *is)
384
- {
385
- register frt_off_t res, b;
386
- register int shift = 7;
387
-
388
- if (is->buf.pos > (is->buf.len - VINT_MAX_LEN)) {
389
- b = frt_is_read_byte(is);
390
- res = b & 0x7F; /* 0x7F = 0b01111111 */
391
-
392
- while ((b & 0x80) != 0) { /* 0x80 = 0b10000000 */
393
- b = frt_is_read_byte(is);
394
- res |= (b & 0x7F) << shift;
395
- shift += 7;
396
- }
397
- }
398
- else { /* unchecked optimization */
399
- b = read_byte(is);
400
- res = b & 0x7F; /* 0x7F = 0b01111111 */
401
-
402
- while ((b & 0x80) != 0) { /* 0x80 = 0b10000000 */
403
- b = read_byte(is);
404
- res |= (b & 0x7F) << shift;
405
- shift += 7;
406
- }
407
- }
408
-
409
- return res;
410
- }
411
-
412
- /* optimized to use unchecked read_byte if there is definitely space */
413
- frt_u64 frt_is_read_vll(FrtInStream *is)
414
- {
415
- register frt_u64 res, b;
416
- register int shift = 7;
417
-
418
- if (is->buf.pos > (is->buf.len - VINT_MAX_LEN)) {
419
- b = frt_is_read_byte(is);
420
- res = b & 0x7F; /* 0x7F = 0b01111111 */
421
-
422
- while ((b & 0x80) != 0) { /* 0x80 = 0b10000000 */
423
- b = frt_is_read_byte(is);
424
- res |= (b & 0x7F) << shift;
425
- shift += 7;
426
- }
427
- }
428
- else { /* unchecked optimization */
429
- b = read_byte(is);
430
- res = b & 0x7F; /* 0x7F = 0b01111111 */
431
-
432
- while ((b & 0x80) != 0) { /* 0x80 = 0b10000000 */
433
- b = read_byte(is);
434
- res |= (b & 0x7F) << shift;
435
- shift += 7;
436
- }
437
- }
438
-
439
- return res;
440
- }
441
-
442
- void frt_is_skip_vints(FrtInStream *is, register int cnt)
443
- {
444
- for (; cnt > 0; cnt--) {
445
- while ((frt_is_read_byte(is) & 0x80) != 0) {
446
- }
447
- }
448
- }
449
-
450
- char *frt_is_read_string(FrtInStream *is)
451
- {
452
- register int length = (int) frt_is_read_vint(is);
453
- char *str = FRT_ALLOC_N(char, length + 1);
454
- str[length] = '\0';
455
-
456
- if (is->buf.pos > (is->buf.len - length)) {
457
- register int i;
458
- for (i = 0; i < length; i++) {
459
- str[i] = frt_is_read_byte(is);
460
- }
461
- }
462
- else { /* unchecked optimization */
463
- memcpy(str, is->buf.buf + is->buf.pos, length);
464
- is->buf.pos += length;
465
- }
466
-
467
- return str;
468
- }
469
-
470
- char *frt_is_read_string_safe(FrtInStream *is)
471
- {
472
- register int length = (int) frt_is_read_vint(is);
473
- char *str = FRT_ALLOC_N(char, length + 1);
474
- str[length] = '\0';
475
-
476
- FRT_TRY
477
- if (is->buf.pos > (is->buf.len - length)) {
478
- register int i;
479
- for (i = 0; i < length; i++) {
480
- str[i] = frt_is_read_byte(is);
481
- }
482
- }
483
- else { /* unchecked optimization */
484
- memcpy(str, is->buf.buf + is->buf.pos, length);
485
- is->buf.pos += length;
486
- }
487
- FRT_XCATCHALL
488
- free(str);
489
- FRT_XENDTRY
490
-
491
- return str;
492
- }
493
-
494
- void frt_os_write_i32(FrtOutStream *os, frt_i32 num)
495
- {
496
- frt_os_write_byte(os, (frt_uchar)((num >> 24) & 0xFF));
497
- frt_os_write_byte(os, (frt_uchar)((num >> 16) & 0xFF));
498
- frt_os_write_byte(os, (frt_uchar)((num >> 8) & 0xFF));
499
- frt_os_write_byte(os, (frt_uchar)(num & 0xFF));
500
- }
501
-
502
- void frt_os_write_i64(FrtOutStream *os, frt_i64 num)
503
- {
504
- frt_os_write_byte(os, (frt_uchar)((num >> 56) & 0xFF));
505
- frt_os_write_byte(os, (frt_uchar)((num >> 48) & 0xFF));
506
- frt_os_write_byte(os, (frt_uchar)((num >> 40) & 0xFF));
507
- frt_os_write_byte(os, (frt_uchar)((num >> 32) & 0xFF));
508
- frt_os_write_byte(os, (frt_uchar)((num >> 24) & 0xFF));
509
- frt_os_write_byte(os, (frt_uchar)((num >> 16) & 0xFF));
510
- frt_os_write_byte(os, (frt_uchar)((num >> 8) & 0xFF));
511
- frt_os_write_byte(os, (frt_uchar)(num & 0xFF));
512
- }
513
-
514
- void frt_os_write_u32(FrtOutStream *os, frt_u32 num)
515
- {
516
- frt_os_write_byte(os, (frt_uchar)((num >> 24) & 0xFF));
517
- frt_os_write_byte(os, (frt_uchar)((num >> 16) & 0xFF));
518
- frt_os_write_byte(os, (frt_uchar)((num >> 8) & 0xFF));
519
- frt_os_write_byte(os, (frt_uchar)(num & 0xFF));
520
- }
521
-
522
- void frt_os_write_u64(FrtOutStream *os, frt_u64 num)
523
- {
524
- frt_os_write_byte(os, (frt_uchar)((num >> 56) & 0xFF));
525
- frt_os_write_byte(os, (frt_uchar)((num >> 48) & 0xFF));
526
- frt_os_write_byte(os, (frt_uchar)((num >> 40) & 0xFF));
527
- frt_os_write_byte(os, (frt_uchar)((num >> 32) & 0xFF));
528
- frt_os_write_byte(os, (frt_uchar)((num >> 24) & 0xFF));
529
- frt_os_write_byte(os, (frt_uchar)((num >> 16) & 0xFF));
530
- frt_os_write_byte(os, (frt_uchar)((num >> 8) & 0xFF));
531
- frt_os_write_byte(os, (frt_uchar)(num & 0xFF));
532
- }
533
-
534
- /* optimized to use an unchecked write if there is space */
535
- void frt_os_write_vint(FrtOutStream *os, register unsigned int num)
536
- {
537
- if (os->buf.pos > VINT_END) {
538
- while (num > 127) {
539
- frt_os_write_byte(os, (frt_uchar)((num & 0x7f) | 0x80));
540
- num >>= 7;
541
- }
542
- frt_os_write_byte(os, (frt_uchar)(num));
543
- }
544
- else {
545
- while (num > 127) {
546
- write_byte(os, (frt_uchar)((num & 0x7f) | 0x80));
547
- num >>= 7;
548
- }
549
- write_byte(os, (frt_uchar)(num));
550
- }
551
- }
552
-
553
- /* optimized to use an unchecked write if there is space */
554
- void frt_os_write_voff_t(FrtOutStream *os, register frt_off_t num)
555
- {
556
- if (os->buf.pos > VINT_END) {
557
- while (num > 127) {
558
- frt_os_write_byte(os, (frt_uchar)((num & 0x7f) | 0x80));
559
- num >>= 7;
560
- }
561
- frt_os_write_byte(os, (frt_uchar)num);
562
- }
563
- else {
564
- while (num > 127) {
565
- write_byte(os, (frt_uchar)((num & 0x7f) | 0x80));
566
- num >>= 7;
567
- }
568
- write_byte(os, (frt_uchar)num);
569
- }
570
- }
571
-
572
- /* optimized to use an unchecked write if there is space */
573
- void frt_os_write_vll(FrtOutStream *os, register frt_u64 num)
574
- {
575
- if (os->buf.pos > VINT_END) {
576
- while (num > 127) {
577
- frt_os_write_byte(os, (frt_uchar)((num & 0x7f) | 0x80));
578
- num >>= 7;
579
- }
580
- frt_os_write_byte(os, (frt_uchar)num);
581
- }
582
- else {
583
- while (num > 127) {
584
- write_byte(os, (frt_uchar)((num & 0x7f) | 0x80));
585
- num >>= 7;
586
- }
587
- write_byte(os, (frt_uchar)num);
588
- }
589
- }
590
-
591
- void frt_os_write_string_len(FrtOutStream *os, const char *str, int len)
592
- {
593
- frt_os_write_vint(os, len);
594
- frt_os_write_bytes(os, (frt_uchar *)str, len);
595
- }
596
- void frt_os_write_string(FrtOutStream *os, const char *str)
597
- {
598
- frt_os_write_string_len(os, str, (int)strlen(str));
599
- }
600
-
601
84
  /**
602
85
  * Determine if the filename is the name of a lock file. Return 1 if it is, 0
603
86
  * otherwise.
@@ -605,14 +88,12 @@ void frt_os_write_string(FrtOutStream *os, const char *str)
605
88
  * @param filename the name of the file to check
606
89
  * @return 1 (true) if the file is a lock file, 0 (false) otherwise
607
90
  */
608
- int frt_file_is_lock(const char *filename)
609
- {
91
+ int frt_file_is_lock(const char *filename) {
610
92
  int start = (int) strlen(filename) - 4;
611
93
  return ((start > 0) && (strcmp(FRT_LOCK_EXT, &filename[start]) == 0));
612
94
  }
613
95
 
614
- void frt_is2os_copy_bytes(FrtInStream *is, FrtOutStream *os, int cnt)
615
- {
96
+ void frt_is2os_copy_bytes(FrtInStream *is, FrtOutStream *os, int cnt) {
616
97
  int len;
617
98
  frt_uchar buf[FRT_BUFFER_SIZE];
618
99
 
@@ -623,8 +104,7 @@ void frt_is2os_copy_bytes(FrtInStream *is, FrtOutStream *os, int cnt)
623
104
  }
624
105
  }
625
106
 
626
- void frt_is2os_copy_vints(FrtInStream *is, FrtOutStream *os, int cnt)
627
- {
107
+ void frt_is2os_copy_vints(FrtInStream *is, FrtOutStream *os, int cnt) {
628
108
  frt_uchar b;
629
109
  for (; cnt > 0; cnt--) {
630
110
  while (((b = frt_is_read_byte(is)) & 0x80) != 0) {
@@ -637,8 +117,7 @@ void frt_is2os_copy_vints(FrtInStream *is, FrtOutStream *os, int cnt)
637
117
  /**
638
118
  * Test argument used to test the store->each function
639
119
  */
640
- struct FileNameListArg
641
- {
120
+ struct FileNameListArg {
642
121
  int count;
643
122
  int size;
644
123
  int total_len;
@@ -648,8 +127,7 @@ struct FileNameListArg
648
127
  /**
649
128
  * Test function used to test store->each function
650
129
  */
651
- static void add_file_name(const char *fname, void *arg)
652
- {
130
+ static void add_file_name(const char *fname, void *arg) {
653
131
  struct FileNameListArg *fnl = (struct FileNameListArg *)arg;
654
132
  if (fnl->count >= fnl->size) {
655
133
  fnl->size *= 2;
@@ -659,8 +137,7 @@ static void add_file_name(const char *fname, void *arg)
659
137
  fnl->total_len += strlen(fname) + 2;
660
138
  }
661
139
 
662
- char *frt_store_to_s(FrtStore *store)
663
- {
140
+ char *frt_store_folder_to_s(FrtStore *store, const char *folder_name) {
664
141
  struct FileNameListArg fnl;
665
142
  char *buf, *b;
666
143
  int i;
@@ -669,7 +146,7 @@ char *frt_store_to_s(FrtStore *store)
669
146
  fnl.total_len = 10;
670
147
  fnl.files = FRT_ALLOC_N(char *, 16);
671
148
 
672
- store->each(store, &add_file_name, &fnl);
149
+ store->each(store, folder_name, &add_file_name, &fnl);
673
150
  qsort(fnl.files, fnl.count, sizeof(char *), &frt_scmp);
674
151
  b = buf = FRT_ALLOC_N(char, fnl.total_len);
675
152