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
data/ext/hash.h CHANGED
@@ -1,47 +1,51 @@
1
1
  #ifndef FRT_HASH_H
2
2
  #define FRT_HASH_H
3
3
 
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
4
8
  #include "global.h"
5
9
 
6
10
  /****************************************************************************
7
11
  *
8
- * HashTable
12
+ * Hash
9
13
  *
10
14
  ****************************************************************************/
11
15
 
12
- #define HASH_MINSIZE 8
13
- #define SLOW_DOWN 50000 /* stop increasing the hash table so quickly to
16
+ #define FRT_HASH_MINSIZE 8
17
+ #define FRT_SLOW_DOWN 50000 /* stop increasing the hash table so quickly to
14
18
  * conserve memory */
15
19
 
16
20
  /**
17
21
  * Return values for h_set
18
22
  */
19
- enum HashSetValues
23
+ typedef enum
20
24
  {
21
- HASH_KEY_DOES_NOT_EXIST = 0,
22
- HASH_KEY_EQUAL = 1,
23
- HASH_KEY_SAME = 2
24
- };
25
+ FRT_HASH_KEY_DOES_NOT_EXIST = 0,
26
+ FRT_HASH_KEY_EQUAL = 1,
27
+ FRT_HASH_KEY_SAME = 2
28
+ } FrtHashKeyStatus;
25
29
 
26
30
  /**
27
- * struct used internally to store values in the HashTable
31
+ * struct used internally to store values in the Hash
28
32
  */
29
33
  typedef struct
30
34
  {
31
35
  unsigned long hash;
32
36
  void *key;
33
37
  void *value;
34
- } HashEntry;
38
+ } FrtHashEntry;
35
39
 
36
40
  /**
37
41
  * As the hash table is filled and entries are deleted, Dummy HashEntries are
38
42
  * put in place. We therefor keep two counts. +size+ is the number active
39
43
  * elements and +fill+ is the number of active elements together with the
40
44
  * number of dummy elements. +fill+ is basically just kept around so that we
41
- * know when to resize. The HashTable is resized when more than two thirds of
42
- * the HashTable is Filled.
45
+ * know when to resize. The Hash is resized when more than two thirds of
46
+ * the Hash is Filled.
43
47
  */
44
- typedef struct HashTable
48
+ typedef struct FrtHash
45
49
  {
46
50
  int fill; /* num Active + num Dummy */
47
51
  int size; /* num Active ie, num keys set */
@@ -50,36 +54,37 @@ typedef struct HashTable
50
54
 
51
55
  /* table points to smalltable initially. If the table grows beyond 2/3 of
52
56
  * HASH_MINSIZE it will point to newly malloced memory as it grows. */
53
- HashEntry *table;
57
+ FrtHashEntry *table;
54
58
 
55
- /* When a HashTable is created it needs an initial table to start if off.
56
- * All HashTables will start with smalltable and then malloc a larger
57
- * table as the HashTable grows */
58
- HashEntry smalltable[HASH_MINSIZE];
59
+ /* When a Hash is created it needs an initial table to start if off.
60
+ * All Hashs will start with smalltable and then malloc a larger
61
+ * table as the Hash grows */
62
+ FrtHashEntry smalltable[FRT_HASH_MINSIZE];
59
63
 
60
64
  /* the following function pointers are used internally and should not be
61
- * used outside of the HashTable methods */
62
- HashEntry *(*lookup_i)(struct HashTable *self, register const void *key);
65
+ * used outside of the Hash methods */
66
+ FrtHashEntry *(*lookup_i)(struct FrtHash *self,
67
+ register const void *key);
63
68
  unsigned long (*hash_i)(const void *key);
64
69
  int (*eq_i)(const void *key1, const void *key2);
65
70
  void (*free_key_i)(void *p);
66
71
  void (*free_value_i)(void *p);
67
- } HashTable;
72
+ } FrtHash;
68
73
 
