ferret 0.11.6 → 0.11.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -22
- data/RELEASE_CHANGES +137 -0
- data/RELEASE_NOTES +60 -0
- data/Rakefile +379 -274
- data/TODO +100 -8
- data/bin/ferret-browser +0 -0
- data/ext/BZLIB_blocksort.c +1094 -0
- data/ext/BZLIB_bzlib.c +1578 -0
- data/ext/BZLIB_compress.c +672 -0
- data/ext/BZLIB_crctable.c +104 -0
- data/ext/BZLIB_decompress.c +626 -0
- data/ext/BZLIB_huffman.c +205 -0
- data/ext/BZLIB_randtable.c +84 -0
- data/ext/{api.c → STEMMER_api.c} +7 -10
- data/ext/{libstemmer.c → STEMMER_libstemmer.c} +3 -2
- data/ext/{stem_ISO_8859_1_danish.c → STEMMER_stem_ISO_8859_1_danish.c} +123 -124
- data/ext/{stem_ISO_8859_1_dutch.c → STEMMER_stem_ISO_8859_1_dutch.c} +177 -188
- data/ext/STEMMER_stem_ISO_8859_1_english.c +1117 -0
- data/ext/{stem_ISO_8859_1_finnish.c → STEMMER_stem_ISO_8859_1_finnish.c} +276 -306
- data/ext/STEMMER_stem_ISO_8859_1_french.c +1246 -0
- data/ext/{stem_ISO_8859_1_german.c → STEMMER_stem_ISO_8859_1_german.c} +161 -170
- data/ext/STEMMER_stem_ISO_8859_1_hungarian.c +1230 -0
- data/ext/STEMMER_stem_ISO_8859_1_italian.c +1065 -0
- data/ext/STEMMER_stem_ISO_8859_1_norwegian.c +297 -0
- data/ext/{stem_ISO_8859_1_porter.c → STEMMER_stem_ISO_8859_1_porter.c} +263 -290
- data/ext/{stem_ISO_8859_1_portuguese.c → STEMMER_stem_ISO_8859_1_portuguese.c} +362 -380
- data/ext/STEMMER_stem_ISO_8859_1_spanish.c +1093 -0
- data/ext/STEMMER_stem_ISO_8859_1_swedish.c +307 -0
- data/ext/STEMMER_stem_ISO_8859_2_romanian.c +998 -0
- data/ext/{stem_KOI8_R_russian.c → STEMMER_stem_KOI8_R_russian.c} +244 -245
- data/ext/STEMMER_stem_UTF_8_danish.c +339 -0
- data/ext/{stem_UTF_8_dutch.c → STEMMER_stem_UTF_8_dutch.c} +192 -211
- data/ext/STEMMER_stem_UTF_8_english.c +1125 -0
- data/ext/{stem_UTF_8_finnish.c → STEMMER_stem_UTF_8_finnish.c} +284 -324
- data/ext/STEMMER_stem_UTF_8_french.c +1256 -0
- data/ext/{stem_UTF_8_german.c → STEMMER_stem_UTF_8_german.c} +170 -187
- data/ext/STEMMER_stem_UTF_8_hungarian.c +1234 -0
- data/ext/STEMMER_stem_UTF_8_italian.c +1073 -0
- data/ext/STEMMER_stem_UTF_8_norwegian.c +299 -0
- data/ext/{stem_UTF_8_porter.c → STEMMER_stem_UTF_8_porter.c} +271 -310
- data/ext/STEMMER_stem_UTF_8_portuguese.c +1023 -0
- data/ext/STEMMER_stem_UTF_8_romanian.c +1004 -0
- data/ext/STEMMER_stem_UTF_8_russian.c +694 -0
- data/ext/STEMMER_stem_UTF_8_spanish.c +1097 -0
- data/ext/STEMMER_stem_UTF_8_swedish.c +309 -0
- data/ext/STEMMER_stem_UTF_8_turkish.c +2205 -0
- data/ext/{utilities.c → STEMMER_utilities.c} +100 -68
- data/ext/analysis.c +276 -121
- data/ext/analysis.h +190 -143
- data/ext/api.h +3 -4
- data/ext/array.c +5 -3
- data/ext/array.h +52 -43
- data/ext/bitvector.c +38 -482
- data/ext/bitvector.h +446 -124
- data/ext/bzlib.h +282 -0
- data/ext/bzlib_private.h +503 -0
- data/ext/compound_io.c +23 -22
- data/ext/config.h +21 -11
- data/ext/document.c +43 -40
- data/ext/document.h +31 -21
- data/ext/except.c +20 -38
- data/ext/except.h +89 -76
- data/ext/extconf.rb +3 -2
- data/ext/ferret.c +49 -35
- data/ext/ferret.h +14 -11
- data/ext/field_index.c +262 -0
- data/ext/field_index.h +52 -0
- data/ext/filter.c +11 -10
- data/ext/fs_store.c +65 -47
- data/ext/global.c +245 -165
- data/ext/global.h +252 -54
- data/ext/hash.c +200 -243
- data/ext/hash.h +205 -163
- data/ext/hashset.c +118 -96
- data/ext/hashset.h +110 -82
- data/ext/header.h +19 -19
- data/ext/helper.c +11 -10
- data/ext/helper.h +14 -6
- data/ext/index.c +745 -366
- data/ext/index.h +503 -529
- data/ext/internal.h +1020 -0
- data/ext/lang.c +10 -0
- data/ext/lang.h +35 -15
- data/ext/mempool.c +5 -4
- data/ext/mempool.h +30 -22
- data/ext/modules.h +35 -7
- data/ext/multimapper.c +43 -2
- data/ext/multimapper.h +32 -23
- data/ext/posh.c +0 -0
- data/ext/posh.h +4 -38
- data/ext/priorityqueue.c +10 -12
- data/ext/priorityqueue.h +33 -21
- data/ext/q_boolean.c +22 -9
- data/ext/q_const_score.c +3 -2
- data/ext/q_filtered_query.c +15 -12
- data/ext/q_fuzzy.c +147 -135
- data/ext/q_match_all.c +3 -2
- data/ext/q_multi_term.c +28 -32
- data/ext/q_parser.c +451 -173
- data/ext/q_phrase.c +158 -79
- data/ext/q_prefix.c +16 -18
- data/ext/q_range.c +363 -31
- data/ext/q_span.c +130 -141
- data/ext/q_term.c +21 -21
- data/ext/q_wildcard.c +19 -23
- data/ext/r_analysis.c +369 -242
- data/ext/r_index.c +421 -434
- data/ext/r_qparser.c +142 -92
- data/ext/r_search.c +790 -407
- data/ext/r_store.c +44 -44
- data/ext/r_utils.c +264 -96
- data/ext/ram_store.c +29 -23
- data/ext/scanner.c +895 -0
- data/ext/scanner.h +36 -0
- data/ext/scanner_mb.c +6701 -0
- data/ext/scanner_utf8.c +4415 -0
- data/ext/search.c +210 -87
- data/ext/search.h +556 -488
- data/ext/similarity.c +17 -16
- data/ext/similarity.h +51 -44
- data/ext/sort.c +157 -354
- data/ext/stem_ISO_8859_1_hungarian.h +16 -0
- data/ext/stem_ISO_8859_2_romanian.h +16 -0
- data/ext/stem_UTF_8_hungarian.h +16 -0
- data/ext/stem_UTF_8_romanian.h +16 -0
- data/ext/stem_UTF_8_turkish.h +16 -0
- data/ext/stopwords.c +287 -278
- data/ext/store.c +57 -51
- data/ext/store.h +308 -286
- data/ext/symbol.c +10 -0
- data/ext/symbol.h +23 -0
- data/ext/term_vectors.c +14 -293
- data/ext/threading.h +22 -22
- data/ext/win32.h +12 -4
- data/lib/ferret.rb +2 -1
- data/lib/ferret/browser.rb +1 -1
- data/lib/ferret/field_symbol.rb +94 -0
- data/lib/ferret/index.rb +221 -34
- data/lib/ferret/number_tools.rb +6 -6
- data/lib/ferret/version.rb +3 -0
- data/test/{unit → long_running}/largefile/tc_largefile.rb +1 -1
- data/test/test_helper.rb +7 -2
- data/test/test_installed.rb +1 -0
- data/test/threading/thread_safety_index_test.rb +10 -1
- data/test/threading/thread_safety_read_write_test.rb +4 -7
- data/test/threading/thread_safety_test.rb +0 -0
- data/test/unit/analysis/tc_analyzer.rb +29 -27
- data/test/unit/analysis/tc_token_stream.rb +23 -16
- data/test/unit/index/tc_index.rb +116 -11
- data/test/unit/index/tc_index_reader.rb +27 -27
- data/test/unit/index/tc_index_writer.rb +10 -0
- data/test/unit/index/th_doc.rb +38 -21
- data/test/unit/search/tc_filter.rb +31 -10
- data/test/unit/search/tc_index_searcher.rb +6 -0
- data/test/unit/search/tm_searcher.rb +53 -1
- data/test/unit/store/tc_fs_store.rb +40 -2
- data/test/unit/store/tc_ram_store.rb +0 -0
- data/test/unit/store/tm_store.rb +0 -0
- data/test/unit/store/tm_store_lock.rb +7 -6
- data/test/unit/tc_field_symbol.rb +26 -0
- data/test/unit/ts_analysis.rb +0 -0
- data/test/unit/ts_index.rb +0 -0
- data/test/unit/ts_store.rb +0 -0
- data/test/unit/ts_utils.rb +0 -0
- data/test/unit/utils/tc_number_tools.rb +0 -0
- data/test/utils/content_generator.rb +226 -0
- metadata +262 -221
- data/ext/inc/lang.h +0 -48
- data/ext/inc/threading.h +0 -31
- data/ext/stem_ISO_8859_1_english.c +0 -1156
- data/ext/stem_ISO_8859_1_french.c +0 -1276
- data/ext/stem_ISO_8859_1_italian.c +0 -1091
- data/ext/stem_ISO_8859_1_norwegian.c +0 -296
- data/ext/stem_ISO_8859_1_spanish.c +0 -1119
- data/ext/stem_ISO_8859_1_swedish.c +0 -307
- data/ext/stem_UTF_8_danish.c +0 -344
- data/ext/stem_UTF_8_english.c +0 -1176
- data/ext/stem_UTF_8_french.c +0 -1296
- data/ext/stem_UTF_8_italian.c +0 -1113
- data/ext/stem_UTF_8_norwegian.c +0 -302
- data/ext/stem_UTF_8_portuguese.c +0 -1055
- data/ext/stem_UTF_8_russian.c +0 -709
- data/ext/stem_UTF_8_spanish.c +0 -1137
- data/ext/stem_UTF_8_swedish.c +0 -313
- data/lib/ferret_version.rb +0 -3
data/ext/hashset.c
CHANGED
@@ -1,170 +1,192 @@
|
|
1
1
|
#include "hashset.h"
|
2
2
|
#include <string.h>
|
3
|
+
#include "internal.h"
|
3
4
|
|
4
5
|
/*
|
5
6
|
* The HashSet contains an array +elems+ of the elements that have been added.
|
6
7
|
* It always has +size+ elements so +size+ ane +elems+ can be used to iterate
|
7
|
-
* over all alements in the HashSet. It also uses a
|
8
|
+
* over all alements in the HashSet. It also uses a Hash to keep track of
|
8
9
|
* which elements have been added and their index in the +elems+ array.
|
9
10
|
*/
|
10
|
-
static HashSet *hs_alloc(
|
11
|
+
static HashSet *hs_alloc(free_ft free_func)
|
11
12
|
{
|
12
13
|
HashSet *hs = ALLOC(HashSet);
|
13
14
|
hs->size = 0;
|
14
|
-
hs->
|
15
|
-
hs->
|
16
|
-
hs->free_elem_i = free_elem ? free_elem : &dummy_free;
|
15
|
+
hs->first = hs->last = NULL;
|
16
|
+
hs->free_elem_i = free_func ? free_func : &dummy_free;
|
17
17
|
return hs;
|
18
18
|
}
|
19
19
|
|
20
|
-
HashSet *hs_new(
|
21
|
-
int (*eq)(const void *p1, const void *p2),
|
22
|
-
void (*free_elem)(void *p))
|
20
|
+
HashSet *hs_new(hash_ft hash_func, eq_ft eq_func, free_ft free_func)
|
23
21
|
{
|
24
|
-
HashSet *hs = hs_alloc(
|
25
|
-
hs->ht = h_new(
|
22
|
+
HashSet *hs = hs_alloc(free_func);
|
23
|
+
hs->ht = h_new(hash_func, eq_func, NULL, NULL);
|
26
24
|
return hs;
|
27
25
|
}
|
28
26
|
|
29
|
-
HashSet *hs_new_str(
|
27
|
+
HashSet *hs_new_str(free_ft free_func)
|
30
28
|
{
|
31
|
-
HashSet *hs = hs_alloc(
|
32
|
-
hs->ht = h_new_str((free_ft) NULL,
|
29
|
+
HashSet *hs = hs_alloc(free_func);
|
30
|
+
hs->ht = h_new_str((free_ft) NULL, NULL);
|
33
31
|
return hs;
|
34
32
|
}
|
35
33
|
|
36
|
-
|
34
|
+
HashSet *hs_new_ptr(free_ft free_func)
|
37
35
|
{
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
HashSet *hs = hs_alloc(free_func);
|
37
|
+
hs->ht = h_new_ptr(NULL);
|
38
|
+
return hs;
|
41
39
|
}
|
42
40
|
|
43
|
-
void
|
41
|
+
static INLINE void clear(HashSet *hs, bool destroy)
|
44
42
|
{
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
HashSetEntry *curr, *next = hs->first;
|
44
|
+
free_ft do_free = destroy ? hs->free_elem_i : &dummy_free;
|
45
|
+
while (NULL != (curr = next)) {
|
46
|
+
next = curr->next;
|
47
|
+
do_free(curr->elem);
|
48
|
+
free(curr);
|
48
49
|
}
|
50
|
+
hs->first = hs->last = NULL;
|
51
|
+
hs->size = 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
void hs_clear(HashSet *hs)
|
55
|
+
{
|
56
|
+
clear(hs, true);
|
57
|
+
h_clear(hs->ht);
|
58
|
+
}
|
59
|
+
|
60
|
+
void hs_free(HashSet *hs)
|
61
|
+
{
|
62
|
+
clear(hs, false);
|
63
|
+
h_destroy(hs->ht);
|
64
|
+
free(hs);
|
49
65
|
}
|
50
66
|
|
51
67
|
void hs_destroy(HashSet *hs)
|
52
68
|
{
|
53
|
-
|
54
|
-
if (hs->free_elem_i != &dummy_free) {
|
55
|
-
for (i = 0; i < hs->size; i++) {
|
56
|
-
hs->free_elem_i(hs->elems[i]);
|
57
|
-
}
|
58
|
-
}
|
69
|
+
clear(hs, true);
|
59
70
|
h_destroy(hs->ht);
|
60
|
-
free(hs->elems);
|
61
71
|
free(hs);
|
62
72
|
}
|
63
73
|
|
64
|
-
|
74
|
+
static INLINE void append(HashSet *hs, void *elem)
|
65
75
|
{
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
/* No need to do anything */
|
76
|
+
HashSetEntry *entry = ALLOC(HashSetEntry);
|
77
|
+
entry->elem = elem;
|
78
|
+
entry->prev = hs->last;
|
79
|
+
entry->next = NULL;
|
80
|
+
if (!hs->first) {
|
81
|
+
hs->first = hs->last = entry;
|
73
82
|
}
|
74
83
|
else {
|
84
|
+
hs->last->next = entry;
|
85
|
+
hs->last = entry;
|
86
|
+
}
|
87
|
+
h_set(hs->ht, elem, entry);
|
88
|
+
hs->size++;
|
89
|
+
}
|
90
|
+
|
91
|
+
HashKeyStatus hs_add(HashSet *hs, void *elem)
|
92
|
+
{
|
93
|
+
HashKeyStatus has_elem = h_has_key(hs->ht, elem);
|
94
|
+
switch (has_elem)
|
95
|
+
{
|
96
|
+
/* We don't want to keep two of the same elem so free if necessary */
|
97
|
+
case HASH_KEY_EQUAL:
|
98
|
+
hs->free_elem_i(elem);
|
99
|
+
return has_elem;
|
100
|
+
|
101
|
+
/* No need to do anything */
|
102
|
+
case HASH_KEY_SAME:
|
103
|
+
return has_elem;
|
104
|
+
|
75
105
|
/* add the elem to the array, resizing if necessary */
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
}
|
80
|
-
hs->elems[hs->size] = elem;
|
81
|
-
h_set(hs->ht, elem, imalloc(hs->size));
|
82
|
-
hs->size++;
|
106
|
+
case HASH_KEY_DOES_NOT_EXIST:
|
107
|
+
break;
|
108
|
+
|
83
109
|
}
|
110
|
+
|
111
|
+
append(hs, elem);
|
84
112
|
return has_elem;
|
85
113
|
}
|
86
114
|
|
87
115
|
int hs_add_safe(HashSet *hs, void *elem)
|
88
116
|
{
|
89
|
-
|
90
|
-
|
117
|
+
switch(h_has_key(hs->ht, elem))
|
118
|
+
{
|
91
119
|
/* element can't be added */
|
92
|
-
return false;
|
93
|
-
|
94
|
-
else if (has_elem == HASH_KEY_SAME) {
|
120
|
+
case HASH_KEY_EQUAL: return false;
|
121
|
+
|
95
122
|
/* the exact same element has already been added */
|
96
|
-
return true;
|
97
|
-
|
98
|
-
else {
|
123
|
+
case HASH_KEY_SAME : return true;
|
124
|
+
|
99
125
|
/* add the elem to the array, resizing if necessary */
|
100
|
-
|
101
|
-
hs->capa *= 2;
|
102
|
-
REALLOC_N(hs->elems, void *, hs->capa);
|
103
|
-
}
|
104
|
-
hs->elems[hs->size] = elem;
|
105
|
-
h_set(hs->ht, elem, imalloc(hs->size));
|
106
|
-
hs->size++;
|
107
|
-
return true;
|
126
|
+
case HASH_KEY_DOES_NOT_EXIST : break;
|
108
127
|
}
|
128
|
+
append(hs, elem);
|
129
|
+
return true;
|
109
130
|
}
|
110
131
|
|
111
|
-
|
132
|
+
void *hs_rem(HashSet *hs, const void *elem)
|
112
133
|
{
|
113
|
-
void *
|
114
|
-
|
115
|
-
|
116
|
-
|
134
|
+
void *return_elem;
|
135
|
+
HashSetEntry *entry = (HashSetEntry *)h_get(hs->ht, elem);
|
136
|
+
if (entry == NULL) return NULL;
|
137
|
+
|
138
|
+
if (hs->first == hs->last) {
|
139
|
+
hs->first = hs->last = NULL;
|
140
|
+
}
|
141
|
+
else if (hs->first == entry) {
|
142
|
+
hs->first = entry->next;
|
143
|
+
hs->first->prev = NULL;
|
144
|
+
}
|
145
|
+
else if (hs->last == entry) {
|
146
|
+
hs->last = entry->prev;
|
147
|
+
hs->last->next = NULL;
|
117
148
|
}
|
118
149
|
else {
|
119
|
-
|
150
|
+
entry->prev->next = entry->next;
|
151
|
+
entry->next->prev = entry->prev;
|
120
152
|
}
|
153
|
+
return_elem = entry->elem;
|
154
|
+
h_del(hs->ht, return_elem);
|
155
|
+
free(entry);
|
156
|
+
hs->size--;
|
157
|
+
return return_elem;
|
121
158
|
}
|
122
159
|
|
123
|
-
|
160
|
+
int hs_del(HashSet *hs, const void *elem)
|
124
161
|
{
|
125
|
-
void *
|
126
|
-
|
127
|
-
|
128
|
-
return
|
129
|
-
}
|
130
|
-
else {
|
131
|
-
int i = *index;
|
132
|
-
int j;
|
133
|
-
ret_elem = hs->elems[i];
|
134
|
-
h_del(hs->ht, elem);
|
135
|
-
hs->size--;
|
136
|
-
for (j = i; j < hs->size; j++) {
|
137
|
-
hs->elems[j] = hs->elems[j+1];
|
138
|
-
h_set(hs->ht, hs->elems[j], imalloc(j));
|
139
|
-
}
|
140
|
-
return ret_elem;
|
162
|
+
void *tmp_elem = hs_rem(hs, elem);
|
163
|
+
if (tmp_elem != NULL) {
|
164
|
+
hs->free_elem_i(tmp_elem);
|
165
|
+
return 1;
|
141
166
|
}
|
167
|
+
return 0;
|
142
168
|
}
|
143
169
|
|
144
|
-
|
170
|
+
HashKeyStatus hs_exists(HashSet *hs, const void *elem)
|
145
171
|
{
|
146
172
|
return h_has_key(hs->ht, elem);
|
147
173
|
}
|
148
174
|
|
149
175
|
HashSet *hs_merge(HashSet *hs, HashSet * other)
|
150
176
|
{
|
151
|
-
|
152
|
-
for (
|
153
|
-
hs_add(hs,
|
177
|
+
HashSetEntry *entry = other->first;
|
178
|
+
for (; entry != NULL; entry = entry->next) {
|
179
|
+
hs_add(hs, entry->elem);
|
154
180
|
}
|
155
|
-
/* Now free the other hashset. It is no longer needed. No need, however,
|
156
|
-
* delete the elements as they
|
181
|
+
/* Now free the other hashset. It is no longer needed. No need, however,
|
182
|
+
* to delete the elements as they were either destroyed or added to the
|
183
|
+
* new hashset. */
|
157
184
|
hs_free(other);
|
158
185
|
return hs;
|
159
186
|
}
|
160
187
|
|
161
|
-
void *hs_orig(HashSet *hs, void *elem)
|
188
|
+
void *hs_orig(HashSet *hs, const void *elem)
|
162
189
|
{
|
163
|
-
|
164
|
-
|
165
|
-
return hs->elems[*index];
|
166
|
-
}
|
167
|
-
else {
|
168
|
-
return NULL;
|
169
|
-
}
|
190
|
+
HashSetEntry *entry = (HashSetEntry *)h_get(hs->ht, elem);
|
191
|
+
return entry ? entry->elem : NULL;
|
170
192
|
}
|
data/ext/hashset.h
CHANGED
@@ -1,187 +1,215 @@
|
|
1
1
|
#ifndef FRT_HASHSET_H
|
2
2
|
#define FRT_HASHSET_H
|
3
3
|
|
4
|
+
#ifdef __cplusplus
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
4
8
|
#include "hash.h"
|
5
9
|
#include "global.h"
|
6
10
|
|
7
|
-
#define
|
11
|
+
#define FRT_HS_MIN_SIZE 4
|
12
|
+
typedef struct FrtHashSetEntry {
|
13
|
+
void *elem;
|
14
|
+
struct FrtHashSetEntry *next;
|
15
|
+
struct FrtHashSetEntry *prev;
|
16
|
+
} FrtHashSetEntry;
|
8
17
|
|
9
|
-
typedef struct
|
18
|
+
typedef struct FrtHashSet
|
10
19
|
{
|
11
|
-
/*
|
12
|
-
int capa;
|
13
|
-
|
14
|
-
/* the number of elements in the HashSet */
|
20
|
+
/* the number of elements in the instance */
|
15
21
|
int size;
|
16
22
|
|
17
|
-
/* the
|
18
|
-
* they were added and can be iterated over
|
19
|
-
|
23
|
+
/* the first element in the list of elements in the FrtHashSet. The elements
|
24
|
+
* will be listed in the order they were added and can be iterated over by
|
25
|
+
* following the ->next pointer */
|
26
|
+
FrtHashSetEntry *first;
|
20
27
|
|
21
|
-
/*
|
22
|
-
|
28
|
+
/* the last element in the list of elements in the FrtHashSet. This is used
|
29
|
+
* internally to add elements to the list. */
|
30
|
+
FrtHashSetEntry *last;
|
23
31
|
|
24
|
-
/*
|
25
|
-
|
26
|
-
|
32
|
+
/* Hash used internally */
|
33
|
+
FrtHash *ht;
|
34
|
+
|
35
|
+
/* Internal: Frees elements added to the FrtHashSet. Should never be NULL */
|
36
|
+
frt_free_ft free_elem_i;
|
37
|
+
} FrtHashSet;
|
27
38
|
|
28
39
|
/**
|
29
|
-
* Create a new
|
30
|
-
* the functions used to hash the objects it will contain and the eq
|
31
|
-
* This should be used for non-string types.
|
40
|
+
* Create a new FrtHashSet. The function will allocate a FrtHashSet Struct
|
41
|
+
* setting the functions used to hash the objects it will contain and the eq
|
42
|
+
* function. This should be used for non-string types.
|
32
43
|
*
|
33
|
-
* @param hash function to hash objects added to the
|
44
|
+
* @param hash function to hash objects added to the FrtHashSet
|
34
45
|
* @param eq function to determine whether two items are equal
|
35
|
-
* @param free_elem function used to free elements as added to the
|
36
|
-
* when the
|
37
|
-
* @return a newly allocated
|
46
|
+
* @param free_elem function used to free elements as added to the FrtHashSet
|
47
|
+
* when the FrtHashSet if destroyed or duplicate elements are added to the Set
|
48
|
+
* @return a newly allocated FrtHashSet structure
|
49
|
+
*/
|
50
|
+
extern FrtHashSet *frt_hs_new(frt_hash_ft hash_func,
|
51
|
+
frt_eq_ft eq_func,
|
52
|
+
frt_free_ft free_func);
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Create a new FrtHashSet specifically for strings. This will create a
|
56
|
+
* FrtHashSet as if you used frt_hs_new with the standard string hash and eq
|
57
|
+
* functions.
|
58
|
+
*
|
59
|
+
* @param free_elem function used to free elements as added to the FrtHashSet
|
60
|
+
* when the FrtHashSet if destroyed or duplicate elements are added to the Set
|
61
|
+
* @return a newly allocated FrtHashSet structure
|
38
62
|
*/
|
39
|
-
extern
|
40
|
-
int (*eq)(const void *p1, const void *p2),
|
41
|
-
void (*free_elem)(void *p));
|
63
|
+
extern FrtHashSet *frt_hs_new_str(frt_free_ft free_func);
|
42
64
|
|
43
65
|
/**
|
44
|
-
* Create a new
|
45
|
-
*
|
66
|
+
* Create a new FrtHashSet specifically for pointers. Note that the only way
|
67
|
+
* two pointers will be considered equal is if they have the same address. So
|
68
|
+
* you can add the string "key" twice if it is stored at two different
|
69
|
+
* addresses.
|
46
70
|
*
|
47
|
-
* @param free_elem function used to free elements as added to the
|
48
|
-
* when the
|
49
|
-
* @return a newly allocated
|
71
|
+
* @param free_elem function used to free elements as added to the FrtHashSet
|
72
|
+
* when the FrtHashSet if destroyed or duplicate elements are added to the Set
|
73
|
+
* @return a newly allocated FrtHashSet structure
|
50
74
|
*/
|
51
|
-
extern
|
75
|
+
extern FrtHashSet *frt_hs_new_ptr(frt_free_ft free_func);
|
52
76
|
|
53
77
|
/**
|
54
|
-
* Free the memory allocated by the
|
55
|
-
* to the
|
56
|
-
* use
|
78
|
+
* Free the memory allocated by the FrtHashSet, but don't free the elements added
|
79
|
+
* to the FrtHashSet. If you'd like to free everything in the FrtHashSet you should
|
80
|
+
* use frt_hs_destroy
|
57
81
|
*
|
58
|
-
* @param hs the
|
82
|
+
* @param hs the FrtHashSet to free
|
59
83
|
*/
|
60
|
-
extern void
|
84
|
+
extern void frt_hs_free(FrtHashSet *self);
|
61
85
|
|
62
86
|
/**
|
63
|
-
* Destroy the
|
64
|
-
* like to free the memory allocated to the
|
65
|
-
* elements in the
|
87
|
+
* Destroy the FrtHashSet including all elements added to the FrtHashSet. If you'd
|
88
|
+
* like to free the memory allocated to the FrtHashSet without touching the
|
89
|
+
* elements in the FrtHashSet then use frt_hs_free
|
66
90
|
*
|
67
|
-
* @param hs the
|
91
|
+
* @param hs the FrtHashSet to destroy
|
68
92
|
*/
|
69
|
-
extern void
|
93
|
+
extern void frt_hs_destroy(FrtHashSet *self);
|
70
94
|
|
71
95
|
/**
|
72
96
|
* WARNING: this function may destroy some elements if you add them to a
|
73
|
-
*
|
97
|
+
* FrtHashSet were equivalent elements already exist, depending on how free_elem
|
74
98
|
* was set.
|
75
99
|
*
|
76
|
-
* Add the element to the
|
77
|
-
*
|
100
|
+
* Add the element to the FrtHashSet whether or not it was already in the
|
101
|
+
* FrtHashSet.
|
78
102
|
*
|
79
|
-
* When a element is added to the
|
103
|
+
* When a element is added to the Hash where it already exists, free_elem
|
80
104
|
* is called on it, ie the element you tried to add might get destroyed.
|
81
105
|
*
|
82
|
-
* @param hs the
|
83
|
-
* @param elem the element to add to the
|
106
|
+
* @param hs the FrtHashSet to add the element to
|
107
|
+
* @param elem the element to add to the FrtHashSet
|
84
108
|
* @return one of three values;
|
85
109
|
* <pre>
|
86
|
-
* HASH_KEY_DOES_NOT_EXIST the element was not already in the
|
110
|
+
* HASH_KEY_DOES_NOT_EXIST the element was not already in the FrtHashSet.
|
87
111
|
* This value is equal to 0 or false
|
88
112
|
* HASH_KEY_SAME the element was identical (same memory
|
89
113
|
* pointer) to an existing element so no freeing
|
90
114
|
* was done
|
91
115
|
* HASH_KEY_EQUAL the element was equal to an element already in
|
92
|
-
* the
|
116
|
+
* the FrtHashSet so the new_elem was freed if
|
93
117
|
* free_elem was set
|
94
118
|
* </pre>
|
95
119
|
*/
|
96
|
-
extern
|
120
|
+
extern FrtHashKeyStatus frt_hs_add(FrtHashSet *self, void *elem);
|
97
121
|
|
98
122
|
/**
|
99
|
-
* Add element to the
|
123
|
+
* Add element to the FrtHashSet. If the element already existed in the FrtHashSet
|
100
124
|
* and the new element was equal but not the same (same pointer/memory) then
|
101
125
|
* don't add the element and return false, otherwise return true.
|
102
126
|
*
|
103
|
-
* @param hs the
|
104
|
-
* @param elem the element to add to the
|
127
|
+
* @param hs the FrtHashSet to add the element to
|
128
|
+
* @param elem the element to add to the FrtHashSet
|
105
129
|
* @return true if the element was successfully added or false otherwise
|
106
130
|
*/
|
107
|
-
extern int
|
131
|
+
extern int frt_hs_add_safe(FrtHashSet *self, void *elem);
|
108
132
|
|
109
133
|
/**
|
110
|
-
* Delete the element from the
|
134
|
+
* Delete the element from the FrtHashSet. Returns true if the item was
|
111
135
|
* successfully deleted or false if the element never existed.
|
112
136
|
*
|
113
|
-
* @param hs the
|
137
|
+
* @param hs the FrtHashSet to delete from
|
114
138
|
* @param elem the element to delete
|
115
139
|
* @return true if the element was deleted or false if the element never
|
116
140
|
* existed
|
117
141
|
*/
|
118
|
-
extern int
|
142
|
+
extern int frt_hs_del(FrtHashSet *self, const void *elem);
|
119
143
|
|
120
144
|
/**
|
121
|
-
* Remove an item from the
|
145
|
+
* Remove an item from the FrtHashSet without actually freeing the item. This
|
122
146
|
* function should return the item itself so that it can be freed later if
|
123
147
|
* necessary.
|
124
148
|
*
|
125
|
-
* @param hs the
|
149
|
+
* @param hs the FrtHashSet to remove the element from.
|
126
150
|
* @param elem the element to remove
|
127
151
|
* @param the element that was removed or NULL otherwise
|
128
152
|
*/
|
129
|
-
extern void *
|
153
|
+
extern void *frt_hs_rem(FrtHashSet *self, const void *elem);
|
130
154
|
|
131
155
|
/**
|
132
156
|
* Check if the element exists and return the appropriate value described
|
133
157
|
* bellow.
|
134
158
|
*
|
135
|
-
* @param hs the
|
159
|
+
* @param hs the FrtHashSet to check in
|
136
160
|
* @param elem the element to check for
|
137
161
|
* @return one of the following values
|
138
162
|
* <pre>
|
139
|
-
* HASH_KEY_DOES_NOT_EXIST the element was not already in the
|
163
|
+
* HASH_KEY_DOES_NOT_EXIST the element was not already in the FrtHashSet.
|
140
164
|
* This value is equal to 0 or false
|
141
165
|
* HASH_KEY_SAME the element was identical (same memory
|
142
166
|
* pointer) to an existing element so no freeing
|
143
167
|
* was done
|
144
168
|
* HASH_KEY_EQUAL the element was equal to an element already in
|
145
|
-
* the
|
169
|
+
* the FrtHashSet so the new_elem was freed if
|
146
170
|
* free_elem was set
|
147
171
|
* </pre>
|
148
172
|
*/
|
149
|
-
extern
|
173
|
+
extern FrtHashKeyStatus frt_hs_exists(FrtHashSet *self, const void *elem);
|
150
174
|
|
151
175
|
/**
|
152
|
-
* Merge two HashSets. When a merge is done the merger (self)
|
176
|
+
* Merge two HashSets. When a merge is done the merger (self) Hash is
|
153
177
|
* returned and the mergee is destroyed. All elements from mergee that were
|
154
178
|
* not found in merger (self) will be added to self, otherwise they will be
|
155
179
|
* destroyed.
|
156
|
-
*
|
157
|
-
* @param self the
|
180
|
+
*
|
181
|
+
* @param self the FrtHashSet to merge into
|
158
182
|
* @param other HastSet to be merged into self
|
159
|
-
* @return the merged
|
183
|
+
* @return the merged FrtHashSet
|
160
184
|
*/
|
161
|
-
extern
|
185
|
+
extern FrtHashSet *frt_hs_merge(FrtHashSet *self, FrtHashSet *other);
|
162
186
|
|
163
|
-
/**
|
187
|
+
/**
|
164
188
|
* Return the original version of +elem+. So if you allocate two elements
|
165
|
-
* which are equal and add the first to the
|
166
|
-
* with the second element will return the first element from the
|
189
|
+
* which are equal and add the first to the FrtHashSet, calling this function
|
190
|
+
* with the second element will return the first element from the FrtHashSet.
|
167
191
|
*/
|
168
|
-
extern void *
|
192
|
+
extern void *frt_hs_orig(FrtHashSet *self, const void *elem);
|
169
193
|
|
170
194
|
/**
|
171
|
-
* Clear all elements from the
|
195
|
+
* Clear all elements from the FrtHashSet. If free_elem was set then use it to
|
172
196
|
* free all elements as they are cleared. After the method is called, the
|
173
197
|
* HashSets size will be 0.
|
174
198
|
*
|
175
|
-
* @param self the
|
199
|
+
* @param self the FrtHashSet to clear
|
176
200
|
*/
|
177
|
-
extern void
|
178
|
-
|
179
|
-
/* TODO: finish these functions
|
180
|
-
int hs_osf(
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
201
|
+
extern void frt_hs_clear(FrtHashSet *self);
|
202
|
+
|
203
|
+
/* TODO: finish implementing these functions FrtHashSet
|
204
|
+
int hs_osf(FrtHashSet *hs, void *elem);
|
205
|
+
FrtHashSet hs_or(FrtHashSet *hs1, FrtHashSet *h2);
|
206
|
+
FrtHashSet hs_excl_or(FrtHashSet *hs1, FrtHashSet *h2);
|
207
|
+
FrtHashSet hs_and(FrtHashSet *hs1, FrtHashSet *h2);
|
208
|
+
FrtHashSet hs_mask(FrtHashSet *hs1, FrtHashSet *h2);
|
185
209
|
*/
|
186
210
|
|
211
|
+
#ifdef __cplusplus
|
212
|
+
} // extern "C"
|
213
|
+
#endif
|
214
|
+
|
187
215
|
#endif
|