jk-ferret 0.11.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. data/CHANGELOG +24 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +90 -0
  4. data/RELEASE_CHANGES +137 -0
  5. data/RELEASE_NOTES +60 -0
  6. data/Rakefile +443 -0
  7. data/TODO +109 -0
  8. data/TUTORIAL +231 -0
  9. data/bin/ferret-browser +79 -0
  10. data/ext/BZLIB_blocksort.c +1094 -0
  11. data/ext/BZLIB_bzlib.c +1578 -0
  12. data/ext/BZLIB_compress.c +672 -0
  13. data/ext/BZLIB_crctable.c +104 -0
  14. data/ext/BZLIB_decompress.c +626 -0
  15. data/ext/BZLIB_huffman.c +205 -0
  16. data/ext/BZLIB_randtable.c +84 -0
  17. data/ext/STEMMER_api.c +66 -0
  18. data/ext/STEMMER_libstemmer.c +93 -0
  19. data/ext/STEMMER_stem_ISO_8859_1_danish.c +337 -0
  20. data/ext/STEMMER_stem_ISO_8859_1_dutch.c +624 -0
  21. data/ext/STEMMER_stem_ISO_8859_1_english.c +1117 -0
  22. data/ext/STEMMER_stem_ISO_8859_1_finnish.c +762 -0
  23. data/ext/STEMMER_stem_ISO_8859_1_french.c +1246 -0
  24. data/ext/STEMMER_stem_ISO_8859_1_german.c +503 -0
  25. data/ext/STEMMER_stem_ISO_8859_1_hungarian.c +1230 -0
  26. data/ext/STEMMER_stem_ISO_8859_1_italian.c +1065 -0
  27. data/ext/STEMMER_stem_ISO_8859_1_norwegian.c +297 -0
  28. data/ext/STEMMER_stem_ISO_8859_1_porter.c +749 -0
  29. data/ext/STEMMER_stem_ISO_8859_1_portuguese.c +1017 -0
  30. data/ext/STEMMER_stem_ISO_8859_1_spanish.c +1093 -0
  31. data/ext/STEMMER_stem_ISO_8859_1_swedish.c +307 -0
  32. data/ext/STEMMER_stem_ISO_8859_2_romanian.c +998 -0
  33. data/ext/STEMMER_stem_KOI8_R_russian.c +700 -0
  34. data/ext/STEMMER_stem_UTF_8_danish.c +339 -0
  35. data/ext/STEMMER_stem_UTF_8_dutch.c +634 -0
  36. data/ext/STEMMER_stem_UTF_8_english.c +1125 -0
  37. data/ext/STEMMER_stem_UTF_8_finnish.c +768 -0
  38. data/ext/STEMMER_stem_UTF_8_french.c +1256 -0
  39. data/ext/STEMMER_stem_UTF_8_german.c +509 -0
  40. data/ext/STEMMER_stem_UTF_8_hungarian.c +1234 -0
  41. data/ext/STEMMER_stem_UTF_8_italian.c +1073 -0
  42. data/ext/STEMMER_stem_UTF_8_norwegian.c +299 -0
  43. data/ext/STEMMER_stem_UTF_8_porter.c +755 -0
  44. data/ext/STEMMER_stem_UTF_8_portuguese.c +1023 -0
  45. data/ext/STEMMER_stem_UTF_8_romanian.c +1004 -0
  46. data/ext/STEMMER_stem_UTF_8_russian.c +694 -0
  47. data/ext/STEMMER_stem_UTF_8_spanish.c +1097 -0
  48. data/ext/STEMMER_stem_UTF_8_swedish.c +309 -0
  49. data/ext/STEMMER_stem_UTF_8_turkish.c +2205 -0
  50. data/ext/STEMMER_utilities.c +478 -0
  51. data/ext/analysis.c +1710 -0
  52. data/ext/analysis.h +266 -0
  53. data/ext/api.h +26 -0
  54. data/ext/array.c +125 -0
  55. data/ext/array.h +62 -0
  56. data/ext/bitvector.c +96 -0
  57. data/ext/bitvector.h +594 -0
  58. data/ext/bzlib.h +282 -0
  59. data/ext/bzlib_private.h +503 -0
  60. data/ext/compound_io.c +384 -0
  61. data/ext/config.h +52 -0
  62. data/ext/document.c +159 -0
  63. data/ext/document.h +63 -0
  64. data/ext/except.c +102 -0
  65. data/ext/except.h +176 -0
  66. data/ext/extconf.rb +15 -0
  67. data/ext/ferret.c +416 -0
  68. data/ext/ferret.h +94 -0
  69. data/ext/field_index.c +262 -0
  70. data/ext/field_index.h +52 -0
  71. data/ext/filter.c +157 -0
  72. data/ext/fs_store.c +493 -0
  73. data/ext/global.c +458 -0
  74. data/ext/global.h +302 -0
  75. data/ext/hash.c +524 -0
  76. data/ext/hash.h +515 -0
  77. data/ext/hashset.c +192 -0
  78. data/ext/hashset.h +215 -0
  79. data/ext/header.h +58 -0
  80. data/ext/helper.c +63 -0
  81. data/ext/helper.h +21 -0
  82. data/ext/index.c +6804 -0
  83. data/ext/index.h +935 -0
  84. data/ext/internal.h +1019 -0
  85. data/ext/lang.c +10 -0
  86. data/ext/lang.h +68 -0
  87. data/ext/libstemmer.h +79 -0
  88. data/ext/mempool.c +88 -0
  89. data/ext/mempool.h +43 -0
  90. data/ext/modules.h +190 -0
  91. data/ext/multimapper.c +351 -0
  92. data/ext/multimapper.h +60 -0
  93. data/ext/posh.c +1006 -0
  94. data/ext/posh.h +973 -0
  95. data/ext/priorityqueue.c +149 -0
  96. data/ext/priorityqueue.h +155 -0
  97. data/ext/q_boolean.c +1621 -0
  98. data/ext/q_const_score.c +162 -0
  99. data/ext/q_filtered_query.c +212 -0
  100. data/ext/q_fuzzy.c +280 -0
  101. data/ext/q_match_all.c +149 -0
  102. data/ext/q_multi_term.c +673 -0
  103. data/ext/q_parser.c +3103 -0
  104. data/ext/q_phrase.c +1206 -0
  105. data/ext/q_prefix.c +98 -0
  106. data/ext/q_range.c +682 -0
  107. data/ext/q_span.c +2390 -0
  108. data/ext/q_term.c +337 -0
  109. data/ext/q_wildcard.c +167 -0
  110. data/ext/r_analysis.c +2626 -0
  111. data/ext/r_index.c +3468 -0
  112. data/ext/r_qparser.c +635 -0
  113. data/ext/r_search.c +4490 -0
  114. data/ext/r_store.c +513 -0
  115. data/ext/r_utils.c +1131 -0
  116. data/ext/ram_store.c +476 -0
  117. data/ext/scanner.c +895 -0
  118. data/ext/scanner.h +36 -0
  119. data/ext/scanner_mb.c +6701 -0
  120. data/ext/scanner_utf8.c +4415 -0
  121. data/ext/search.c +1864 -0
  122. data/ext/search.h +953 -0
  123. data/ext/similarity.c +151 -0
  124. data/ext/similarity.h +89 -0
  125. data/ext/sort.c +786 -0
  126. data/ext/stem_ISO_8859_1_danish.h +16 -0
  127. data/ext/stem_ISO_8859_1_dutch.h +16 -0
  128. data/ext/stem_ISO_8859_1_english.h +16 -0
  129. data/ext/stem_ISO_8859_1_finnish.h +16 -0
  130. data/ext/stem_ISO_8859_1_french.h +16 -0
  131. data/ext/stem_ISO_8859_1_german.h +16 -0
  132. data/ext/stem_ISO_8859_1_hungarian.h +16 -0
  133. data/ext/stem_ISO_8859_1_italian.h +16 -0
  134. data/ext/stem_ISO_8859_1_norwegian.h +16 -0
  135. data/ext/stem_ISO_8859_1_porter.h +16 -0
  136. data/ext/stem_ISO_8859_1_portuguese.h +16 -0
  137. data/ext/stem_ISO_8859_1_spanish.h +16 -0
  138. data/ext/stem_ISO_8859_1_swedish.h +16 -0
  139. data/ext/stem_ISO_8859_2_romanian.h +16 -0
  140. data/ext/stem_KOI8_R_russian.h +16 -0
  141. data/ext/stem_UTF_8_danish.h +16 -0
  142. data/ext/stem_UTF_8_dutch.h +16 -0
  143. data/ext/stem_UTF_8_english.h +16 -0
  144. data/ext/stem_UTF_8_finnish.h +16 -0
  145. data/ext/stem_UTF_8_french.h +16 -0
  146. data/ext/stem_UTF_8_german.h +16 -0
  147. data/ext/stem_UTF_8_hungarian.h +16 -0
  148. data/ext/stem_UTF_8_italian.h +16 -0
  149. data/ext/stem_UTF_8_norwegian.h +16 -0
  150. data/ext/stem_UTF_8_porter.h +16 -0
  151. data/ext/stem_UTF_8_portuguese.h +16 -0
  152. data/ext/stem_UTF_8_romanian.h +16 -0
  153. data/ext/stem_UTF_8_russian.h +16 -0
  154. data/ext/stem_UTF_8_spanish.h +16 -0
  155. data/ext/stem_UTF_8_swedish.h +16 -0
  156. data/ext/stem_UTF_8_turkish.h +16 -0
  157. data/ext/stopwords.c +410 -0
  158. data/ext/store.c +698 -0
  159. data/ext/store.h +799 -0
  160. data/ext/symbol.c +10 -0
  161. data/ext/symbol.h +23 -0
  162. data/ext/term_vectors.c +73 -0
  163. data/ext/threading.h +31 -0
  164. data/ext/win32.h +62 -0
  165. data/lib/ferret.rb +30 -0
  166. data/lib/ferret/browser.rb +246 -0
  167. data/lib/ferret/browser/s/global.js +192 -0
  168. data/lib/ferret/browser/s/style.css +148 -0
  169. data/lib/ferret/browser/views/document/list.rhtml +49 -0
  170. data/lib/ferret/browser/views/document/show.rhtml +27 -0
  171. data/lib/ferret/browser/views/error/index.rhtml +7 -0
  172. data/lib/ferret/browser/views/help/index.rhtml +8 -0
  173. data/lib/ferret/browser/views/home/index.rhtml +29 -0
  174. data/lib/ferret/browser/views/layout.rhtml +22 -0
  175. data/lib/ferret/browser/views/term-vector/index.rhtml +4 -0
  176. data/lib/ferret/browser/views/term/index.rhtml +199 -0
  177. data/lib/ferret/browser/views/term/termdocs.rhtml +1 -0
  178. data/lib/ferret/browser/webrick.rb +14 -0
  179. data/lib/ferret/document.rb +130 -0
  180. data/lib/ferret/field_infos.rb +44 -0
  181. data/lib/ferret/field_symbol.rb +87 -0
  182. data/lib/ferret/index.rb +973 -0
  183. data/lib/ferret/number_tools.rb +157 -0
  184. data/lib/ferret/version.rb +3 -0
  185. data/setup.rb +1555 -0
  186. data/test/long_running/largefile/tc_largefile.rb +46 -0
  187. data/test/test_all.rb +5 -0
  188. data/test/test_helper.rb +29 -0
  189. data/test/test_installed.rb +1 -0
  190. data/test/threading/number_to_spoken.rb +132 -0
  191. data/test/threading/thread_safety_index_test.rb +88 -0
  192. data/test/threading/thread_safety_read_write_test.rb +73 -0
  193. data/test/threading/thread_safety_test.rb +133 -0
  194. data/test/unit/analysis/tc_analyzer.rb +550 -0
  195. data/test/unit/analysis/tc_token_stream.rb +653 -0
  196. data/test/unit/index/tc_index.rb +867 -0
  197. data/test/unit/index/tc_index_reader.rb +699 -0
  198. data/test/unit/index/tc_index_writer.rb +447 -0
  199. data/test/unit/index/th_doc.rb +332 -0
  200. data/test/unit/query_parser/tc_query_parser.rb +238 -0
  201. data/test/unit/search/tc_filter.rb +156 -0
  202. data/test/unit/search/tc_fuzzy_query.rb +147 -0
  203. data/test/unit/search/tc_index_searcher.rb +67 -0
  204. data/test/unit/search/tc_multi_searcher.rb +128 -0
  205. data/test/unit/search/tc_multiple_search_requests.rb +58 -0
  206. data/test/unit/search/tc_search_and_sort.rb +179 -0
  207. data/test/unit/search/tc_sort.rb +49 -0
  208. data/test/unit/search/tc_sort_field.rb +27 -0
  209. data/test/unit/search/tc_spans.rb +190 -0
  210. data/test/unit/search/tm_searcher.rb +436 -0
  211. data/test/unit/store/tc_fs_store.rb +115 -0
  212. data/test/unit/store/tc_ram_store.rb +35 -0
  213. data/test/unit/store/tm_store.rb +34 -0
  214. data/test/unit/store/tm_store_lock.rb +68 -0
  215. data/test/unit/tc_document.rb +81 -0
  216. data/test/unit/tc_field_symbol.rb +26 -0
  217. data/test/unit/ts_analysis.rb +2 -0
  218. data/test/unit/ts_index.rb +2 -0
  219. data/test/unit/ts_largefile.rb +4 -0
  220. data/test/unit/ts_query_parser.rb +2 -0
  221. data/test/unit/ts_search.rb +2 -0
  222. data/test/unit/ts_store.rb +2 -0
  223. data/test/unit/ts_utils.rb +2 -0
  224. data/test/unit/utils/tc_bit_vector.rb +295 -0
  225. data/test/unit/utils/tc_number_tools.rb +117 -0
  226. data/test/unit/utils/tc_priority_queue.rb +106 -0
  227. data/test/utils/content_generator.rb +226 -0
  228. metadata +319 -0