69
74
  /**
70
- * Hashing function type used by HashTable. A function of this type must be
71
- * passed to create a new HashTable.
75
+ * Hashing function type used by Hash. A function of this type must be
76
+ * passed to create a new Hash.
72
77
  *
73
78
  * @param key object to hash
74
79
  * @return an unsigned 32-bit integer hash value
75
80
  */
76
- typedef unsigned long (*hash_ft)(const void *key);
81
+ typedef unsigned long (*frt_hash_ft)(const void *key);
77
82
 
78
83
  /**
79
- * Equals function type used by HashTable. A function of this type must be
80
- * passed to create a new HashTable.
84
+ * Equals function type used by Hash. A function of this type must be
85
+ * passed to create a new Hash.
81
86
  */
82
- typedef int (*eq_ft)(const void *key1, const void *key2);
87
+ typedef int (*frt_eq_ft)(const void *key1, const void *key2);
83
88
 
84
89
  /**
85
90
  * Determine a hash value for a string. The string must be null terminated
@@ -87,7 +92,7 @@ typedef int (*eq_ft)(const void *key1, const void *key2);
87
92
  * @param str string to hash
88
93
  * @return an unsigned long integer hash value
89
94
  */
90
- extern unsigned long str_hash(const char *const str);
95
+ extern unsigned long frt_str_hash(const char *const str);
91
96
 
92
97
  /**
93
98
  * Determine a hash value for a pointer. Just cast the pointer to an unsigned
@@ -96,7 +101,7 @@ extern unsigned long str_hash(const char *const str);
96
101
  * @param ptr pointer to hash
97
102
  * @return an unsigned long integer hash value
98
103
  */
99
- extern unsigned long ptr_hash(const void *const ptr);
104
+ extern unsigned long frt_ptr_hash(const void *const ptr);
100
105
 
101
106
  /**
102
107
  * Determine if two pointers point to the same point in memory.
@@ -105,137 +110,151 @@ extern unsigned long ptr_hash(const void *const ptr);
105
110
  * @param q2 second pointer
106
111
  * @return true if the pointers are equal
107
112
  */
108
- extern int ptr_eq(const void *q1, const void *q2);
113
+ extern int frt_ptr_eq(const void *q1, const void *q2);
109
114
 
110
115
  /**
111
- * Create a new HashTable that uses any type of object as it's key. The
112
- * HashTable will store all keys and values so if you want to destroy those
113
- * values when the HashTable is destroyed then you should pass free functions.
116
+ * Create a new Hash that uses any type of object as its key. The
117
+ * Hash will store all keys and values so if you want to destroy those
118
+ * values when the Hash is destroyed then you should pass free functions.
114
119
  * NULL will suffice otherwise.
115
120
  *
116
- * @param hash function to determine the hash value of a key in the HashTable
117
- * @param eq function to determine the equality of to keys in the HashTable
118
- * @param free_key function to free the key stored in the HashTable when an
119
- * entry is deleted, replaced or when the HashTable is destroyed. If you
121
+ * @param hash function to determine the hash value of a key in the Hash
122
+ * @param eq function to determine the equality of to keys in the Hash
123
+ * @param free_key function to free the key stored in the Hash when an
124
+ * entry is deleted, replaced or when the Hash is destroyed. If you
120
125
  * pass NULL in place of this parameter the key will not be destroyed.
121
- * @param free_value function to free the value stored in the HashTable when
122
- * an entry is deleted, replaced or when the HashTable is destroyed. If you
126
+ * @param free_value function to free the value stored in the Hash when
127
+ * an entry is deleted, replaced or when the Hash is destroyed. If you
123
128
  * pass NULL in place of this parameter the value will not be destroyed.
124
- * @return A newly allocated HashTable
129
+ * @return A newly allocated Hash
125
130
  */
