isomorfeus-ferret 0.13.6 → 0.13.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -34
  3. data/ext/isomorfeus_ferret_ext/frb_analysis.c +7 -4
  4. data/ext/isomorfeus_ferret_ext/frb_index.c +18 -24
  5. data/ext/isomorfeus_ferret_ext/frb_qparser.c +2 -1
  6. data/ext/isomorfeus_ferret_ext/frb_search.c +23 -19
  7. data/ext/isomorfeus_ferret_ext/frb_store.c +34 -36
  8. data/ext/isomorfeus_ferret_ext/frt_analysis.c +2 -2
  9. data/ext/isomorfeus_ferret_ext/frt_analysis.h +5 -5
  10. data/ext/isomorfeus_ferret_ext/frt_bitvector.c +1 -1
  11. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +1 -1
  12. data/ext/isomorfeus_ferret_ext/frt_compound_io.c +34 -59
  13. data/ext/isomorfeus_ferret_ext/frt_except.c +1 -0
  14. data/ext/isomorfeus_ferret_ext/frt_field_index.c +1 -1
  15. data/ext/isomorfeus_ferret_ext/frt_filter.c +2 -4
  16. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +11 -12
  17. data/ext/isomorfeus_ferret_ext/frt_global.c +6 -4
  18. data/ext/isomorfeus_ferret_ext/frt_global.h +2 -2
  19. data/ext/isomorfeus_ferret_ext/frt_hash.c +40 -48
  20. data/ext/isomorfeus_ferret_ext/frt_hash.h +14 -16
  21. data/ext/isomorfeus_ferret_ext/frt_ind.c +3 -4
  22. data/ext/isomorfeus_ferret_ext/frt_index.c +127 -197
  23. data/ext/isomorfeus_ferret_ext/frt_index.h +13 -13
  24. data/ext/isomorfeus_ferret_ext/frt_lang.c +1 -4
  25. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +8 -9
  26. data/ext/isomorfeus_ferret_ext/frt_multimapper.h +1 -1
  27. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +7 -7
  28. data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +1 -1
  29. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +8 -3
  30. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +2 -2
  31. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +1742 -1742
  32. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +2 -3
  33. data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +1 -1
  34. data/ext/isomorfeus_ferret_ext/frt_q_range.c +1 -1
  35. data/ext/isomorfeus_ferret_ext/frt_q_span.c +12 -11
  36. data/ext/isomorfeus_ferret_ext/frt_q_term.c +2 -2
  37. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +1 -1
  38. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +18 -34
  39. data/ext/isomorfeus_ferret_ext/frt_search.c +30 -29
  40. data/ext/isomorfeus_ferret_ext/frt_search.h +18 -19
  41. data/ext/isomorfeus_ferret_ext/frt_sort.c +1 -1
  42. data/ext/isomorfeus_ferret_ext/frt_store.c +45 -41
  43. data/ext/isomorfeus_ferret_ext/frt_store.h +24 -26
  44. data/ext/isomorfeus_ferret_ext/frt_threading.h +12 -5
  45. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +4 -3
  46. data/ext/isomorfeus_ferret_ext/test_1710.c +1 -2
  47. data/ext/isomorfeus_ferret_ext/test_compound_io.c +8 -8
  48. data/ext/isomorfeus_ferret_ext/test_fields.c +7 -7
  49. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +1 -1
  50. data/ext/isomorfeus_ferret_ext/test_filter.c +5 -4
  51. data/ext/isomorfeus_ferret_ext/test_fs_store.c +1 -1
  52. data/ext/isomorfeus_ferret_ext/test_highlighter.c +4 -2
  53. data/ext/isomorfeus_ferret_ext/test_index.c +61 -61
  54. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +3 -2
  55. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +4 -3
  56. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +4 -2
  57. data/ext/isomorfeus_ferret_ext/test_q_span.c +9 -2
  58. data/ext/isomorfeus_ferret_ext/test_ram_store.c +4 -4
  59. data/ext/isomorfeus_ferret_ext/test_search.c +10 -5
  60. data/ext/isomorfeus_ferret_ext/test_segments.c +4 -3
  61. data/ext/isomorfeus_ferret_ext/test_sort.c +18 -10
  62. data/ext/isomorfeus_ferret_ext/test_store.c +1 -1
  63. data/ext/isomorfeus_ferret_ext/test_term.c +5 -3
  64. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +2 -2
  65. data/ext/isomorfeus_ferret_ext/test_threading.c +5 -4
  66. data/lib/isomorfeus/ferret/index/index.rb +8 -3
  67. data/lib/isomorfeus/ferret/version.rb +1 -1
  68. metadata +2 -2
