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.
Files changed (185) hide show
  1. data/README +10 -22
  2. data/RELEASE_CHANGES +137 -0
  3. data/RELEASE_NOTES +60 -0
  4. data/Rakefile +379 -274
  5. data/TODO +100 -8
  6. data/bin/ferret-browser +0 -0
  7. data/ext/BZLIB_blocksort.c +1094 -0
  8. data/ext/BZLIB_bzlib.c +1578 -0
  9. data/ext/BZLIB_compress.c +672 -0
  10. data/ext/BZLIB_crctable.c +104 -0
  11. data/ext/BZLIB_decompress.c +626 -0
  12. data/ext/BZLIB_huffman.c +205 -0
  13. data/ext/BZLIB_randtable.c +84 -0
  14. data/ext/{api.c → STEMMER_api.c} +7 -10
  15. data/ext/{libstemmer.c → STEMMER_libstemmer.c} +3 -2
  16. data/ext/{stem_ISO_8859_1_danish.c → STEMMER_stem_ISO_8859_1_danish.c} +123 -124
  17. data/ext/{stem_ISO_8859_1_dutch.c → STEMMER_stem_ISO_8859_1_dutch.c} +177 -188
  18. data/ext/STEMMER_stem_ISO_8859_1_english.c +1117 -0
  19. data/ext/{stem_ISO_8859_1_finnish.c → STEMMER_stem_ISO_8859_1_finnish.c} +276 -306
  20. data/ext/STEMMER_stem_ISO_8859_1_french.c +1246 -0
  21. data/ext/{stem_ISO_8859_1_german.c → STEMMER_stem_ISO_8859_1_german.c} +161 -170
  22. data/ext/STEMMER_stem_ISO_8859_1_hungarian.c +1230 -0
  23. data/ext/STEMMER_stem_ISO_8859_1_italian.c +1065 -0
  24. data/ext/STEMMER_stem_ISO_8859_1_norwegian.c +297 -0
  25. data/ext/{stem_ISO_8859_1_porter.c → STEMMER_stem_ISO_8859_1_porter.c} +263 -290
  26. data/ext/{stem_ISO_8859_1_portuguese.c → STEMMER_stem_ISO_8859_1_portuguese.c} +362 -380
  27. data/ext/STEMMER_stem_ISO_8859_1_spanish.c +1093 -0
  28. data/ext/STEMMER_stem_ISO_8859_1_swedish.c +307 -0
  29. data/ext/STEMMER_stem_ISO_8859_2_romanian.c +998 -0
  30. data/ext/{stem_KOI8_R_russian.c → STEMMER_stem_KOI8_R_russian.c} +244 -245
  31. data/ext/STEMMER_stem_UTF_8_danish.c +339 -0
  32. data/ext/{stem_UTF_8_dutch.c → STEMMER_stem_UTF_8_dutch.c} +192 -211
  33. data/ext/STEMMER_stem_UTF_8_english.c +1125 -0
  34. data/ext/{stem_UTF_8_finnish.c → STEMMER_stem_UTF_8_finnish.c} +284 -324
  35. data/ext/STEMMER_stem_UTF_8_french.c +1256 -0
  36. data/ext/{stem_UTF_8_german.c → STEMMER_stem_UTF_8_german.c} +170 -187
  37. data/ext/STEMMER_stem_UTF_8_hungarian.c +1234 -0
  38. data/ext/STEMMER_stem_UTF_8_italian.c +1073 -0
  39. data/ext/STEMMER_stem_UTF_8_norwegian.c +299 -0
  40. data/ext/{stem_UTF_8_porter.c → STEMMER_stem_UTF_8_porter.c} +271 -310
  41. data/ext/STEMMER_stem_UTF_8_portuguese.c +1023 -0
  42. data/ext/STEMMER_stem_UTF_8_romanian.c +1004 -0
  43. data/ext/STEMMER_stem_UTF_8_russian.c +694 -0
  44. data/ext/STEMMER_stem_UTF_8_spanish.c +1097 -0
  45. data/ext/STEMMER_stem_UTF_8_swedish.c +309 -0
  46. data/ext/STEMMER_stem_UTF_8_turkish.c +2205 -0
  47. data/ext/{utilities.c → STEMMER_utilities.c} +100 -68
  48. data/ext/analysis.c +276 -121
  49. data/ext/analysis.h +190 -143
  50. data/ext/api.h +3 -4
  51. data/ext/array.c +5 -3
  52. data/ext/array.h +52 -43
  53. data/ext/bitvector.c +38 -482
  54. data/ext/bitvector.h +446 -124
  55. data/ext/bzlib.h +282 -0
  56. data/ext/bzlib_private.h +503 -0
  57. data/ext/compound_io.c +23 -22
  58. data/ext/config.h +21 -11
  59. data/ext/document.c +43 -40
  60. data/ext/document.h +31 -21
  61. data/ext/except.c +20 -38
  62. data/ext/except.h +89 -76
  63. data/ext/extconf.rb +3 -2
  64. data/ext/ferret.c +49 -35
  65. data/ext/ferret.h +14 -11
  66. data/ext/field_index.c +262 -0
  67. data/ext/field_index.h +52 -0
  68. data/ext/filter.c +11 -10
  69. data/ext/fs_store.c +65 -47
  70. data/ext/global.c +245 -165
  71. data/ext/global.h +252 -54
  72. data/ext/hash.c +200 -243
  73. data/ext/hash.h +205 -163
  74. data/ext/hashset.c +118 -96
  75. data/ext/hashset.h +110 -82
  76. data/ext/header.h +19 -19
  77. data/ext/helper.c +11 -10
  78. data/ext/helper.h +14 -6
  79. data/ext/index.c +745 -366
  80. data/ext/index.h +503 -529
  81. data/ext/internal.h +1020 -0
  82. data/ext/lang.c +10 -0
  83. data/ext/lang.h +35 -15
  84. data/ext/mempool.c +5 -4
  85. data/ext/mempool.h +30 -22
  86. data/ext/modules.h +35 -7
  87. data/ext/multimapper.c +43 -2
  88. data/ext/multimapper.h +32 -23
  89. data/ext/posh.c +0 -0
  90. data/ext/posh.h +4 -38
  91. data/ext/priorityqueue.c +10 -12
  92. data/ext/priorityqueue.h +33 -21
  93. data/ext/q_boolean.c +22 -9
  94. data/ext/q_const_score.c +3 -2
  95. data/ext/q_filtered_query.c +15 -12
  96. data/ext/q_fuzzy.c +147 -135
  97. data/ext/q_match_all.c +3 -2
  98. data/ext/q_multi_term.c +28 -32
  99. data/ext/q_parser.c +451 -173
  100. data/ext/q_phrase.c +158 -79
  101. data/ext/q_prefix.c +16 -18
  102. data/ext/q_range.c +363 -31
  103. data/ext/q_span.c +130 -141
  104. data/ext/q_term.c +21 -21
  105. data/ext/q_wildcard.c +19 -23
  106. data/ext/r_analysis.c +369 -242
  107. data/ext/r_index.c +421 -434
  108. data/ext/r_qparser.c +142 -92
  109. data/ext/r_search.c +790 -407
  110. data/ext/r_store.c +44 -44
  111. data/ext/r_utils.c +264 -96
  112. data/ext/ram_store.c +29 -23
  113. data/ext/scanner.c +895 -0
  114. data/ext/scanner.h +36 -0
  115. data/ext/scanner_mb.c +6701 -0
  116. data/ext/scanner_utf8.c +4415 -0
  117. data/ext/search.c +210 -87
  118. data/ext/search.h +556 -488
  119. data/ext/similarity.c +17 -16
  120. data/ext/similarity.h +51 -44
  121. data/ext/sort.c +157 -354
  122. data/ext/stem_ISO_8859_1_hungarian.h +16 -0
  123. data/ext/stem_ISO_8859_2_romanian.h +16 -0
  124. data/ext/stem_UTF_8_hungarian.h +16 -0
  125. data/ext/stem_UTF_8_romanian.h +16 -0
  126. data/ext/stem_UTF_8_turkish.h +16 -0
  127. data/ext/stopwords.c +287 -278
  128. data/ext/store.c +57 -51
  129. data/ext/store.h +308 -286
  130. data/ext/symbol.c +10 -0
  131. data/ext/symbol.h +23 -0
  132. data/ext/term_vectors.c +14 -293
  133. data/ext/threading.h +22 -22
  134. data/ext/win32.h +12 -4
  135. data/lib/ferret.rb +2 -1
  136. data/lib/ferret/browser.rb +1 -1
  137. data/lib/ferret/field_symbol.rb +94 -0
  138. data/lib/ferret/index.rb +221 -34
  139. data/lib/ferret/number_tools.rb +6 -6
  140. data/lib/ferret/version.rb +3 -0
  141. data/test/{unit → long_running}/largefile/tc_largefile.rb +1 -1
  142. data/test/test_helper.rb +7 -2
  143. data/test/test_installed.rb +1 -0
  144. data/test/threading/thread_safety_index_test.rb +10 -1
  145. data/test/threading/thread_safety_read_write_test.rb +4 -7
  146. data/test/threading/thread_safety_test.rb +0 -0
  147. data/test/unit/analysis/tc_analyzer.rb +29 -27
  148. data/test/unit/analysis/tc_token_stream.rb +23 -16
  149. data/test/unit/index/tc_index.rb +116 -11
  150. data/test/unit/index/tc_index_reader.rb +27 -27
  151. data/test/unit/index/tc_index_writer.rb +10 -0
  152. data/test/unit/index/th_doc.rb +38 -21
  153. data/test/unit/search/tc_filter.rb +31 -10
  154. data/test/unit/search/tc_index_searcher.rb +6 -0
  155. data/test/unit/search/tm_searcher.rb +53 -1
  156. data/test/unit/store/tc_fs_store.rb +40 -2
  157. data/test/unit/store/tc_ram_store.rb +0 -0
  158. data/test/unit/store/tm_store.rb +0 -0
  159. data/test/unit/store/tm_store_lock.rb +7 -6
  160. data/test/unit/tc_field_symbol.rb +26 -0
  161. data/test/unit/ts_analysis.rb +0 -0
  162. data/test/unit/ts_index.rb +0 -0
  163. data/test/unit/ts_store.rb +0 -0
  164. data/test/unit/ts_utils.rb +0 -0
  165. data/test/unit/utils/tc_number_tools.rb +0 -0
  166. data/test/utils/content_generator.rb +226 -0
  167. metadata +262 -221
  168. data/ext/inc/lang.h +0 -48
  169. data/ext/inc/threading.h +0 -31
  170. data/ext/stem_ISO_8859_1_english.c +0 -1156
  171. data/ext/stem_ISO_8859_1_french.c +0 -1276
  172. data/ext/stem_ISO_8859_1_italian.c +0 -1091
  173. data/ext/stem_ISO_8859_1_norwegian.c +0 -296
  174. data/ext/stem_ISO_8859_1_spanish.c +0 -1119
  175. data/ext/stem_ISO_8859_1_swedish.c +0 -307
  176. data/ext/stem_UTF_8_danish.c +0 -344
  177. data/ext/stem_UTF_8_english.c +0 -1176
  178. data/ext/stem_UTF_8_french.c +0 -1296
  179. data/ext/stem_UTF_8_italian.c +0 -1113
  180. data/ext/stem_UTF_8_norwegian.c +0 -302
  181. data/ext/stem_UTF_8_portuguese.c +0 -1055
  182. data/ext/stem_UTF_8_russian.c +0 -709
  183. data/ext/stem_UTF_8_spanish.c +0 -1137
  184. data/ext/stem_UTF_8_swedish.c +0 -313
  185. data/lib/ferret_version.rb +0 -3