126
- extern HashTable *h_new(hash_ft hash, eq_ft eq, free_ft free_key,
127
- free_ft free_value);
131
+ extern FrtHash *frt_h_new(frt_hash_ft hash,
132
+ frt_eq_ft eq,
133
+ frt_free_ft free_key,
134
+ frt_free_ft free_value);
128
135
 
129
136
  /**
130
- * Create a new HashTable that uses null-terminated strings as it's keys. The
131
- * HashTable will store all keys and values so if you want to destroy those
132
- * values when the HashTable is destroyed then you should pass free functions.
137
+ * Create a new Hash that uses null-terminated strings as its keys. The
138
+ * Hash will store all keys and values so if you want to destroy those
139
+ * values when the Hash is destroyed then you should pass free functions.
133
140
  * NULL will suffice otherwise.
134
141
  *
135
- * @param free_key function to free the key stored in the HashTable when an
136
- * entry is deleted, replaced or when the HashTable is destroyed. If you
142
+ * @param free_key function to free the key stored in the Hash when an
143
+ * entry is deleted, replaced or when the Hash is destroyed. If you
137
144
  * pass NULL in place of this parameter the key will not be destroyed.
138
- * @param free_value function to free the value stored in the HashTable when
139
- * an entry is deleted, replaced or when the HashTable is destroyed. If you
145
+ * @param free_value function to free the value stored in the Hash when
146
+ * an entry is deleted, replaced or when the Hash is destroyed. If you
140
147
  * pass NULL in place of this parameter the value will not be destroyed.
141
- * @return A newly allocated HashTable
148
+ * @return A newly allocated Hash
142
149
  */
143
- extern HashTable *h_new_str(free_ft free_key, free_ft free_value);
150
+ extern FrtHash *frt_h_new_str(frt_free_ft free_key,
151
+ frt_free_ft free_value);
144
152
 
145
153
  /**
146
- * Create a new HashTable that uses integers as it's keys. The
147
- * HashTable will store all values so if you want to destroy those
148
- * values when the HashTable is destroyed then you should pass a free function.
149
- * NULL will suffice otherwise.
154
+ * Create a new Hash that uses integers as its keys. The Hash will store all
155
+ * values so if you want to destroy those values when the Hash is destroyed
156
+ * then you should pass a free function. NULL will suffice otherwise.
157
+ *
158
+ * @param free_value function to free the value stored in the Hash when
159
+ * an entry is deleted, replaced or when the Hash is destroyed. If you
160
+ * pass NULL in place of this parameter the value will not be destroyed.
161
+ * @return A newly allocated Hash
162
+ */
163
+ extern FrtHash *frt_h_new_int(frt_free_ft free_value);
164
+
165
+ /**
166
+ * Create a new Hash that uses pointers as its keys. The Hash will store all
167
+ * values so if you want to destroy those values when the Hash is destroyed
168
+ * then you should pass a free function. NULL will suffice otherwise.
150
169
  *
151
- * @param free_value function to free the value stored in the HashTable when
152
- * an entry is deleted, replaced or when the HashTable is destroyed. If you
170
+ * @param free_value function to free the value stored in the Hash when
171
+ * an entry is deleted, replaced or when the Hash is destroyed. If you
153
172
  * pass NULL in place of this parameter the value will not be destroyed.
154
- * @return A newly allocated HashTable
173
+ * @return A newly allocated Hash
155
174
  */
156
- extern HashTable *h_new_int(free_ft free_value);
175
+ #define frt_h_new_ptr(free_value) frt_h_new_int(free_value)
157
176
 
158
177
  /**
159
- * Destroy the HashTable. This function will also destroy all keys and values
160
- * in the HashTable depending on how the free_key and free_value were set.
178
+ * Destroy the Hash. This function will also destroy all keys and values
179
+ * in the Hash depending on how the free_key and free_value were set.
161
180
  *
162
- * @param self the HashTable to destroy
181
+ * @param self the Hash to destroy
163
182
  */