data/ext/hashset.c ADDED
@@ -0,0 +1,192 @@
1
+ #include "hashset.h"
2
+ #include <string.h>
3
+ #include "internal.h"
4
+
5
+ /*
6
+ * The HashSet contains an array +elems+ of the elements that have been added.
7
+ * It always has +size+ elements so +size+ ane +elems+ can be used to iterate
8
+ * over all alements in the HashSet. It also uses a Hash to keep track of
9
+ * which elements have been added and their index in the +elems+ array.
10
+ */
11
+ static HashSet *hs_alloc(free_ft free_func)
12
+ {
13
+ HashSet *hs = ALLOC(HashSet);
14
+ hs->size = 0;
15
+ hs->first = hs->last = NULL;
16
+ hs->free_elem_i = free_func ? free_func : &dummy_free;
17
+ return hs;
18
+ }
19
+
20
+ HashSet *hs_new(hash_ft hash_func, eq_ft eq_func, free_ft free_func)
21
+ {
22
+ HashSet *hs = hs_alloc(free_func);
23
+ hs->ht = h_new(hash_func, eq_func, NULL, NULL);
24
+ return hs;
25
+ }
26
+
27
+ HashSet *hs_new_str(free_ft free_func)
28
+ {
29
+ HashSet *hs = hs_alloc(free_func);
30
+ hs->ht = h_new_str((free_ft) NULL, NULL);
31
+ return hs;
32
+ }
33
+
34
+ HashSet *hs_new_ptr(free_ft free_func)
35
+ {
36
+ HashSet *hs = hs_alloc(free_func);
37
+ hs->ht = h_new_ptr(NULL);
38
+ return hs;
39
+ }
40
+
41
+ static INLINE void clear(HashSet *hs, bool destroy)
42
+ {
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);
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);
65
+ }
66
+
67
+ void hs_destroy(HashSet *hs)
68
+ {
69
+ clear(hs, true);
70
+ h_destroy(hs->ht);
71
+ free(hs);
72
+ }
73
+
74
+ static INLINE void append(HashSet *hs, void *elem)
75
+ {
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;
82
+ }
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
+
105
+ /* add the elem to the array, resizing if necessary */
106
+ case HASH_KEY_DOES_NOT_EXIST:
107
+ break;
108
+
109
+ }
110
+
111
+ append(hs, elem);
112
+ return has_elem;
113
+ }
114
+
115
+ int hs_add_safe(HashSet *hs, void *elem)
116
+ {
117
+ switch(h_has_key(hs->ht, elem))
118
+ {
119
+ /* element can't be added */
120
+ case HASH_KEY_EQUAL: return false;
121
+
122
+ /* the exact same element has already been added */
123
+ case HASH_KEY_SAME : return true;
124
+
125
+ /* add the elem to the array, resizing if necessary */
126
+ case HASH_KEY_DOES_NOT_EXIST : break;
127
+ }
128
+ append(hs, elem);
129
+ return true;
130
+ }
131
+
132
+ void *hs_rem(HashSet *hs, const void *elem)
133
+ {
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;
148
+ }
149
+ else {
150
+ entry->prev->next = entry->next;
151
+ entry->next->prev = entry->prev;
152
+ }
153
+ return_elem = entry->elem;
154
+ h_del(hs->ht, return_elem);
155
+ free(entry);
156
+ hs->size--;
157
+ return return_elem;
158
+ }
159
+
160
+ int hs_del(HashSet *hs, const void *elem)
161
+ {
162
+ void *tmp_elem = hs_rem(hs, elem);
163
+ if (tmp_elem != NULL) {
164
+ hs->free_elem_i(tmp_elem);
165
+ return 1;
166
+ }
167
+ return 0;
168
+ }
169
+
170
+ HashKeyStatus hs_exists(HashSet *hs, const void *elem)
171
+ {
172
+ return h_has_key(hs->ht, elem);
173
+ }
174
+
175
+ HashSet *hs_merge(HashSet *hs, HashSet * other)
176
+ {
177
+ HashSetEntry *entry = other->first;
178
+ for (; entry != NULL; entry = entry->next) {
179
+ hs_add(hs, entry->elem);
180
+ }
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. */
184
+ hs_free(other);
185
+ return hs;
186
+ }
187
+
188
+ void *hs_orig(HashSet *hs, const void *elem)
189
+ {
190
+ HashSetEntry *entry = (HashSetEntry *)h_get(hs->ht, elem);
191
+ return entry ? entry->elem : NULL;
192
+ }
data/ext/hashset.h ADDED
@@ -0,0 +1,215 @@
1
+ #ifndef FRT_HASHSET_H
2
+ #define FRT_HASHSET_H
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include "hash.h"
9
+ #include "global.h"
10
+
11
+ #define FRT_HS_MIN_SIZE 4
12
+ typedef struct FrtHashSetEntry {
13
+ void *elem;
14
+ struct FrtHashSetEntry *next;
15
+ struct FrtHashSetEntry *prev;
16
+ } FrtHashSetEntry;
17
+
18
+ typedef struct FrtHashSet
19
+ {
20
+ /* the number of elements in the instance */
21
+ int size;
22
+
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;
27
+
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;
31
+
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;
38
+
39
+ /**
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.
43
+ *
44
+ * @param hash function to hash objects added to the FrtHashSet
45
+ * @param eq function to determine whether two items are equal
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
62
+ */
63
+ extern FrtHashSet *frt_hs_new_str(frt_free_ft free_func);
64
+
65
+ /**
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.
70
+ *
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
74
+ */
75
+ extern FrtHashSet *frt_hs_new_ptr(frt_free_ft free_func);
76
+
77
+ /**
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
81
+ *
82
+ * @param hs the FrtHashSet to free
83
+ */
84
+ extern void frt_hs_free(FrtHashSet *self);
85
+
86
+ /**
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
90
+ *
91
+ * @param hs the FrtHashSet to destroy
92
+ */
93
+ extern void frt_hs_destroy(FrtHashSet *self);
94
+
95
+ /**
96
+ * WARNING: this function may destroy some elements if you add them to a
97
+ * FrtHashSet were equivalent elements already exist, depending on how free_elem
98
+ * was set.
99
+ *
100
+ * Add the element to the FrtHashSet whether or not it was already in the
101
+ * FrtHashSet.
102
+ *
103
+ * When a element is added to the Hash where it already exists, free_elem
104
+ * is called on it, ie the element you tried to add might get destroyed.
105
+ *
106
+ * @param hs the FrtHashSet to add the element to
107
+ * @param elem the element to add to the FrtHashSet
108
+ * @return one of three values;
109
+ * <pre>
110
+ * HASH_KEY_DOES_NOT_EXIST the element was not already in the FrtHashSet.
111
+ * This value is equal to 0 or false
112
+ * HASH_KEY_SAME the element was identical (same memory
113
+ * pointer) to an existing element so no freeing
114
+ * was done
115
+ * HASH_KEY_EQUAL the element was equal to an element already in
116
+ * the FrtHashSet so the new_elem was freed if
117
+ * free_elem was set
118
+ * </pre>
119
+ */
120
+ extern FrtHashKeyStatus frt_hs_add(FrtHashSet *self, void *elem);
121
+
122
+ /**
123
+ * Add element to the FrtHashSet. If the element already existed in the FrtHashSet
124
+ * and the new element was equal but not the same (same pointer/memory) then
125
+ * don't add the element and return false, otherwise return true.
126
+ *
127
+ * @param hs the FrtHashSet to add the element to
128
+ * @param elem the element to add to the FrtHashSet
129
+ * @return true if the element was successfully added or false otherwise
130
+ */
131
+ extern int frt_hs_add_safe(FrtHashSet *self, void *elem);
132
+
133
+ /**
134
+ * Delete the element from the FrtHashSet. Returns true if the item was
135
+ * successfully deleted or false if the element never existed.
136
+ *
137
+ * @param hs the FrtHashSet to delete from
138
+ * @param elem the element to delete
139
+ * @return true if the element was deleted or false if the element never
140
+ * existed
141
+ */
142
+ extern int frt_hs_del(FrtHashSet *self, const void *elem);
143
+
144
+ /**
145
+ * Remove an item from the FrtHashSet without actually freeing the item. This
146
+ * function should return the item itself so that it can be freed later if
147
+ * necessary.
148
+ *
149
+ * @param hs the FrtHashSet to remove the element from.
150
+ * @param elem the element to remove
151
+ * @param the element that was removed or NULL otherwise
152
+ */
153
+ extern void *frt_hs_rem(FrtHashSet *self, const void *elem);
154
+
155
+ /**
156
+ * Check if the element exists and return the appropriate value described
157
+ * bellow.
158
+ *
159
+ * @param hs the FrtHashSet to check in
160
+ * @param elem the element to check for
161
+ * @return one of the following values
162
+ * <pre>
163
+ * HASH_KEY_DOES_NOT_EXIST the element was not already in the FrtHashSet.
164
+ * This value is equal to 0 or false
165
+ * HASH_KEY_SAME the element was identical (same memory
166
+ * pointer) to an existing element so no freeing
167
+ * was done
168
+ * HASH_KEY_EQUAL the element was equal to an element already in
169
+ * the FrtHashSet so the new_elem was freed if
170
+ * free_elem was set
171
+ * </pre>
172
+ */
173
+ extern FrtHashKeyStatus frt_hs_exists(FrtHashSet *self, const void *elem);
174
+
175
+ /**
176
+ * Merge two HashSets. When a merge is done the merger (self) Hash is
177
+ * returned and the mergee is destroyed. All elements from mergee that were
178
+ * not found in merger (self) will be added to self, otherwise they will be
179
+ * destroyed.
180
+ *
181
+ * @param self the FrtHashSet to merge into
182
+ * @param other HastSet to be merged into self
183
+ * @return the merged FrtHashSet
184
+ */
185
+ extern FrtHashSet *frt_hs_merge(FrtHashSet *self, FrtHashSet *other);
186
+
187
+ /**
188
+ * Return the original version of +elem+. So if you allocate two elements
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.
191
+ */
192
+ extern void *frt_hs_orig(FrtHashSet *self, const void *elem);
193
+
194
+ /**
195
+ * Clear all elements from the FrtHashSet. If free_elem was set then use it to
196
+ * free all elements as they are cleared. After the method is called, the
197
+ * HashSets size will be 0.
198
+ *
199
+ * @param self the FrtHashSet to clear
200
+ */
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);
209
+ */
210
+
211
+ #ifdef __cplusplus
212
+ } // extern "C"
213
+ #endif
214
+
215
+ #endif
data/ext/header.h ADDED
@@ -0,0 +1,58 @@
1
+
2
+ #include <limits.h>
3
+
4
+ #include "api.h"
5
+
6
+ #define MAXINT INT_MAX
7
+ #define MININT INT_MIN
8
+
9
+ #define HEAD 2*sizeof(int)
10
+
11
+ #define SIZE(p) ((int *)(p))[-1]
12
+ #define SET_SIZE(p, n) ((int *)(p))[-1] = n
13
+ #define CAPACITY(p) ((int *)(p))[-2]
14
+
15
+ struct among
16
+ { int s_size; /* number of chars in string */
17
+ const symbol * s; /* search string */
18
+ int substring_i;/* index to longest matching substring */
19
+ int result; /* result of the lookup */
20
+ int (* function)(struct SN_env *);
21
+ };
22
+
23
+ extern symbol * create_s(void);
24
+ extern void lose_s(symbol * p);
25
+
26
+ extern int skip_utf8(const symbol * p, int c, int lb, int l, int n);
27
+
28
+ extern int in_grouping_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
29
+ extern int in_grouping_b_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
30
+ extern int out_grouping_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
31
+ extern int out_grouping_b_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
32
+
33
+ extern int in_grouping(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
34
+ extern int in_grouping_b(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
35
+ extern int out_grouping(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
36
+ extern int out_grouping_b(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
37
+
38
+ extern int eq_s(struct SN_env * z, int s_size, const symbol * s);
39
+ extern int eq_s_b(struct SN_env * z, int s_size, const symbol * s);
40
+ extern int eq_v(struct SN_env * z, const symbol * p);
41
+ extern int eq_v_b(struct SN_env * z, const symbol * p);
42
+
43
+ extern int find_among(struct SN_env * z, const struct among * v, int v_size);
44
+ extern int find_among_b(struct SN_env * z, const struct among * v, int v_size);
45
+
46
+ extern int replace_s(struct SN_env * z, int c_bra, int c_ket, int s_size, const symbol * s, int * adjustment);
47
+ extern int slice_from_s(struct SN_env * z, int s_size, const symbol * s);
48
+ extern int slice_from_v(struct SN_env * z, const symbol * p);
49
+ extern int slice_del(struct SN_env * z);
50
+
51
+ extern int insert_s(struct SN_env * z, int bra, int ket, int s_size, const symbol * s);
52
+ extern int insert_v(struct SN_env * z, int bra, int ket, const symbol * p);
53
+
54
+ extern symbol * slice_to(struct SN_env * z, symbol * p);
55
+ extern symbol * assign_to(struct SN_env * z, symbol * p);
56
+
57
+ extern void debug(struct SN_env * z, int number, int line_count);
58
+