@@ -1,7 +1,7 @@
1
1
  #include "frt_index.h"
2
2
  #include "frt_array.h"
3
3
 
4
- extern void frt_store_destroy(FrtStore *store);
4
+ extern void frt_store_close(FrtStore *store);
5
5
  extern FrtInStream *frt_is_new();
6
6
  extern FrtStore *frt_store_new();
7
7
 
@@ -16,45 +16,37 @@ typedef struct FileEntry {
16
16
  off_t length;
17
17
  } FileEntry;
18
18
 
19
- static void cmpd_touch(FrtStore *store, const char *file_name)
20
- {
19
+ static void cmpd_touch(FrtStore *store, const char *file_name) {
21
20
  store->dir.cmpd->store->touch(store->dir.cmpd->store, file_name);
22
21
  }
23
22
 
24
- static int cmpd_exists(FrtStore *store, const char *file_name)
25
- {
23
+ static int cmpd_exists(FrtStore *store, const char *file_name) {
26
24
  if (frt_h_get(store->dir.cmpd->entries, file_name) != NULL) {
27
25
  return true;
28
- }
29
- else {
26
+ } else {
30
27
  return false;
31
28
  }
32
29
  }
33
30
 
34
- static int cmpd_remove(FrtStore *store, const char *file_name)
35
- {
31
+ static int cmpd_remove(FrtStore *store, const char *file_name) {
36
32
  (void)store;
37
33
  (void)file_name;
38
34
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
39
35
  return 0;
40
36
  }
41
37
 
42
- static void cmpd_rename(FrtStore *store, const char *from, const char *to)
43
- {
38
+ static void cmpd_rename(FrtStore *store, const char *from, const char *to) {
44
39
  (void)store;
45
40
  (void)from;
46
41
  (void)to;
47
42
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
48
43
  }
49
44
 
50
- static int cmpd_count(FrtStore *store)
51
- {
45
+ static int cmpd_count(FrtStore *store) {
52
46
  return store->dir.cmpd->entries->size;
53
47
  }
54
48
 
55
- static void cmpd_each(FrtStore *store,
56
- void (*func)(const char *fname, void *arg), void *arg)
57
- {
49
+ static void cmpd_each(FrtStore *store, void (*func)(const char *fname, void *arg), void *arg) {
58
50
  FrtHash *ht = store->dir.cmpd->entries;
59
51
  int i;
60
52
  for (i = 0; i <= ht->mask; i++) {
@@ -65,15 +57,12 @@ static void cmpd_each(FrtStore *store,
65
57
  }
66
58
  }
67
59
 
68
-
69
- static void cmpd_clear(FrtStore *store)
70
- {
60
+ static void cmpd_clear(FrtStore *store) {
71
61
  (void)store;
72
62
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
73
63
  }
74
64
 
75
- static void cmpd_close_i(FrtStore *store)
76
- {
65
+ static void cmpd_close_i(FrtStore *store) {
77
66
  FrtCompoundStore *cmpd = store->dir.cmpd;
78
67
  if (cmpd->stream == NULL) {
79
68
  FRT_RAISE(FRT_IO_ERROR, "Tried to close already closed compound store");
@@ -83,42 +72,37 @@ static void cmpd_close_i(FrtStore *store)
83
72
 
84
73
  frt_is_close(cmpd->stream);
85
74
  cmpd->stream = NULL;
75
+ frt_store_close(cmpd->store);
86
76
  free(store->dir.cmpd);
87
- frt_store_destroy(store);
88
77
  }
89
78
 
90
- static off_t cmpd_length(FrtStore *store, const char *file_name)
91
- {
79
+ static off_t cmpd_length(FrtStore *store, const char *file_name) {
92
80
  FileEntry *fe = (FileEntry *)frt_h_get(store->dir.cmpd->entries, file_name);
93
81
  if (fe != NULL) {
94
82
  return fe->length;
95
- }
96
- else {
83
+ } else {
97
84
  return 0;
98
85
  }
99
86
  }
100
87
 
101
- static void cmpdi_seek_i(FrtInStream *is, off_t pos)
102
- {
88
+ static void cmpdi_seek_i(FrtInStream *is, off_t pos) {
103
89
  (void)is;
104
90
  (void)pos;
105
91
  }
106
92
 
107
- static void cmpdi_close_i(FrtInStream *is)
108
- {
93
+ static void cmpdi_close_i(FrtInStream *is) {
94
+ frt_is_close(is->d.cis->sub);
109
95
  free(is->d.cis);
110
96
  }
111
97
 
112
- static off_t cmpdi_length_i(FrtInStream *is)
113
- {
98
+ static off_t cmpdi_length_i(FrtInStream *is) {
114
99
  return (is->d.cis->length);
115
100
  }
116
101
 
117
102
  /*
118
103
  * raises: FRT_EOF_ERROR
119
104
  */
120
- static void cmpdi_read_i(FrtInStream *is, frt_uchar *b, int len)
121
- {
105
+ static void cmpdi_read_i(FrtInStream *is, frt_uchar *b, int len) {
122
106
  FrtCompoundInStream *cis = is->d.cis;
123
107
  off_t start = frt_is_pos(is);
124
108
 
@@ -139,12 +123,12 @@ static const struct FrtInStreamMethods CMPD_IN_STREAM_METHODS = {
139
123
  cmpdi_close_i
140
124
  };
141
125
 
142
- static FrtInStream *cmpd_create_input(FrtInStream *sub_is, off_t offset, off_t length)
143
- {
126
+ static FrtInStream *cmpd_create_input(FrtInStream *sub_is, off_t offset, off_t length) {
144
127
  FrtInStream *is = frt_is_new();
145
128
  FrtCompoundInStream *cis = FRT_ALLOC(FrtCompoundInStream);
146
129
 
147
130
  cis->sub = sub_is;
131
+ FRT_REF(sub_is);
148
132
  cis->offset = offset;
149
133
  cis->length = length;
150
134
  is->d.cis = cis;
@@ -153,8 +137,7 @@ static FrtInStream *cmpd_create_input(FrtInStream *sub_is, off_t offset, off_t l
153
137
  return is;
154
138
  }
155
139
 
156
- static FrtInStream *cmpd_open_input(FrtStore *store, const char *file_name)
157
- {
140
+ static FrtInStream *cmpd_open_input(FrtStore *store, const char *file_name) {
158
141
  FileEntry *entry;
159
142
  FrtCompoundStore *cmpd = store->dir.cmpd;
160
143
  FrtInStream *is;
@@ -178,30 +161,26 @@ static FrtInStream *cmpd_open_input(FrtStore *store, const char *file_name)
178
161
  return is;
179
162
  }
180
163
 
181
- static FrtOutStream *cmpd_new_output(FrtStore *store, const char *file_name)
182
- {
164
+ static FrtOutStream *cmpd_new_output(FrtStore *store, const char *file_name) {
183
165
  (void)store;
184
166
  (void)file_name;
185
167
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
186
168
  return NULL;
187
169
  }
188
170
 
189
- static FrtLock *cmpd_open_lock_i(FrtStore *store, const char *lock_name)
190
- {
171
+ static FrtLock *cmpd_open_lock_i(FrtStore *store, const char *lock_name) {
191
172
  (void)store;
192
173
  (void)lock_name;
193
174
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
194
175
  return NULL;
195
176
  }
196
177
 
197
- static void cmpd_close_lock_i(FrtLock *lock)
198
- {
178
+ static void cmpd_close_lock_i(FrtLock *lock) {
199
179
  (void)lock;
200
180
  FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
201
181
  }
202
182
 
203
- FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name)
204
- {
183
+ FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name) {
205
184
  int count, i;
206
185
  off_t offset;
207
186
  char *fname;
@@ -214,6 +193,7 @@ FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name)
214
193
  cmpd = FRT_ALLOC_AND_ZERO(FrtCompoundStore);
215
194
 
216
195
  cmpd->store = store;
196
+ FRT_REF(store);
217
197
  cmpd->name = name;
218
198
  cmpd->entries = frt_h_new_str(&free, &free);
219
199
  is = cmpd->stream = store->open_input(store, cmpd->name);
@@ -235,6 +215,7 @@ FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name)
235
215
  frt_h_set(cmpd->entries, fname, entry);
236
216
  }
237
217
  FRT_XCATCHALL
218
+ frt_store_close(store);
238
219
  if (is) frt_is_close(is);
239
220
  if (cmpd->entries) frt_h_destroy(cmpd->entries);
240
221
  free(cmpd);
@@ -270,18 +251,17 @@ FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name)
270
251
  *
271
252
  ****************************************************************************/
272
253
 
273
- FrtCompoundWriter *frt_open_cw(FrtStore *store, char *name)
274
- {
254
+ FrtCompoundWriter *frt_open_cw(FrtStore *store, char *name) {
275
255
  FrtCompoundWriter *cw = FRT_ALLOC(FrtCompoundWriter);
276
256
  cw->store = store;
257
+ FRT_REF(store);
277
258
  cw->name = name;
278
259
  cw->ids = frt_hs_new_str(&free);
279
260
  cw->file_entries = frt_ary_new_type_capa(FrtCWFileEntry, FRT_CW_INIT_CAPA);
280
261
  return cw;
281
262
  }
282
263
 
283
- void frt_cw_add_file(FrtCompoundWriter *cw, char *id)
284
- {
264
+ void frt_cw_add_file(FrtCompoundWriter *cw, char *id) {
285
265
  id = frt_estrdup(id);
286
266
  if (frt_hs_add(cw->ids, id) != FRT_HASH_KEY_DOES_NOT_EXIST) {
287
267
  FRT_RAISE(FRT_IO_ERROR, "Tried to add file \"%s\" which has already been "
@@ -292,8 +272,7 @@ void frt_cw_add_file(FrtCompoundWriter *cw, char *id)
292
272
  frt_ary_last(cw->file_entries).name = id;
293
273
  }
294
274
 
295
- static void cw_copy_file(FrtCompoundWriter *cw, FrtCWFileEntry *src, FrtOutStream *os)
296
- {
275
+ static void cw_copy_file(FrtCompoundWriter *cw, FrtCWFileEntry *src, FrtOutStream *os) {
297
276
  off_t start_ptr = frt_os_pos(os);
298
277
  off_t end_ptr;
299
278
  off_t remainder, length, len;
@@ -329,8 +308,7 @@ static void cw_copy_file(FrtCompoundWriter *cw, FrtCWFileEntry *src, FrtOutStrea
329
308
  frt_is_close(is);
330
309
  }
331
310
 
332
- void frt_cw_close(FrtCompoundWriter *cw, FrtDeleter *dlr)
333
- {
311
+ void frt_cw_close(FrtCompoundWriter *cw, FrtDeleter *dlr) {
334
312
  FrtOutStream *os = NULL;
335
313
  int i;
336
314
 
@@ -366,12 +344,9 @@ void frt_cw_close(FrtCompoundWriter *cw, FrtDeleter *dlr)
366
344
  frt_os_seek(os, cw->file_entries[i].dir_offset);
367
345
  frt_os_write_u64(os, cw->file_entries[i].data_offset);
368
346
  }
369
-
370
- if (os) {
371
- frt_os_close(os);
372
- }
373
-
347
+ frt_os_close(os);
374
348
  frt_hs_destroy(cw->ids);
375
349
  frt_ary_free(cw->file_entries);
350
+ frt_store_close(cw->store);
376
351
  free(cw);
377
352
  }
@@ -33,6 +33,7 @@ static frt_thread_once_t exception_stack_key_once = FRT_THREAD_ONCE_INIT;
33
33
 
34
34
  static void exception_stack_alloc(void) {
35
35
  frt_thread_key_create(&exception_stack_key, NULL);
36
+ frt_thread_setspecific(exception_stack_key, NULL);
36
37
  }
37
38
 
38
39
  void frt_xpush_context(frt_xcontext_t *context) {
@@ -1,7 +1,7 @@
1
1
  #include <string.h>
2
2
  #include "frt_field_index.h"
3
3
 
4
- #undef close
4
+ // #undef close
5
5
 
6
6
  /***************************************************************************
7
7
  *
@@ -14,9 +14,7 @@ void frt_filt_destroy_i(FrtFilter *filt) {
14
14
  }
15
15
 
16
16
  void frt_filt_deref(FrtFilter *filt) {
17
- if (--(filt->ref_cnt) == 0) {
18
- filt->destroy_i(filt);
19
- }
17
+ if (FRT_DEREF(filt) == 0) filt->destroy_i(filt);
20
18
  }
21
19
 
22
20
  FrtBitVector *frt_filt_get_bv(FrtFilter *filt, FrtIndexReader *ir) {
@@ -97,7 +95,7 @@ static FrtBitVector *qfilt_get_bv_i(FrtFilter *filt, FrtIndexReader *ir) {
97
95
  scorer->destroy(scorer);
98
96
  }
99
97
  weight->destroy(weight);
100
- free(sea);
98
+ frt_searcher_close(sea);
101
99
  return bv;
102
100
  }
103
101
 
@@ -223,7 +223,6 @@ static void fs_destroy(FrtStore *store)
223
223
  FRT_HANDLED();
224
224
  FRT_XENDTRY
225
225
  free(store->dir.path);
226
- frt_store_destroy(store);
227
226
  }
228
227
 
229
228
  static off_t fs_length(FrtStore *store, const char *filename)
@@ -286,7 +285,7 @@ static FrtOutStream *fs_new_output(FrtStore *store, const char *filename)
286
285
 
287
286
  static void fsi_read_i(FrtInStream *is, frt_uchar *path, int len)
288
287
  {
289
- int fd = is->file.fd;
288
+ int fd = is->f->file.fd;
290
289
  off_t pos = frt_is_pos(is);
291
290
  if (pos != lseek(fd, 0, SEEK_CUR)) {
292
291
  lseek(fd, pos, SEEK_SET);
@@ -302,7 +301,7 @@ static void fsi_read_i(FrtInStream *is, frt_uchar *path, int len)
302
301
 
303
302
  static void fsi_seek_i(FrtInStream *is, off_t pos)
304
303
  {
305
- if (lseek(is->file.fd, pos, SEEK_SET) < 0) {
304
+ if (lseek(is->f->file.fd, pos, SEEK_SET) < 0) {
306
305
  FRT_RAISE(FRT_IO_ERROR, "seeking pos %"FRT_OFF_T_PFX"d: <%s>",
307
306
  pos, strerror(errno));
308
307
  }
@@ -310,16 +309,16 @@ static void fsi_seek_i(FrtInStream *is, off_t pos)
310
309
 
311
310
  static void fsi_close_i(FrtInStream *is)
312
311
  {
313
- if (close(is->file.fd)) {
312
+ if (close(is->f->file.fd)) {
314
313
  FRT_RAISE(FRT_IO_ERROR, "%s", strerror(errno));
315
314
  }
316
- free(is->d.path);
315
+ if (is->d.path) free(is->d.path);
317
316
  }
318
317
 
319
318
  static off_t fsi_length_i(FrtInStream *is)
320
319
  {
321
320
  struct stat stt;
322
- if (fstat(is->file.fd, &stt)) {
321
+ if (fstat(is->f->file.fd, &stt)) {
323
322
  FRT_RAISE(FRT_IO_ERROR, "fstat failed: <%s>", strerror(errno));
324
323
  }
325
324
  return stt.st_size;
@@ -343,7 +342,8 @@ static FrtInStream *fs_open_input(FrtStore *store, const char *filename)
343
342
  path, strerror(errno));
344
343
  }
345
344
  is = frt_is_new();
346
- is->file.fd = fd;
345
+ is->f->file.fd = fd;
346
+ is->f->ref_cnt = 1;
347
347
  is->d.path = frt_estrdup(path);
348
348
  is->m = &FS_IN_STREAM_METHODS;
349
349
  return is;
@@ -400,6 +400,7 @@ static FrtLock *fs_open_lock_i(FrtStore *store, const char *lockname)
400
400
  snprintf(lname, 100, "%s%s.lck", FRT_LOCK_PREFIX, lockname);
401
401
  lock->name = frt_estrdup(join_path(path, store->dir.path, lname));
402
402
  lock->store = store;
403
+ FRT_REF(store);
403
404
  lock->obtain = &fs_lock_obtain;
404
405
  lock->release = &fs_lock_release;
405
406
  lock->is_locked = &fs_lock_is_locked;
@@ -409,6 +410,7 @@ static FrtLock *fs_open_lock_i(FrtStore *store, const char *lockname)
409
410
 
410
411
  static void fs_close_lock_i(FrtLock *lock)
411
412
  {
413
+ frt_store_close(lock->store);
412
414
  remove(lock->name);
413
415
  free(lock->name);
414
416
  free(lock);
@@ -486,11 +488,8 @@ FrtStore *frt_open_fs_store(const char *pathname)
486
488
  frt_mutex_lock(&stores_mutex);
487
489
  store = (FrtStore *)frt_h_get(stores, pathname);
488
490
  if (store) {
489
- frt_mutex_lock(&store->mutex);
490
- store->ref_cnt++;
491
- frt_mutex_unlock(&store->mutex);
492
- }
493
- else {
491
+ FRT_REF(store);
492
+ } else {
494
493
  store = fs_store_new(pathname);
495
494
  frt_h_set(stores, store->dir.path, store);
496
495
  }
@@ -116,13 +116,15 @@ char *frt_estrdup(const char *s) {
116
116
  char *frt_dbl_to_s(char *buf, double num) {
117
117
  char *p, *e;
118
118
 
119
- #ifdef FRT_IS_C99
120
119
  if (isinf(num)) {
121
- return frt_estrdup(num < 0 ? "-Infinity" : "Infinity");
120
+ if (num < 0) {
121
+ return strcpy(buf, "-Infinity");
122
+ } else {
123
+ return strcpy(buf, "Infinity");
124
+ }
122
125
  } else if (isnan(num)) {
123
- return frt_estrdup("NaN");
126
+ return strcpy(buf, "NaN");
124
127
  }
125
- #endif
126
128
 
127
129
  sprintf(buf, FRT_DBL2S, num);
128
130
  if (!(e = strchr(buf, 'e'))) {
@@ -13,7 +13,7 @@
13
13
 
14
14
  #define FRT_MAX_WORD_SIZE 255
15
15
  #define FRT_MAX_FILE_PATH 1024
16
- #define FRT_BUFFER_SIZE 1024
16
+ #define FRT_BUFFER_SIZE 16384
17
17
 
18
18
  typedef enum {
19
19
  FRT_COMPRESSION_NONE = 0,
@@ -49,7 +49,7 @@ typedef void (*frt_free_ft)(void *key);
49
49
  #define FRT_ALLOC_AND_ZERO_N(type,n) (type*)frt_ecalloc(sizeof(type)*(n))
50
50
 
51
51
  #define FRT_REF(a) (a)->ref_cnt++
52
- #define FRT_DEREF(a) (a)->ref_cnt--
52
+ #define FRT_DEREF(a) --((a)->ref_cnt)
53
53
 
54
54
  #define FRT_NEXT_NUM(index, size) (((index) + 1) % (size))
55
55
  #define FRT_PREV_NUM(index, size) (((index) + (size) - 1) % (size))
@@ -19,9 +19,9 @@ static const char *dummy_int_key = "i";
19
19
  static FrtHash *free_hts[MAX_FREE_HASH_TABLES];
20
20
  static int num_free_hts = 0;
21
21
 
22
- unsigned long long frt_str_hash(const char *const str)
22
+ unsigned long frt_str_hash(const char *const str)
23
23
  {
24
- register unsigned long long h = 0;
24
+ register unsigned long h = 0;
25
25
  register unsigned char *p = (unsigned char *)str;
26
26
 
27
27
  for (; *p; p++) {
@@ -30,9 +30,9 @@ unsigned long long frt_str_hash(const char *const str)
30
30
  return h;
31
31
  }
32
32
 
33
- unsigned long long frt_ptr_hash(const void *const ptr)
33
+ unsigned long frt_ptr_hash(const void *const ptr)
34
34
  {
35
- return (unsigned long long)ptr;
35
+ return (unsigned long)ptr;
36
36
  }
37
37
 
38
38
  int frt_ptr_eq(const void *q1, const void *q2)
@@ -55,7 +55,7 @@ typedef FrtHashEntry *(*lookup_ft)(struct FrtHash *self, register const void *ke
55
55
  * @param the hashkey we are looking for
56
56
  */
57
57
  static FrtHashEntry *frt_h_resize_lookup(FrtHash *self,
58
- register const unsigned long long hash)
58
+ register const unsigned long hash)
59
59
  {
60
60
  register unsigned long perturb;
61
61
  register int mask = self->mask;
@@ -78,9 +78,8 @@ static FrtHashEntry *frt_h_resize_lookup(FrtHash *self,
78
78
  }
79
79
  }
80
80
 
81
- static FrtHashEntry *frt_h_lookup_ptr(FrtHash *self, const void *key)
82
- {
83
- register const unsigned long long hash = (unsigned long long)key;
81
+ static FrtHashEntry *frt_h_lookup_ptr(FrtHash *self, const void *key) {
82
+ register const unsigned long hash = (unsigned long)key;
84
83
  register unsigned long perturb;
85
84
  register int mask = self->mask;
86
85
  register FrtHashEntry *he0 = self->table;
@@ -88,36 +87,34 @@ static FrtHashEntry *frt_h_lookup_ptr(FrtHash *self, const void *key)
88
87
  register FrtHashEntry *he = &he0[i];
89
88
  register FrtHashEntry *freeslot = NULL;
90
89
 
91
- if (he->key == NULL || he->hash == hash) {
90
+ if (he->key == NULL) {
92
91
  he->hash = hash;
93
92
  return he;
94
93
  }
95
- if (he->key == dummy_key) {
96
- freeslot = he;
97
- }
94
+
95
+ if (he->hash == hash) return he;
96
+
97
+ if (he->key == dummy_key) freeslot = he;
98
98
 
99
99
  for (perturb = hash;; perturb >>= PERTURB_SHIFT) {
100
100
  i = (i << 2) + i + perturb + 1;
101
101
  he = &he0[i & mask];
102
+
102
103
  if (he->key == NULL) {
103
- if (freeslot != NULL) {
104
- he = freeslot;
105
- }
104
+ if (freeslot != NULL) he = freeslot;
106
105
  he->hash = hash;
107
106
  return he;
108
107
  }
109
- if (he->hash == hash) {
110
- return he;
111
- }
112
- if (he->key == dummy_key && freeslot == NULL) {
113
- freeslot = he;
114
- }
108
+
109
+ if (he->hash == hash) return he;
110
+
111
+ if (he->key == dummy_key && freeslot == NULL) freeslot = he;
115
112
  }
113
+ return he;
116
114
  }
117
115
 
118
- FrtHashEntry *frt_h_lookup(FrtHash *self, register const void *key)
119
- {
120
- register const unsigned long long hash = self->hash_i(key);
116
+ FrtHashEntry *frt_h_lookup(FrtHash *self, register const void *key) {
117
+ register const unsigned long hash = self->hash_i(key);
121
118
  register unsigned long perturb;
122
119
  register int mask = self->mask;
123
120
  register FrtHashEntry *he0 = self->table;
@@ -185,7 +182,7 @@ FrtHash *frt_h_new_str(frt_free_ft free_key, frt_free_ft free_value)
185
182
 
186
183
  FrtHash *frt_h_new_int(frt_free_ft free_value)
187
184
  {
188
- FrtHash *self = frt_h_new_str(NULL, free_value);
185
+ FrtHash *self = frt_h_new_str(NULL, free_value);
189
186
 
190
187
  self->lookup_i = &frt_h_lookup_ptr;
191
188
  self->eq_i = NULL;
@@ -196,7 +193,7 @@ FrtHash *frt_h_new_int(frt_free_ft free_value)
196
193
 
197
194
  FrtHash *frt_h_new(frt_hash_ft hash, frt_eq_ft eq, frt_free_ft free_key, frt_free_ft free_value)
198
195
  {
199
- FrtHash *self = frt_h_new_str(free_key, free_value);
196
+ FrtHash *self = frt_h_new_str(free_key, free_value);
200
197
 
201
198
  self->lookup_i = &frt_h_lookup;
202
199
  self->eq_i = eq;
@@ -228,27 +225,24 @@ void frt_h_clear(FrtHash *self)
228
225
  self->fill = 0;
229
226
  }
230
227
 
231
- void frt_h_destroy(FrtHash *self)
232
- {
233
- if (--(self->ref_cnt) <= 0) {
234
- frt_h_clear(self);
228
+ void frt_h_destroy(FrtHash *hash) {
229
+ if (FRT_DEREF(hash) == 0) {
230
+ frt_h_clear(hash);
235
231
 
236
232
  /* if a new table was created, be sure to free it */
237
- if (self->table != self->smalltable) {
238
- free(self->table);
233
+ if (hash->table != hash->smalltable) {
234
+ free(hash->table);
239
235
  }
240
236
 
241
237
  if (num_free_hts < MAX_FREE_HASH_TABLES) {
242
- free_hts[num_free_hts++] = self;
243
- }
244
- else {
245
- free(self);
238
+ free_hts[num_free_hts++] = hash;
239
+ } else {
240
+ free(hash);
246
241
  }
247
242
  }
248
243
  }
249
244
 
250
- void *frt_h_get(FrtHash *self, const void *key)
251
- {
245
+ void *frt_h_get(FrtHash *self, const void *key) {
252
246
  /* Note: lookup_i will never return NULL. */
253
247
  return self->lookup_i(self, key)->value;
254
248
  }
@@ -270,8 +264,7 @@ int frt_h_del(FrtHash *self, const void *key)
270
264
  }
271
265
  }
272
266
 
273
- void *frt_h_rem(FrtHash *self, const void *key, bool destroy_key)
274
- {
267
+ void *frt_h_rem(FrtHash *self, const void *key, bool destroy_key) {
275
268
  void *val;
276
269
  FrtHashEntry *he = self->lookup_i(self, key);
277
270
 
@@ -285,8 +278,7 @@ void *frt_h_rem(FrtHash *self, const void *key, bool destroy_key)
285
278
  he->value = NULL;
286
279
  self->size--;
287
280
  return val;
288
- }
289
- else {
281
+ } else {
290
282
  return NULL;
291
283
  }
292
284
  }
@@ -405,23 +397,23 @@ FrtHashKeyStatus frt_h_has_key(FrtHash *self, const void *key)
405
397
  return FRT_HASH_KEY_EQUAL;
406
398
  }
407
399
 
408
- void *frt_h_get_int(FrtHash *self, const unsigned long long key)
400
+ void *frt_h_get_int(FrtHash *self, const unsigned long key)
409
401
  {
410
402
  return frt_h_get(self, (const void *)key);
411
403
  }
412
404
 
413
- int frt_h_del_int(FrtHash *self, const unsigned long long key)
405
+ int frt_h_del_int(FrtHash *self, const unsigned long key)
414
406
  {
415
407
  return frt_h_del(self, (const void *)key);
416
408
  }
417
409
 
418
- void *frt_h_rem_int(FrtHash *self, const unsigned long long key)
410
+ void *frt_h_rem_int(FrtHash *self, const unsigned long key)
419
411
  {
420
412
  return frt_h_rem(self, (const void *)key, false);
421
413
  }
422
414
 
423
415
  FrtHashKeyStatus frt_h_set_int(FrtHash *self,
424
- const unsigned long long key,
416
+ const unsigned long key,
425
417
  void *value)
426
418
  {
427
419
  FrtHashKeyStatus ret_val = FRT_HASH_KEY_DOES_NOT_EXIST;
@@ -439,7 +431,7 @@ FrtHashKeyStatus frt_h_set_int(FrtHash *self,
439
431
  return ret_val;
440
432
  }
441
433
 
442
- int frt_h_set_safe_int(FrtHash *self, const unsigned long long key, void *value)
434
+ int frt_h_set_safe_int(FrtHash *self, const unsigned long key, void *value)
443
435
  {
444
436
  FrtHashEntry *he;
445
437
  if (frt_h_set_ext(self, (const void *)key, &he)) {
@@ -450,7 +442,7 @@ int frt_h_set_safe_int(FrtHash *self, const unsigned long long key, void *value)
450
442
  return false;
451
443
  }
452
444
 
453
- int frt_h_has_key_int(FrtHash *self, const unsigned long long key)
445
+ int frt_h_has_key_int(FrtHash *self, const unsigned long key)
454
446
  {
455
447
  return frt_h_has_key(self, (const void *)key);
456
448
  }