164
- extern void h_destroy(HashTable *self);
183
+ extern void frt_h_destroy(FrtHash *self);
165
184
 
166
185
  /**
167
- * Clear the HashTable. This function will delete all keys and values from the
168
- * hash table, also destroying all keys and values in the HashTable depending
186
+ * Clear the Hash. This function will delete all keys and values from the
187
+ * hash table, also destroying all keys and values in the Hash depending
169
188
  * on how the free_key and free_value were set.
170
189
  *
171
- * @param self the HashTable to clear
190
+ * @param self the Hash to clear
172
191
  */
173
- extern void h_clear(HashTable *self);
192
+ extern void frt_h_clear(FrtHash *self);
174
193
 
175
194
  /**
176
- * Get the value in the HashTable referenced by the key +key+.
195
+ * Get the value in the Hash referenced by the key +key+.
177
196
  *
178
- * @param self the HashTable to reference
197
+ * @param self the Hash to reference
179
198
  * @param key the key to lookup
180
199
  * @return the value referenced by the key +key+. If there is no value
181
200
  * referenced by that key, NULL is returned.
182
201
  */
183
- extern void *h_get(HashTable *self, const void *key);
202
+ extern void *frt_h_get(FrtHash *self, const void *key);
184
203
 
185
204
  /**
186
- * Delete the value in HashTable referenced by the key +key+. When the value
205
+ * Delete the value in Hash referenced by the key +key+. When the value
187
206
  * is deleted it is also destroyed along with the key depending on how
188
- * free_key and free_value where set when the HashTable was created. If you
189
- * don't want to destroy the value use h_rem.
207
+ * free_key and free_value where set when the Hash was created. If you
208
+ * don't want to destroy the value use h_rem.
190
209
  *
191
210
  * This functions returns +true+ if the value was deleted successfully or
192
211
  * false if the key was not found.
193
212
  *
194
213
  * @see h_rem
195
214
  *
196
- * @param self the HashTable to reference
215
+ * @param self the Hash to reference
197
216
  * @param key the key to lookup
198
217
  * @return true if the object was successfully deleted or false if the key was
199
218
  * not found
200
219
  */
201
- extern int h_del(HashTable *self, const void *key);
220
+ extern int frt_h_del(FrtHash *self, const void *key);
202
221
 
203
222
  /**
204
- * Remove the value in HashTable referenced by the key +key+. When the value
223
+ * Remove the value in Hash referenced by the key +key+. When the value
205
224
  * is removed it is returned rather than destroyed. The key however is
206
- * destroyed using the free_key functions passed when the HashTable is created
225
+ * destroyed using the free_key functions passed when the Hash is created
207
226
  * if del_key is true.
208
227
  *
209
228
  * If you want the value to be destroyed, use the h_del function.
210
229
  *
211
230
  * @see h_del
212
231
  *
213
- * @param self the HashTable to reference
232
+ * @param self the Hash to reference
214
233
  * @param key the key to lookup
215
234
  * @param del_key set to true if you want the key to be deleted when the value
216
- * is removed from the HashTable
235
+ * is removed from the Hash
217
236
  * @return the value referenced by +key+ if it can be found or NULL otherwise
218
237
  */
219
- extern void *h_rem(HashTable *self, const void *key, bool del_key);
238
+ extern void *frt_h_rem(FrtHash *self, const void *key, bool del_key);
220
239
 