@@ -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 HashTable to keep track of
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(void (*free_elem) (void *p))
11
+ static HashSet *hs_alloc(free_ft free_func)
11
12
  {
12
13
  HashSet *hs = ALLOC(HashSet);
13
14
  hs->size = 0;
14
- hs->capa = HS_MIN_SIZE;
15
- hs->elems = ALLOC_N(void *, HS_MIN_SIZE);
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(unsigned long (*hash)(const void *p),
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(free_elem);
25
- hs->ht = h_new(hash, eq, NULL, &free);
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(void (*free_elem) (void *p))
27
+ HashSet *hs_new_str(free_ft free_func)
30
28
  {
31
- HashSet *hs = hs_alloc(free_elem);
32
- hs->ht = h_new_str((free_ft) NULL, &free);
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
- void hs_free(HashSet *hs)
34
+ HashSet *hs_new_ptr(free_ft free_func)
37
35
  {
38
- h_destroy(hs->ht);
39
- free(hs->elems);
40
- free(hs);
36
+ HashSet *hs = hs_alloc(free_func);
37
+ hs->ht = h_new_ptr(NULL);
38
+ return hs;
41
39
  }
42
40
 
43
- void hs_clear(HashSet *hs)
41
+ static INLINE void clear(HashSet *hs, bool destroy)
44
42
  {
45
- int i;
46
- for (i = hs->size - 1; i >= 0; i--) {
47
- hs_del(hs, hs->elems[i]);
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
- int i;
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
- int hs_add(HashSet *hs, void *elem)
74
+ static INLINE void append(HashSet *hs, void *elem)
65
75
  {
66
- int has_elem = h_has_key(hs->ht, elem);
67
- if (has_elem == HASH_KEY_EQUAL) {
68
- /* We don't want to keep two of the same elem so free if necessary */
69
- hs->free_elem_i(elem);
70
- }
71
- else if (has_elem == HASH_KEY_SAME) {
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
- if (hs->size >= hs->capa) {
77
- hs->capa *= 2;
78
- REALLOC_N(hs->elems, void *, hs->capa);
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
- int has_elem = h_has_key(hs->ht, elem);
90
- if (has_elem == HASH_KEY_EQUAL) {
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
- if (hs->size >= hs->capa) {
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
- int hs_del(HashSet *hs, void *elem)
132
+ void *hs_rem(HashSet *hs, const void *elem)
112
133
  {
113
- void *tmp_elem = hs_rem(hs, elem);
114
- if (tmp_elem != NULL) {
115
- hs->free_elem_i(tmp_elem);
116
- return 1;
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
- return 0;
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
- void *hs_rem(HashSet *hs, void *elem)
160
+ int hs_del(HashSet *hs, const void *elem)
124
161
  {
125
- void *ret_elem;
126
- int *index = (int *)h_get(hs->ht, elem);
127
- if (index == NULL) {
128
- return NULL;
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
- int hs_exists(HashSet *hs, void *elem)
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
- int i;
152
- for (i = 0; i < other->size; i++) {
153
- hs_add(hs, other->elems[i]);
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, to
156
- * delete the elements as they're either destroyed or in the new hash set */
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
- int *index = h_get(hs->ht, elem);
164
- if (index) {
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
  }
@@ -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 HS_MIN_SIZE 4
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 HashSet
18
+ typedef struct FrtHashSet
10
19
  {
11
- /* used internally to allocate space to elems */
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 elements in the HashSet. The elements will be found in the order
18
- * they were added and can be iterated over from 0 to .size */
19
- void **elems;
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
- /* HashTable used internally */
22
- HashTable *ht;
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
- /* Internal: Frees elements added to the HashSet. Should never be NULL */
25
- void (*free_elem_i)(void *p);
26
- } HashSet;
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 HashSet. The function will allocate a HashSet Struct setting
30
- * the functions used to hash the objects it will contain and the eq function.
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 HashSet
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 HashSet
36
- * when the HashSet if destroyed or duplicate elements are added to the Set
37
- * @return a newly allocated HashSet structure
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 HashSet *hs_new(unsigned long (*hash)(const void *p),
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 HashSet specifically for strings. This will create a HashSet
45
- * as if you used hs_new with the standard string hash and eq functions.
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 HashSet
48
- * when the HashSet if destroyed or duplicate elements are added to the Set
49
- * @return a newly allocated HashSet structure
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 HashSet *hs_new_str(void (*free_elem) (void *p));
75
+ extern FrtHashSet *frt_hs_new_ptr(frt_free_ft free_func);
52
76
 
53
77
  /**
54
- * Free the memory allocated by the HashSet, but don't free the elements added
55
- * to the HashSet. If you'd like to free everything in the HashSet you should
56
- * use hs_destroy
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 HashSet to free
82
+ * @param hs the FrtHashSet to free
59
83
  */
60
- extern void hs_free(HashSet *self);
84
+ extern void frt_hs_free(FrtHashSet *self);
61
85
 
62
86
  /**
63
- * Destroy the HashSet including all elements added to the HashSet. If you'd
64
- * like to free the memory allocated to the HashSet without touching the
65
- * elements in the HashSet then use hs_free
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 HashSet to destroy
91
+ * @param hs the FrtHashSet to destroy
68
92
  */
69
- extern void hs_destroy(HashSet *self);
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
- * HashSet were equivalent elements already exist, depending on how free_elem
97
+ * FrtHashSet were equivalent elements already exist, depending on how free_elem
74
98
  * was set.
75
99
  *
76
- * Add the element to the HashSet whether or not it was already in the
77
- * HashSet.
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 HashTable where it already exists, free_elem
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 HashSet to add the element to
83
- * @param elem the element to add to the HashSet
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 HashSet.
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 HashSet so the new_elem was freed if
116
+ * the FrtHashSet so the new_elem was freed if
93
117
  * free_elem was set
94
118
  * </pre>
95
119
  */
96
- extern int hs_add(HashSet *self, void *elem);
120
+ extern FrtHashKeyStatus frt_hs_add(FrtHashSet *self, void *elem);
97
121
 
98
122
  /**
99
- * Add element to the HashSet. If the element already existed in the HashSet
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 HashSet to add the element to
104
- * @param elem the element to add to the HashSet
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 hs_add_safe(HashSet *self, void *elem);
131
+ extern int frt_hs_add_safe(FrtHashSet *self, void *elem);
108
132
 
109
133
  /**
110
- * Delete the element from the HashSet. Returns true if the item was
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 HashSet to delete from
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 hs_del(HashSet *self, void *elem);
142
+ extern int frt_hs_del(FrtHashSet *self, const void *elem);
119
143
 
120
144
  /**
121
- * Remove an item from the HashSet without actually freeing the item. This
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 HashSet to remove the element from.
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 *hs_rem(HashSet *self, void *elem);
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 HashSet to check in
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 HashSet.
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 HashSet so the new_elem was freed if
169
+ * the FrtHashSet so the new_elem was freed if
146
170
  * free_elem was set
147
171
  * </pre>
148
172
  */
149
- extern int hs_exists(HashSet *self, void *elem);
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) HashTable is
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 HashSet to merge into
180
+ *
181
+ * @param self the FrtHashSet to merge into
158
182
  * @param other HastSet to be merged into self
159
- * @return the merged HashSet
183
+ * @return the merged FrtHashSet
160
184
  */
161
- extern HashSet *hs_merge(HashSet *self, HashSet *other);
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 HashSet, calling this function
166
- * with the second element will return the first element from the HashSet.
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 *hs_orig(HashSet *self, void *elem);
192
+ extern void *frt_hs_orig(FrtHashSet *self, const void *elem);
169
193
 
170
194
  /**
171
- * Clear all elements from the HashSet. If free_elem was set then use it to
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 HashSet to clear
199
+ * @param self the FrtHashSet to clear
176
200
  */
177
- extern void hs_clear(HashSet *self);
178
-
179
- /* TODO: finish these functions.
180
- int hs_osf(HashSet *hs, void *elem);
181
- HashSet hs_or(HashSet *hs1, HashSet *h2);
182
- HashSet hs_excl_or(HashSet *hs1, HashSet *h2);
183
- HashSet hs_and(HashSet *hs1, HashSet *h2);
184
- HashSet hs_mask(HashSet *hs1, HashSet *h2);
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