isomorfeus-ferret 0.17.2 → 0.17.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/isomorfeus_ferret_ext/benchmark.c +9 -20
- data/ext/isomorfeus_ferret_ext/benchmarks_all.h +1 -2
- data/ext/isomorfeus_ferret_ext/bm_hash.c +1 -2
- data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +4 -2
- data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +3 -2
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +4 -5
- data/ext/isomorfeus_ferret_ext/frb_field_info.c +3 -4
- data/ext/isomorfeus_ferret_ext/frb_index.c +161 -187
- data/ext/isomorfeus_ferret_ext/frb_lazy_doc.c +14 -16
- data/ext/isomorfeus_ferret_ext/frb_search.c +77 -69
- data/ext/isomorfeus_ferret_ext/frb_store.c +27 -13
- data/ext/isomorfeus_ferret_ext/frb_utils.c +3 -6
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +39 -46
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +9 -9
- data/ext/isomorfeus_ferret_ext/frt_array.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +3 -6
- data/ext/isomorfeus_ferret_ext/frt_doc_field.c +87 -0
- data/ext/isomorfeus_ferret_ext/frt_doc_field.h +26 -0
- data/ext/isomorfeus_ferret_ext/frt_document.c +4 -97
- data/ext/isomorfeus_ferret_ext/frt_document.h +5 -33
- data/ext/isomorfeus_ferret_ext/frt_except.c +8 -6
- data/ext/isomorfeus_ferret_ext/frt_except.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +14 -33
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +0 -6
- data/ext/isomorfeus_ferret_ext/frt_field_info.c +69 -0
- data/ext/isomorfeus_ferret_ext/frt_field_info.h +49 -0
- data/ext/isomorfeus_ferret_ext/frt_field_infos.c +196 -0
- data/ext/isomorfeus_ferret_ext/frt_field_infos.h +35 -0
- data/ext/isomorfeus_ferret_ext/frt_filter.c +2 -2
- data/ext/isomorfeus_ferret_ext/frt_global.c +10 -4
- data/ext/isomorfeus_ferret_ext/frt_global.h +11 -15
- data/ext/isomorfeus_ferret_ext/frt_hash.c +8 -8
- data/ext/isomorfeus_ferret_ext/frt_hash.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_hashset.c +20 -40
- data/ext/isomorfeus_ferret_ext/frt_hashset.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_helper.c +7 -15
- data/ext/isomorfeus_ferret_ext/frt_in_stream.c +35 -45
- data/ext/isomorfeus_ferret_ext/frt_in_stream.h +3 -2
- data/ext/isomorfeus_ferret_ext/frt_ind.c +21 -39
- data/ext/isomorfeus_ferret_ext/frt_ind.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_index.c +334 -848
- data/ext/isomorfeus_ferret_ext/frt_index.h +4 -105
- data/ext/isomorfeus_ferret_ext/frt_lang.c +5 -10
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc.c +3 -3
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.c +18 -25
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.h +5 -5
- data/ext/isomorfeus_ferret_ext/frt_mdbx_store.c +102 -70
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +23 -46
- data/ext/isomorfeus_ferret_ext/frt_multimapper.h +4 -8
- data/ext/isomorfeus_ferret_ext/frt_out_stream.c +31 -43
- data/ext/isomorfeus_ferret_ext/frt_out_stream.h +2 -2
- data/ext/isomorfeus_ferret_ext/frt_posh.c +6 -819
- data/ext/isomorfeus_ferret_ext/frt_posh.h +0 -57
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +131 -217
- data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +2 -2
- data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +4 -4
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +18 -26
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +27 -28
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +49 -98
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +64 -116
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +8 -14
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +251 -365
- data/ext/isomorfeus_ferret_ext/frt_q_term.c +9 -9
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +134 -85
- data/ext/isomorfeus_ferret_ext/frt_search.c +109 -191
- data/ext/isomorfeus_ferret_ext/frt_search.h +6 -6
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +12 -23
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_sort.c +20 -20
- data/ext/isomorfeus_ferret_ext/frt_store.c +13 -25
- data/ext/isomorfeus_ferret_ext/frt_store.h +86 -52
- data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_win32.h +5 -10
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +12 -11
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +11 -13
- data/ext/isomorfeus_ferret_ext/lz4.c +422 -195
- data/ext/isomorfeus_ferret_ext/lz4.h +114 -46
- data/ext/isomorfeus_ferret_ext/lz4frame.c +421 -242
- data/ext/isomorfeus_ferret_ext/lz4frame.h +122 -53
- data/ext/isomorfeus_ferret_ext/lz4hc.c +127 -111
- data/ext/isomorfeus_ferret_ext/lz4hc.h +14 -14
- data/ext/isomorfeus_ferret_ext/lz4xxhash.h +1 -1
- data/ext/isomorfeus_ferret_ext/mdbx.c +3762 -2526
- data/ext/isomorfeus_ferret_ext/mdbx.h +115 -70
- data/ext/isomorfeus_ferret_ext/test.c +41 -88
- data/ext/isomorfeus_ferret_ext/test.h +3 -6
- data/ext/isomorfeus_ferret_ext/test_1710.c +11 -13
- data/ext/isomorfeus_ferret_ext/test_analysis.c +32 -64
- data/ext/isomorfeus_ferret_ext/test_array.c +6 -12
- data/ext/isomorfeus_ferret_ext/test_bitvector.c +12 -24
- data/ext/isomorfeus_ferret_ext/test_document.c +23 -33
- data/ext/isomorfeus_ferret_ext/test_except.c +10 -21
- data/ext/isomorfeus_ferret_ext/test_fields.c +62 -68
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +16 -25
- data/ext/isomorfeus_ferret_ext/test_filter.c +22 -33
- data/ext/isomorfeus_ferret_ext/test_global.c +14 -29
- data/ext/isomorfeus_ferret_ext/test_hash.c +19 -38
- data/ext/isomorfeus_ferret_ext/test_hashset.c +8 -16
- data/ext/isomorfeus_ferret_ext/test_helper.c +4 -8
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +16 -28
- data/ext/isomorfeus_ferret_ext/test_index.c +307 -519
- data/ext/isomorfeus_ferret_ext/test_lang.c +7 -14
- data/ext/isomorfeus_ferret_ext/test_mdbx_store.c +2 -5
- data/ext/isomorfeus_ferret_ext/test_mempool.c +5 -10
- data/ext/isomorfeus_ferret_ext/test_multimapper.c +3 -6
- data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +9 -18
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +4 -6
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +3 -4
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +9 -15
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +8 -16
- data/ext/isomorfeus_ferret_ext/test_q_span.c +19 -35
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +14 -13
- data/ext/isomorfeus_ferret_ext/test_search.c +66 -115
- data/ext/isomorfeus_ferret_ext/test_segments.c +8 -13
- data/ext/isomorfeus_ferret_ext/test_similarity.c +2 -4
- data/ext/isomorfeus_ferret_ext/test_sort.c +17 -27
- data/ext/isomorfeus_ferret_ext/test_store.c +96 -115
- data/ext/isomorfeus_ferret_ext/test_term.c +9 -15
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -14
- data/ext/isomorfeus_ferret_ext/test_test.c +4 -8
- data/ext/isomorfeus_ferret_ext/test_threading.c +15 -21
- data/ext/isomorfeus_ferret_ext/testhelper.c +11 -21
- data/ext/isomorfeus_ferret_ext/testhelper.h +1 -1
- data/ext/isomorfeus_ferret_ext/tests_all.h +1 -2
- data/lib/isomorfeus/ferret/index/index.rb +8 -8
- data/lib/isomorfeus/ferret/version.rb +1 -1
- metadata +32 -6
@@ -0,0 +1,35 @@
|
|
1
|
+
#ifndef FRT_FIELD_INFOS_H
|
2
|
+
#define FRT_FIELD_INFOS_H
|
3
|
+
|
4
|
+
#include "frt_field_info.h"
|
5
|
+
#include "frt_hash.h"
|
6
|
+
#include "frt_in_stream.h"
|
7
|
+
#include "frt_out_stream.h"
|
8
|
+
|
9
|
+
#define FIELD_INFOS_INIT_CAPA 4
|
10
|
+
|
11
|
+
/* carry changes over to dummy_fis in test/test_segments.c */
|
12
|
+
typedef struct FrtFieldInfos {
|
13
|
+
unsigned int bits;
|
14
|
+
int size;
|
15
|
+
int capa;
|
16
|
+
FrtFieldInfo **fields;
|
17
|
+
FrtHash *field_dict;
|
18
|
+
_Atomic unsigned int ref_cnt;
|
19
|
+
VALUE rfis;
|
20
|
+
} FrtFieldInfos;
|
21
|
+
|
22
|
+
FrtFieldInfos *frt_fis_alloc();
|
23
|
+
FrtFieldInfos *frt_fis_init(FrtFieldInfos *fis, unsigned int bits);
|
24
|
+
FrtFieldInfos *frt_fis_new(unsigned int bits);
|
25
|
+
extern FrtFieldInfo *frt_fis_add_field(FrtFieldInfos *fis, FrtFieldInfo *fi);
|
26
|
+
extern FrtFieldInfo *frt_fis_get_field(FrtFieldInfos *fis, ID name);
|
27
|
+
extern int frt_fis_get_field_num(FrtFieldInfos *fis, ID name);
|
28
|
+
extern FrtFieldInfo *frt_fis_get_or_add_field(FrtFieldInfos *fis, ID name);
|
29
|
+
extern bool frt_fis_has_vectors(FrtFieldInfos *fis);
|
30
|
+
extern void frt_fis_write(FrtFieldInfos *fis, FrtOutStream *os);
|
31
|
+
extern FrtFieldInfos *frt_fis_read(FrtInStream *is);
|
32
|
+
extern char *frt_fis_to_s(FrtFieldInfos *fis);
|
33
|
+
extern void frt_fis_deref(FrtFieldInfos *fis);
|
34
|
+
|
35
|
+
#endif
|
@@ -84,13 +84,13 @@ static char *qfilt_to_s(FrtFilter *filt) {
|
|
84
84
|
}
|
85
85
|
|
86
86
|
static FrtBitVector *qfilt_get_bv_i(FrtFilter *filt, FrtIndexReader *ir) {
|
87
|
-
FrtBitVector *bv = frt_bv_new_capa(ir->
|
87
|
+
FrtBitVector *bv = frt_bv_new_capa(ir->max_doc_num(ir));
|
88
88
|
FrtSearcher *sea = frt_isea_new(ir);
|
89
89
|
FrtWeight *weight = frt_q_weight(QF(filt)->query, sea);
|
90
90
|
FrtScorer *scorer = weight->scorer(weight, ir);
|
91
91
|
if (scorer) {
|
92
92
|
while (scorer->next(scorer)) {
|
93
|
-
frt_bv_set(bv, scorer->
|
93
|
+
frt_bv_set(bv, scorer->doc_num);
|
94
94
|
}
|
95
95
|
scorer->destroy(scorer);
|
96
96
|
}
|
@@ -44,8 +44,7 @@ int frt_icmp(const void *p1, const void *p2) {
|
|
44
44
|
|
45
45
|
if (i1 > i2) {
|
46
46
|
return 1;
|
47
|
-
}
|
48
|
-
else if (i1 < i2) {
|
47
|
+
} else if (i1 < i2) {
|
49
48
|
return -1;
|
50
49
|
}
|
51
50
|
return 0;
|
@@ -110,6 +109,14 @@ char *frt_estrdup(const char *s) {
|
|
110
109
|
return t;
|
111
110
|
}
|
112
111
|
|
112
|
+
/* frt_estrndup: duplicate a string with length given, report if error */
|
113
|
+
char *frt_estrndup(const char *s, int len) {
|
114
|
+
char *t = FRT_ALLOC_N(char, len + 1);
|
115
|
+
strncpy(t, s, len);
|
116
|
+
t[len] = '\0';
|
117
|
+
return t;
|
118
|
+
}
|
119
|
+
|
113
120
|
/* Pretty print a float to the buffer. The buffer should have at least 32
|
114
121
|
* bytes available.
|
115
122
|
*/
|
@@ -248,8 +255,7 @@ void frt_register_for_cleanup(void *p, frt_free_ft free_func) {
|
|
248
255
|
if (free_mes_capa == 0) {
|
249
256
|
free_mes_capa = 16;
|
250
257
|
free_mes = FRT_ALLOC_N(FreeMe, free_mes_capa);
|
251
|
-
}
|
252
|
-
else if (free_mes_capa <= free_mes_size) {
|
258
|
+
} else if (free_mes_capa <= free_mes_size) {
|
253
259
|
free_mes_capa *= 2;
|
254
260
|
FRT_REALLOC_N(free_mes, FreeMe, free_mes_capa);
|
255
261
|
}
|
@@ -83,12 +83,15 @@ typedef void (*frt_free_ft)(void *key);
|
|
83
83
|
# define Xj fprintf(stdout,"%s, %d: %s\n", __FILE__, __LINE__, __func__);
|
84
84
|
#endif
|
85
85
|
|
86
|
+
extern const char *segm_idx_name;
|
87
|
+
|
86
88
|
extern unsigned int *frt_imalloc(unsigned int value);
|
87
89
|
extern unsigned long *frt_lmalloc(unsigned long value);
|
88
90
|
extern frt_u32 *frt_u32malloc(frt_u32 value);
|
89
91
|
extern frt_u64 *frt_u64malloc(frt_u64 value);
|
90
92
|
|
91
93
|
extern char *frt_estrdup(const char *s);
|
94
|
+
extern char *frt_estrndup(const char *s, int len);
|
92
95
|
extern char *frt_estrcat(char *str, char *str_cat);
|
93
96
|
extern char *frt_epstrdup(const char *fmt, int len, ...);
|
94
97
|
|
@@ -120,8 +123,7 @@ extern void frt_dummy_free(void *p);
|
|
120
123
|
* Returns the count of leading [MSB] 0 bits in +word+.
|
121
124
|
*/
|
122
125
|
static FRT_ATTR_ALWAYS_INLINE FRT_ATTR_CONST
|
123
|
-
int frt_count_leading_zeros(frt_u32 word)
|
124
|
-
{
|
126
|
+
int frt_count_leading_zeros(frt_u32 word) {
|
125
127
|
#ifdef __GNUC__
|
126
128
|
if (word)
|
127
129
|
return __builtin_clz(word);
|
@@ -153,8 +155,7 @@ int frt_count_leading_zeros(frt_u32 word)
|
|
153
155
|
}
|
154
156
|
|
155
157
|
static FRT_ATTR_ALWAYS_INLINE FRT_ATTR_CONST
|
156
|
-
int frt_count_leading_ones(frt_u32 word)
|
157
|
-
{
|
158
|
+
int frt_count_leading_ones(frt_u32 word) {
|
158
159
|
return frt_count_leading_zeros(~word);
|
159
160
|
}
|
160
161
|
|
@@ -163,8 +164,7 @@ int frt_count_leading_ones(frt_u32 word)
|
|
163
164
|
*/
|
164
165
|
|
165
166
|
static FRT_ATTR_ALWAYS_INLINE FRT_ATTR_CONST
|
166
|
-
int frt_count_trailing_zeros(frt_u32 word)
|
167
|
-
{
|
167
|
+
int frt_count_trailing_zeros(frt_u32 word) {
|
168
168
|
#ifdef __GNUC__
|
169
169
|
if (word)
|
170
170
|
return __builtin_ctz(word);
|
@@ -196,14 +196,12 @@ int frt_count_trailing_zeros(frt_u32 word)
|
|
196
196
|
}
|
197
197
|
|
198
198
|
static FRT_ATTR_ALWAYS_INLINE FRT_ATTR_CONST
|
199
|
-
int frt_count_trailing_ones(frt_u32 word)
|
200
|
-
{
|
199
|
+
int frt_count_trailing_ones(frt_u32 word) {
|
201
200
|
return frt_count_trailing_zeros(~word);
|
202
201
|
}
|
203
202
|
|
204
203
|
static FRT_ATTR_ALWAYS_INLINE FRT_ATTR_CONST
|
205
|
-
int frt_count_ones(frt_u32 word)
|
206
|
-
{
|
204
|
+
int frt_count_ones(frt_u32 word) {
|
207
205
|
#ifdef __GNUC__
|
208
206
|
return __builtin_popcount(word);
|
209
207
|
#else
|
@@ -233,8 +231,7 @@ int frt_count_ones(frt_u32 word)
|
|
233
231
|
}
|
234
232
|
|
235
233
|
static FRT_ATTR_ALWAYS_INLINE FRT_ATTR_CONST
|
236
|
-
int frt_count_zeros(frt_u32 word)
|
237
|
-
{
|
234
|
+
int frt_count_zeros(frt_u32 word) {
|
238
235
|
return frt_count_ones(~word);
|
239
236
|
}
|
240
237
|
|
@@ -242,8 +239,7 @@ int frt_count_zeros(frt_u32 word)
|
|
242
239
|
* Round up to the next power of 2
|
243
240
|
*/
|
244
241
|
static FRT_ATTR_ALWAYS_INLINE FRT_ATTR_CONST
|
245
|
-
int frt_round2(frt_u32 word)
|
246
|
-
{
|
242
|
+
int frt_round2(frt_u32 word) {
|
247
243
|
return 1 << (32 - frt_count_leading_zeros(word));
|
248
244
|
}
|
249
245
|
|
@@ -261,7 +257,7 @@ extern FILE *frt_x_exception_stream;
|
|
261
257
|
|
262
258
|
/**
|
263
259
|
* The convenience macro +EXCEPTION_STREAM+ returns stderr when
|
264
|
-
* +frt_x_exception_stream+ isn't
|
260
|
+
* +frt_x_exception_stream+ isn't explicitly set.
|
265
261
|
*/
|
266
262
|
#define EXCEPTION 2
|
267
263
|
#define EXCEPTION_STREAM (frt_x_exception_stream ? frt_x_exception_stream : stderr)
|
@@ -30,7 +30,7 @@ unsigned long frt_str_hash(const char *const str) {
|
|
30
30
|
}
|
31
31
|
|
32
32
|
unsigned long frt_ptr_hash(const void *const ptr) {
|
33
|
-
return (unsigned long)ptr;
|
33
|
+
return (unsigned long)(uintptr_t)ptr;
|
34
34
|
}
|
35
35
|
|
36
36
|
int frt_ptr_eq(const void *q1, const void *q2) {
|
@@ -73,7 +73,7 @@ static FrtHashEntry *frt_h_resize_lookup(FrtHash *self, register const unsigned
|
|
73
73
|
}
|
74
74
|
|
75
75
|
static FrtHashEntry *frt_h_lookup_ptr(FrtHash *self, const void *key) {
|
76
|
-
register const unsigned long hash = (unsigned long)key;
|
76
|
+
register const unsigned long hash = (unsigned long)(uintptr_t)key;
|
77
77
|
register unsigned long perturb;
|
78
78
|
register int mask = self->mask;
|
79
79
|
register FrtHashEntry *he0 = self->table;
|
@@ -375,21 +375,21 @@ FrtHashKeyStatus frt_h_has_key(FrtHash *self, const void *key) {
|
|
375
375
|
}
|
376
376
|
|
377
377
|
void *frt_h_get_int(FrtHash *self, const unsigned long key) {
|
378
|
-
return frt_h_get(self, (const void *)key);
|
378
|
+
return frt_h_get(self, (const void *)(uintptr_t)key);
|
379
379
|
}
|
380
380
|
|
381
381
|
int frt_h_del_int(FrtHash *self, const unsigned long key) {
|
382
|
-
return frt_h_del(self, (const void *)key);
|
382
|
+
return frt_h_del(self, (const void *)(uintptr_t)key);
|
383
383
|
}
|
384
384
|
|
385
385
|
void *frt_h_rem_int(FrtHash *self, const unsigned long key) {
|
386
|
-
return frt_h_rem(self, (const void *)key, false);
|
386
|
+
return frt_h_rem(self, (const void *)(uintptr_t)key, false);
|
387
387
|
}
|
388
388
|
|
389
389
|
FrtHashKeyStatus frt_h_set_int(FrtHash *self, const unsigned long key, void *value) {
|
390
390
|
FrtHashKeyStatus ret_val = FRT_HASH_KEY_DOES_NOT_EXIST;
|
391
391
|
FrtHashEntry *he;
|
392
|
-
if (!frt_h_set_ext(self, (const void *)key, &he)) {
|
392
|
+
if (!frt_h_set_ext(self, (const void *)(uintptr_t)key, &he)) {
|
393
393
|
/* Only free old value if it isn't the new value */
|
394
394
|
if (he->value != value) {
|
395
395
|
self->free_value_i(he->value);
|
@@ -404,7 +404,7 @@ FrtHashKeyStatus frt_h_set_int(FrtHash *self, const unsigned long key, void *val
|
|
404
404
|
|
405
405
|
int frt_h_set_safe_int(FrtHash *self, const unsigned long key, void *value) {
|
406
406
|
FrtHashEntry *he;
|
407
|
-
if (frt_h_set_ext(self, (const void *)key, &he)) {
|
407
|
+
if (frt_h_set_ext(self, (const void *)(uintptr_t)key, &he)) {
|
408
408
|
he->key = (char *)dummy_int_key;
|
409
409
|
he->value = value;
|
410
410
|
return true;
|
@@ -413,7 +413,7 @@ int frt_h_set_safe_int(FrtHash *self, const unsigned long key, void *value) {
|
|
413
413
|
}
|
414
414
|
|
415
415
|
int frt_h_has_key_int(FrtHash *self, const unsigned long key) {
|
416
|
-
return frt_h_has_key(self, (const void *)key);
|
416
|
+
return frt_h_has_key(self, (const void *)(uintptr_t)key);
|
417
417
|
}
|
418
418
|
|
419
419
|
void frt_h_each(FrtHash *self, void (*each_kv) (void *key, void *value, void *arg), void *arg) {
|
@@ -7,8 +7,7 @@
|
|
7
7
|
* over all alements in the HashSet. It also uses a Hash to keep track of
|
8
8
|
* which elements have been added and their index in the +elems+ array.
|
9
9
|
*/
|
10
|
-
static FrtHashSet *hs_alloc(frt_free_ft free_func)
|
11
|
-
{
|
10
|
+
static FrtHashSet *hs_alloc(frt_free_ft free_func) {
|
12
11
|
FrtHashSet *hs = FRT_ALLOC(FrtHashSet);
|
13
12
|
hs->size = 0;
|
14
13
|
hs->first = hs->last = NULL;
|
@@ -16,29 +15,25 @@ static FrtHashSet *hs_alloc(frt_free_ft free_func)
|
|
16
15
|
return hs;
|
17
16
|
}
|
18
17
|
|
19
|
-
FrtHashSet *frt_hs_new(frt_hash_ft hash_func, frt_eq_ft eq_func, frt_free_ft free_func)
|
20
|
-
{
|
18
|
+
FrtHashSet *frt_hs_new(frt_hash_ft hash_func, frt_eq_ft eq_func, frt_free_ft free_func) {
|
21
19
|
FrtHashSet *hs = hs_alloc(free_func);
|
22
20
|
hs->ht = frt_h_new(hash_func, eq_func, NULL, NULL);
|
23
21
|
return hs;
|
24
22
|
}
|
25
23
|
|
26
|
-
FrtHashSet *frt_hs_new_str(frt_free_ft free_func)
|
27
|
-
{
|
24
|
+
FrtHashSet *frt_hs_new_str(frt_free_ft free_func) {
|
28
25
|
FrtHashSet *hs = hs_alloc(free_func);
|
29
26
|
hs->ht = frt_h_new_str((frt_free_ft) NULL, NULL);
|
30
27
|
return hs;
|
31
28
|
}
|
32
29
|
|
33
|
-
FrtHashSet *frt_hs_new_ptr(frt_free_ft free_func)
|
34
|
-
{
|
30
|
+
FrtHashSet *frt_hs_new_ptr(frt_free_ft free_func) {
|
35
31
|
FrtHashSet *hs = hs_alloc(free_func);
|
36
32
|
hs->ht = frt_h_new_ptr(NULL);
|
37
33
|
return hs;
|
38
34
|
}
|
39
35
|
|
40
|
-
static void hs_clear(FrtHashSet *hs, bool destroy)
|
41
|
-
{
|
36
|
+
static void hs_clear(FrtHashSet *hs, bool destroy) {
|
42
37
|
FrtHashSetEntry *curr, *next = hs->first;
|
43
38
|
frt_free_ft do_free = destroy ? hs->free_elem_i : &frt_dummy_free;
|
44
39
|
while (NULL != (curr = next)) {
|
@@ -50,36 +45,31 @@ static void hs_clear(FrtHashSet *hs, bool destroy)
|
|
50
45
|
hs->size = 0;
|
51
46
|
}
|
52
47
|
|
53
|
-
void frt_hs_clear(FrtHashSet *hs)
|
54
|
-
{
|
48
|
+
void frt_hs_clear(FrtHashSet *hs) {
|
55
49
|
hs_clear(hs, true);
|
56
50
|
frt_h_clear(hs->ht);
|
57
51
|
}
|
58
52
|
|
59
|
-
void frt_hs_free(FrtHashSet *hs)
|
60
|
-
{
|
53
|
+
void frt_hs_free(FrtHashSet *hs) {
|
61
54
|
hs_clear(hs, false);
|
62
55
|
frt_h_destroy(hs->ht);
|
63
56
|
free(hs);
|
64
57
|
}
|
65
58
|
|
66
|
-
void frt_hs_destroy(FrtHashSet *hs)
|
67
|
-
{
|
59
|
+
void frt_hs_destroy(FrtHashSet *hs) {
|
68
60
|
hs_clear(hs, true);
|
69
61
|
frt_h_destroy(hs->ht);
|
70
62
|
free(hs);
|
71
63
|
}
|
72
64
|
|
73
|
-
static void append(FrtHashSet *hs, void *elem)
|
74
|
-
{
|
65
|
+
static void append(FrtHashSet *hs, void *elem) {
|
75
66
|
FrtHashSetEntry *entry = FRT_ALLOC(FrtHashSetEntry);
|
76
67
|
entry->elem = elem;
|
77
68
|
entry->prev = hs->last;
|
78
69
|
entry->next = NULL;
|
79
70
|
if (!hs->first) {
|
80
71
|
hs->first = hs->last = entry;
|
81
|
-
}
|
82
|
-
else {
|
72
|
+
} else {
|
83
73
|
hs->last->next = entry;
|
84
74
|
hs->last = entry;
|
85
75
|
}
|
@@ -87,8 +77,7 @@ static void append(FrtHashSet *hs, void *elem)
|
|
87
77
|
hs->size++;
|
88
78
|
}
|
89
79
|
|
90
|
-
FrtHashKeyStatus frt_hs_add(FrtHashSet *hs, void *elem)
|
91
|
-
{
|
80
|
+
FrtHashKeyStatus frt_hs_add(FrtHashSet *hs, void *elem) {
|
92
81
|
FrtHashKeyStatus has_elem = frt_h_has_key(hs->ht, elem);
|
93
82
|
switch (has_elem)
|
94
83
|
{
|
@@ -111,8 +100,7 @@ FrtHashKeyStatus frt_hs_add(FrtHashSet *hs, void *elem)
|
|
111
100
|
return has_elem;
|
112
101
|
}
|
113
102
|
|
114
|
-
int frt_hs_add_safe(FrtHashSet *hs, void *elem)
|
115
|
-
{
|
103
|
+
int frt_hs_add_safe(FrtHashSet *hs, void *elem) {
|
116
104
|
switch(frt_h_has_key(hs->ht, elem))
|
117
105
|
{
|
118
106
|
/* element can't be added */
|
@@ -128,24 +116,20 @@ int frt_hs_add_safe(FrtHashSet *hs, void *elem)
|
|
128
116
|
return true;
|
129
117
|
}
|
130
118
|
|
131
|
-
void *frt_hs_rem(FrtHashSet *hs, const void *elem)
|
132
|
-
{
|
119
|
+
void *frt_hs_rem(FrtHashSet *hs, const void *elem) {
|
133
120
|
void *return_elem;
|
134
121
|
FrtHashSetEntry *entry = (FrtHashSetEntry *)frt_h_get(hs->ht, elem);
|
135
122
|
if (entry == NULL) return NULL;
|
136
123
|
|
137
124
|
if (hs->first == hs->last) {
|
138
125
|
hs->first = hs->last = NULL;
|
139
|
-
}
|
140
|
-
else if (hs->first == entry) {
|
126
|
+
} else if (hs->first == entry) {
|
141
127
|
hs->first = entry->next;
|
142
128
|
hs->first->prev = NULL;
|
143
|
-
}
|
144
|
-
else if (hs->last == entry) {
|
129
|
+
} else if (hs->last == entry) {
|
145
130
|
hs->last = entry->prev;
|
146
131
|
hs->last->next = NULL;
|
147
|
-
}
|
148
|
-
else {
|
132
|
+
} else {
|
149
133
|
entry->prev->next = entry->next;
|
150
134
|
entry->next->prev = entry->prev;
|
151
135
|
}
|
@@ -156,8 +140,7 @@ void *frt_hs_rem(FrtHashSet *hs, const void *elem)
|
|
156
140
|
return return_elem;
|
157
141
|
}
|
158
142
|
|
159
|
-
int frt_hs_del(FrtHashSet *hs, const void *elem)
|
160
|
-
{
|
143
|
+
int frt_hs_del(FrtHashSet *hs, const void *elem) {
|
161
144
|
void *tmp_elem = frt_hs_rem(hs, elem);
|
162
145
|
if (tmp_elem != NULL) {
|
163
146
|
hs->free_elem_i(tmp_elem);
|
@@ -166,13 +149,11 @@ int frt_hs_del(FrtHashSet *hs, const void *elem)
|
|
166
149
|
return 0;
|
167
150
|
}
|
168
151
|
|
169
|
-
FrtHashKeyStatus frt_hs_exists(FrtHashSet *hs, const void *elem)
|
170
|
-
{
|
152
|
+
FrtHashKeyStatus frt_hs_exists(FrtHashSet *hs, const void *elem) {
|
171
153
|
return frt_h_has_key(hs->ht, elem);
|
172
154
|
}
|
173
155
|
|
174
|
-
FrtHashSet *frt_hs_merge(FrtHashSet *hs, FrtHashSet * other)
|
175
|
-
{
|
156
|
+
FrtHashSet *frt_hs_merge(FrtHashSet *hs, FrtHashSet * other) {
|
176
157
|
FrtHashSetEntry *entry = other->first;
|
177
158
|
for (; entry != NULL; entry = entry->next) {
|
178
159
|
frt_hs_add(hs, entry->elem);
|
@@ -184,8 +165,7 @@ FrtHashSet *frt_hs_merge(FrtHashSet *hs, FrtHashSet * other)
|
|
184
165
|
return hs;
|
185
166
|
}
|
186
167
|
|
187
|
-
void *frt_hs_orig(FrtHashSet *hs, const void *elem)
|
188
|
-
{
|
168
|
+
void *frt_hs_orig(FrtHashSet *hs, const void *elem) {
|
189
169
|
FrtHashSetEntry *entry = (FrtHashSetEntry *)frt_h_get(hs->ht, elem);
|
190
170
|
return entry ? entry->elem : NULL;
|
191
171
|
}
|
@@ -1,8 +1,6 @@
|
|
1
1
|
#include "frt_helper.h"
|
2
2
|
|
3
|
-
int frt_hlp_string_diff(register const char *const s1,
|
4
|
-
register const char *const s2)
|
5
|
-
{
|
3
|
+
int frt_hlp_string_diff(register const char *const s1, register const char *const s2) {
|
6
4
|
register int i = 0;
|
7
5
|
while (s1[i] && (s1[i] == s2[i])) {
|
8
6
|
i++;
|
@@ -10,26 +8,22 @@ int frt_hlp_string_diff(register const char *const s1,
|
|
10
8
|
return i;
|
11
9
|
}
|
12
10
|
|
13
|
-
frt_i32 frt_float2int(float f)
|
14
|
-
{
|
11
|
+
frt_i32 frt_float2int(float f) {
|
15
12
|
union { frt_i32 i; float f; } tmp;
|
16
13
|
tmp.f = f;
|
17
14
|
return tmp.i;
|
18
15
|
}
|
19
16
|
|
20
|
-
float frt_int2float(frt_i32 v)
|
21
|
-
{
|
17
|
+
float frt_int2float(frt_i32 v) {
|
22
18
|
union { frt_i32 i; float f; } tmp;
|
23
19
|
tmp.i = v;
|
24
20
|
return tmp.f;
|
25
21
|
}
|
26
22
|
|
27
|
-
float frt_byte2float(unsigned char b)
|
28
|
-
{
|
23
|
+
float frt_byte2float(unsigned char b) {
|
29
24
|
if (b == 0) {
|
30
25
|
return 0.0;
|
31
|
-
}
|
32
|
-
else {
|
26
|
+
} else {
|
33
27
|
frt_u32 mantissa = b & 0x07;
|
34
28
|
frt_u32 exponent = (b >> 3) & 0x1f;
|
35
29
|
|
@@ -37,12 +31,10 @@ float frt_byte2float(unsigned char b)
|
|
37
31
|
}
|
38
32
|
}
|
39
33
|
|
40
|
-
unsigned char frt_float2byte(float f)
|
41
|
-
{
|
34
|
+
unsigned char frt_float2byte(float f) {
|
42
35
|
if (f <= 0.0) {
|
43
36
|
return 0;
|
44
|
-
}
|
45
|
-
else {
|
37
|
+
} else {
|
46
38
|
/* correctly order the bytes for encoding */
|
47
39
|
frt_u32 i = frt_float2int(f);
|
48
40
|
int mantissa = (i & 0xEf0000) >> 21;
|