221
240
  /**
222
241
  * WARNING: this function may destroy an old value or key if the key already
223
- * exists in the HashTable, depending on how free_value and free_key were set
224
- * for this HashTable.
242
+ * exists in the Hash, depending on how free_value and free_key were set
243
+ * for this Hash.
225
244
  *
226
- * Add the value +value+ to the HashTable referencing it with key +key+.
245
+ * Add the value +value+ to the Hash referencing it with key +key+.
227
246
  *
228
- * When a value is added to the HashTable it replaces any value that
247
+ * When a value is added to the Hash it replaces any value that
229
248
  * might already be stored under that key. If free_value is already set then
230
249
  * the old value will be freed using that function.
231
250
  *
232
251
  * Similarly the old key might replace be replaced by the new key if they are
233
- * are equal (according to the HashTable's eq function) but seperately
252
+ * are equal (according to the Hash's eq function) but seperately
234
253
  * allocated objects.
235
254
  *
236
- * @param self the HashTable to add the value to
255
+ * @param self the Hash to add the value to
237
256
  * @param key the key to use to reference the value
238
- * @param value the value to add to the HashTable
257
+ * @param value the value to add to the Hash
239
258
  * @return one of three values;
240
259
  * <pre>
241
260
  * HASH_KEY_DOES_NOT_EXIST there was no value stored with that key
@@ -246,19 +265,20 @@ extern void *h_rem(HashTable *self, const void *key, bool del_key);
246
265
  * the existing key so no key was freed
247
266
  * </pre>
248
267
  */
249
- extern int h_set(HashTable *self, const void *key, void *value);
268
+ extern FrtHashKeyStatus frt_h_set(FrtHash *self,
269
+ const void *key, void *value);
250
270
 
251
271
  /**
252
- * Add the value +value+ to the HashTable referencing it with key +key+. If
253
- * the key already exists in the HashTable, the value won't be added and the
272
+ * Add the value +value+ to the Hash referencing it with key +key+. If
273
+ * the key already exists in the Hash, the value won't be added and the
254
274
  * function will return false. Otherwise it will return true.
255
275
  *
256
- * @param self the HashTable to add the value to
276
+ * @param self the Hash to add the value to
257
277
  * @param key the key to use to reference the value
258
- * @param value the value to add to the HashTable
278
+ * @param value the value to add to the Hash
259
279
  * @return true if the value was successfully added or false otherwise
260
280
  */
261
- extern int h_set_safe(HashTable *self, const void *key, void *value);
281
+ extern int frt_h_set_safe(FrtHash *self, const void *key, void *value);
262
282
 
263
283
  /**
264
284
  * Return a hash entry object so you can handle the insert yourself. This can
@@ -267,81 +287,95 @@ extern int h_set_safe(HashTable *self, const void *key, void *value);
267
287
  * new array if non-existed, you could use this method by checking the value
268
288
  * of the HashEntry returned.
269
289
  *
270
- * @param self the HashTable to add the value to
290
+ * @param self the Hash to add the value to
271
291
  * @param key the key to use to reference the value
272
- * @return HashEntry a pointer to the hash entry object now reserved for this
292
+ * @param he HashEntry a pointer to the hash entry object now reserved for this
273
293
  * value. Be sure to set both the *key* and the *value*
294
+ * @return true if the key was empty, false otherwise
274
295
  */
275
- extern HashEntry *h_set_ext(HashTable *ht, const void *key);
296
+ extern FRT_INLINE bool frt_h_set_ext(FrtHash *self,
297
+ const void *key,
298
+ FrtHashEntry **he);
276
299
 
277
300
  /**
278
- * Check whether key +key+ exists in the HashTable.
301
+ * Check whether key +key+ exists in the Hash.
279
302
  *
280
- * @param self the HashTable to check in
281
- * @param key the key to check for in the HashTable
282
- * @return true if the key exists in the HashTable, false otherwise.
303
+ * @param self the Hash to check in
304
+ * @param key the key to check for in the Hash
305
+ * @return one of three values;
306
+ * <pre>
307
+ * 0 - HASH_KEY_DOES_NOT_EXIST there was no value stored with that key
308
+ * 1 - HASH_KEY_EQUAL the key existed and was seperately
309
+ * allocated.
310
+ * 2 - HASH_KEY_SAME the key was identical (same memory
311
+ * pointer) to the existing key so no key was
312
+ * freed
313
+ * </pre>
314
+ * Note: the return value can be treated as a true/false value, ie 0 if the
315
+ * key doesn't exist, non-zero if it does.
283
316
  */
284
- extern int h_has_key(HashTable *self, const void *key);
317
+ extern FrtHashKeyStatus frt_h_has_key(FrtHash *self,
318
+ const void *key);
285
319
 
286
320
  /**
287
- * Get the value in the HashTable referenced by an integer key +key+.
321
+ * Get the value in the Hash referenced by an integer key +key+.
288
322
  *
289
- * @param self the HashTable to reference
323
+ * @param self the Hash to reference
290
324
  * @param key the integer key to lookup
291
325
  * @return the value referenced by the key +key+. If there is no value
292
326
  * referenced by that key, NULL is returned.
293
327
  */
294
- extern void *h_get_int(HashTable *self, const unsigned long key);
328
+ extern void *frt_h_get_int(FrtHash *self, const unsigned long key);
295
329
 
296
330
  /**
297
- * Delete the value in HashTable referenced by the integer key +key+. When the
331
+ * Delete the value in Hash referenced by the integer key +key+. When the
298
332
  * value is deleted it is also destroyed using the free_value function. If you
299
- * don't want to destroy the value use h_rem.
333
+ * don't want to destroy the value use h_rem.
300
334
  *
301
335
  * This functions returns +true+ if the value was deleted successfully or
302
336
  * false if the key was not found.
303
337
  *
304
338
  * @see h_rem
305
339
  *
306
- * @param self the HashTable to reference
340
+ * @param self the Hash to reference
307
341
  * @param key the integer key to lookup
308
342
  * @return true if the object was successfully deleted or false if the key was
309
343
  * not found
310
344
  */
311
- extern int h_del_int(HashTable *self, const unsigned long key);
345
+ extern int frt_h_del_int(FrtHash *self, const unsigned long key);
312
346
 
313
347
  /**
314
- * Remove the value in HashTable referenced by the integer key +key+. When the
348
+ * Remove the value in Hash referenced by the integer key +key+. When the
315
349
  * value is removed it is returned rather than destroyed.
316
350
  *
317
351
  * If you want the value to be destroyed, use the h_del function.
318
352
  *
319
353
  * @see h_del
320
354
  *
321
- * @param self the HashTable to reference
355
+ * @param self the Hash to reference
322
356
  * @param key the integer key to lookup
323
357
  * @return the value referenced by +key+ if it can be found or NULL otherwise
324
358
  */
325
- extern void *h_rem_int(HashTable *self, const unsigned long key);
359
+ extern void *frt_h_rem_int(FrtHash *self, const unsigned long key);
326
360
 
327
361
  /**
328
362
  * WARNING: this function may destroy an old value if the key already exists
329
- * in the HashTable, depending on how free_value was set for this HashTable.
363
+ * in the Hash, depending on how free_value was set for this Hash.
330
364
  *
331
- * Add the value +value+ to the HashTable referencing it with an integer key
365
+ * Add the value +value+ to the Hash referencing it with an integer key
332
366
  * +key+.
333
367
  *
334
- * When a value is added to the HashTable it replaces any value that
368
+ * When a value is added to the Hash it replaces any value that
335
369
  * might already be stored under that key. If free_value is already set then
336
370
  * the old value will be freed using that function.
337
371
  *
338
372
  * Similarly the old key might replace be replaced by the new key if they are
339
- * are equal (according to the HashTable's eq function) but seperately
373
+ * are equal (according to the Hash's eq function) but seperately
340
374
  * allocated objects.
341
375
  *
342
- * @param self the HashTable to add the value to
376
+ * @param self the Hash to add the value to
343
377
  * @param key the integer key to use to reference the value
344
- * @param value the value to add to the HashTable
378
+ * @param value the value to add to the Hash
345
379
  * @return one of three values;
346
380
  * <pre>
347
381
  * HASH_KEY_DOES_NOT_EXIST there was no value stored with that key
@@ -352,38 +386,42 @@ extern void *h_rem_int(HashTable *self, const unsigned long key);
352
386
  * the existing key so no key was freed
353
387
  * </pre>
354
388
  */
355
- extern int h_set_int(HashTable *self, const unsigned long key, void *value);
389
+ extern FrtHashKeyStatus frt_h_set_int(FrtHash *self,
390
+ const unsigned long key,
391
+ void *value);
356
392
 
357
393
  /**
358
- * Add the value +value+ to the HashTable referencing it with integer key
359
- * +key+. If the key already exists in the HashTable, the value won't be added
394
+ * Add the value +value+ to the Hash referencing it with integer key
395
+ * +key+. If the key already exists in the Hash, the value won't be added
360
396
  * and the function will return false. Otherwise it will return true.
361
397
  *
362
- * @param self the HashTable to add the value to
398
+ * @param self the Hash to add the value to
363
399
  * @param key the integer key to use to reference the value
364
- * @param value the value to add to the HashTable
400
+ * @param value the value to add to the Hash
365
401
  * @return true if the value was successfully added or false otherwise
366
402
  */
367
- extern int h_set_safe_int(HashTable *self, const unsigned long key, void *value);
403
+ extern int frt_h_set_safe_int(FrtHash *self,
404
+ const unsigned long key,
405
+ void *value);
368
406
  /**
369
- * Check whether integer key +key+ exists in the HashTable.
407
+ * Check whether integer key +key+ exists in the Hash.
370
408
  *
371
- * @param self the HashTable to check in
372
- * @param key the integer key to check for in the HashTable
373
- * @return true if the key exists in the HashTable, false otherwise.
409
+ * @param self the Hash to check in
410
+ * @param key the integer key to check for in the Hash
411
+ * @return true if the key exists in the Hash, false otherwise.
374
412
  */
375
- extern int h_has_key_int(HashTable *self, const unsigned long key);
413
+ extern int frt_h_has_key_int(FrtHash *self, const unsigned long key);
376
414
 
377
- typedef void (*h_each_key_val_ft)(void *key, void *value, void *arg);
415
+ typedef void (*frt_h_each_key_val_ft)(void *key, void *value, void *arg);
378
416
 
379
417
  /**
380
- * Run function +each_key_val+ on each key and value in the HashTable. The third
418
+ * Run function +each_key_val+ on each key and value in the Hash. The third
381
419
  * argument +arg+ will also be passed to +each_key_val+. If you need to pass
382
420
  * more than one argument to the function you should pass a struct.
383
421
  *
384
422
  * example;
385
423
  *
386
- * // Lets say we have stored strings in a HashTable and we want to put them
424
+ * // Lets say we have stored strings in a Hash and we want to put them
387
425
  * // all into an array. First we need to create a struct to store the
388
426
  * // strings;
389
427
  *
@@ -400,11 +438,11 @@ typedef void (*h_each_key_val_ft)(void *key, void *value, void *arg);
400
438
  * str_arr->cnt++;
401
439
  * }
402
440
  *
403
- * struct StringArray *h_extract_strings(HashTable *ht)
441
+ * struct StringArray *h_extract_strings(Hash *ht)
404
442
  * {
405
- * struct StringArray *str_arr = ALLOC(struct StringArray);
443
+ * struct StringArray *str_arr = FRT_ALLOC(struct StringArray);
406
444
  *
407
- * str_arr->strings = ALLOC_N(char *, ht->size);
445
+ * str_arr->strings = FRT_ALLOC_N(char *, ht->size);
408
446
  * str_arr->cnt = 0;
409
447
  * str_arr->size = ht->size;
410
448
  *
@@ -413,47 +451,34 @@ typedef void (*h_each_key_val_ft)(void *key, void *value, void *arg);
413
451
  * return str_arr;
414
452
  * }
415
453
  *
416
- * @param self the HashTable to run the function on
454
+ * @param self the Hash to run the function on
417
455
  * @param each_key_val function to run on on each key and value in the
418
- * HashTable
456
+ * Hash
419
457
  * @param arg an extra argument to pass to each_key_val each time it is called
420
458
  */
421
- extern void h_each(HashTable *self,
422
- void (*each_key_val)(void *key, void *value, void *arg),
423
- void *arg);
459
+ extern void frt_h_each(FrtHash *self,
460
+ void (*each_key_val)(void *key, void *value, void *arg),
461
+ void *arg);
424
462
 
425
- typedef void *(*h_clone_func_t)(void *val);
463
+ typedef void *(*frt_h_clone_ft)(void *val);
426
464
  /**
427
- * Clone the HashTable as well as cloning each of the keys and values if you
465
+ * Clone the Hash as well as cloning each of the keys and values if you
428
466
  * want to do a deep clone. To do a deep clone you will need to pass a
429
467
  * clone_key function and/or a clone_value function.
430
468
  *
431
- * @param self the HashTable to clone
469
+ * @param self the Hash to clone
432
470
  * @param clone_key the function to clone the key with
433
471
  * @param clone_value the function to clone the value with
434
- * @return a clone of the original HashTable
472
+ * @return a clone of the original Hash
435
473
  */
436
- extern HashTable *h_clone(HashTable *self,
437
- h_clone_func_t clone_key,
438
- h_clone_func_t clone_value);
474
+ extern FrtHash *frt_h_clone(FrtHash *self,
475
+ frt_h_clone_ft clone_key,
476
+ frt_h_clone_ft clone_value);
439
477
 
440
478
  /*
441
- * The following functions should only be used in static HashTable
479
+ * The following functions should only be used in static Hash
442
480
  * declarations
443
481
  */
444
- /**
445
- * This is the lookup function for a hash table keyed with strings. Since it
446
- * is so common for hash tables to be keyed with strings it gets it's own
447
- * lookup function. This method will always return a HashEntry. If there is no
448
- * entry with the given key then an empty entry will be returned with the key
449
- * set to the key that was passed.
450
- *
451
- * @param ht the hash table to look in
452
- * @param key the key to lookup
453
- * @return the HashEntry that was found
454
- */
455
- extern HashEntry *h_lookup_str(HashTable *ht, register const char *key);
456
-
457
482
  /**
458
483
  * This is the lookup function for a hash table with non-string keys. The
459
484
  * hash() and eq() methods used are stored in the hash table. This method will
@@ -464,10 +489,27 @@ extern HashEntry *h_lookup_str(HashTable *ht, register const char *key);
464
489
  * @param key the key to lookup
465
490
  * @return the HashEntry that was found
466
491
  */
467
- extern HashEntry *h_lookup(HashTable *ht, register const void *key);
492
+ extern FrtHashEntry *frt_h_lookup(FrtHash *ht,
493
+ register const void *key);
468
494
 
469
- typedef HashEntry *(*h_lookup_ft)(HashTable *ht, register const void *key);
495
+ typedef FrtHashEntry *(*frt_h_lookup_ft)(FrtHash *ht,
496
+ register const void *key);
470
497
 
471
- extern void h_str_print_keys(HashTable *ht);
498
+ extern void frt_h_str_print_keys(FrtHash *ht, FILE *out);
499
+
500
+ /**
501
+ * The Hash implementation actually keeps a buffer of old hash tables around
502
+ * for performance reasons. If you want all memory freed when your program
503
+ * finishes (useful if you are using valgrind) you should call this method on
504
+ * exit.
505
+ *
506
+ * One way to do this is to register it with atexit(). This is done for you
507
+ * when you call +frt_init+.
508
+ */
509
+ extern void frt_hash_finalize();
510
+
511
+ #ifdef __cplusplus
512
+ } // extern "C"
513
+ #endif
472
514
 
473
515
  #endif