ferret 0.11.6 → 0.11.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -22
- data/RELEASE_CHANGES +137 -0
- data/RELEASE_NOTES +60 -0
- data/Rakefile +379 -274
- data/TODO +100 -8
- data/bin/ferret-browser +0 -0
- data/ext/BZLIB_blocksort.c +1094 -0
- data/ext/BZLIB_bzlib.c +1578 -0
- data/ext/BZLIB_compress.c +672 -0
- data/ext/BZLIB_crctable.c +104 -0
- data/ext/BZLIB_decompress.c +626 -0
- data/ext/BZLIB_huffman.c +205 -0
- data/ext/BZLIB_randtable.c +84 -0
- data/ext/{api.c → STEMMER_api.c} +7 -10
- data/ext/{libstemmer.c → STEMMER_libstemmer.c} +3 -2
- data/ext/{stem_ISO_8859_1_danish.c → STEMMER_stem_ISO_8859_1_danish.c} +123 -124
- data/ext/{stem_ISO_8859_1_dutch.c → STEMMER_stem_ISO_8859_1_dutch.c} +177 -188
- data/ext/STEMMER_stem_ISO_8859_1_english.c +1117 -0
- data/ext/{stem_ISO_8859_1_finnish.c → STEMMER_stem_ISO_8859_1_finnish.c} +276 -306
- data/ext/STEMMER_stem_ISO_8859_1_french.c +1246 -0
- data/ext/{stem_ISO_8859_1_german.c → STEMMER_stem_ISO_8859_1_german.c} +161 -170
- data/ext/STEMMER_stem_ISO_8859_1_hungarian.c +1230 -0
- data/ext/STEMMER_stem_ISO_8859_1_italian.c +1065 -0
- data/ext/STEMMER_stem_ISO_8859_1_norwegian.c +297 -0
- data/ext/{stem_ISO_8859_1_porter.c → STEMMER_stem_ISO_8859_1_porter.c} +263 -290
- data/ext/{stem_ISO_8859_1_portuguese.c → STEMMER_stem_ISO_8859_1_portuguese.c} +362 -380
- data/ext/STEMMER_stem_ISO_8859_1_spanish.c +1093 -0
- data/ext/STEMMER_stem_ISO_8859_1_swedish.c +307 -0
- data/ext/STEMMER_stem_ISO_8859_2_romanian.c +998 -0
- data/ext/{stem_KOI8_R_russian.c → STEMMER_stem_KOI8_R_russian.c} +244 -245
- data/ext/STEMMER_stem_UTF_8_danish.c +339 -0
- data/ext/{stem_UTF_8_dutch.c → STEMMER_stem_UTF_8_dutch.c} +192 -211
- data/ext/STEMMER_stem_UTF_8_english.c +1125 -0
- data/ext/{stem_UTF_8_finnish.c → STEMMER_stem_UTF_8_finnish.c} +284 -324
- data/ext/STEMMER_stem_UTF_8_french.c +1256 -0
- data/ext/{stem_UTF_8_german.c → STEMMER_stem_UTF_8_german.c} +170 -187
- data/ext/STEMMER_stem_UTF_8_hungarian.c +1234 -0
- data/ext/STEMMER_stem_UTF_8_italian.c +1073 -0
- data/ext/STEMMER_stem_UTF_8_norwegian.c +299 -0
- data/ext/{stem_UTF_8_porter.c → STEMMER_stem_UTF_8_porter.c} +271 -310
- data/ext/STEMMER_stem_UTF_8_portuguese.c +1023 -0
- data/ext/STEMMER_stem_UTF_8_romanian.c +1004 -0
- data/ext/STEMMER_stem_UTF_8_russian.c +694 -0
- data/ext/STEMMER_stem_UTF_8_spanish.c +1097 -0
- data/ext/STEMMER_stem_UTF_8_swedish.c +309 -0
- data/ext/STEMMER_stem_UTF_8_turkish.c +2205 -0
- data/ext/{utilities.c → STEMMER_utilities.c} +100 -68
- data/ext/analysis.c +276 -121
- data/ext/analysis.h +190 -143
- data/ext/api.h +3 -4
- data/ext/array.c +5 -3
- data/ext/array.h +52 -43
- data/ext/bitvector.c +38 -482
- data/ext/bitvector.h +446 -124
- data/ext/bzlib.h +282 -0
- data/ext/bzlib_private.h +503 -0
- data/ext/compound_io.c +23 -22
- data/ext/config.h +21 -11
- data/ext/document.c +43 -40
- data/ext/document.h +31 -21
- data/ext/except.c +20 -38
- data/ext/except.h +89 -76
- data/ext/extconf.rb +3 -2
- data/ext/ferret.c +49 -35
- data/ext/ferret.h +14 -11
- data/ext/field_index.c +262 -0
- data/ext/field_index.h +52 -0
- data/ext/filter.c +11 -10
- data/ext/fs_store.c +65 -47
- data/ext/global.c +245 -165
- data/ext/global.h +252 -54
- data/ext/hash.c +200 -243
- data/ext/hash.h +205 -163
- data/ext/hashset.c +118 -96
- data/ext/hashset.h +110 -82
- data/ext/header.h +19 -19
- data/ext/helper.c +11 -10
- data/ext/helper.h +14 -6
- data/ext/index.c +745 -366
- data/ext/index.h +503 -529
- data/ext/internal.h +1020 -0
- data/ext/lang.c +10 -0
- data/ext/lang.h +35 -15
- data/ext/mempool.c +5 -4
- data/ext/mempool.h +30 -22
- data/ext/modules.h +35 -7
- data/ext/multimapper.c +43 -2
- data/ext/multimapper.h +32 -23
- data/ext/posh.c +0 -0
- data/ext/posh.h +4 -38
- data/ext/priorityqueue.c +10 -12
- data/ext/priorityqueue.h +33 -21
- data/ext/q_boolean.c +22 -9
- data/ext/q_const_score.c +3 -2
- data/ext/q_filtered_query.c +15 -12
- data/ext/q_fuzzy.c +147 -135
- data/ext/q_match_all.c +3 -2
- data/ext/q_multi_term.c +28 -32
- data/ext/q_parser.c +451 -173
- data/ext/q_phrase.c +158 -79
- data/ext/q_prefix.c +16 -18
- data/ext/q_range.c +363 -31
- data/ext/q_span.c +130 -141
- data/ext/q_term.c +21 -21
- data/ext/q_wildcard.c +19 -23
- data/ext/r_analysis.c +369 -242
- data/ext/r_index.c +421 -434
- data/ext/r_qparser.c +142 -92
- data/ext/r_search.c +790 -407
- data/ext/r_store.c +44 -44
- data/ext/r_utils.c +264 -96
- data/ext/ram_store.c +29 -23
- data/ext/scanner.c +895 -0
- data/ext/scanner.h +36 -0
- data/ext/scanner_mb.c +6701 -0
- data/ext/scanner_utf8.c +4415 -0
- data/ext/search.c +210 -87
- data/ext/search.h +556 -488
- data/ext/similarity.c +17 -16
- data/ext/similarity.h +51 -44
- data/ext/sort.c +157 -354
- data/ext/stem_ISO_8859_1_hungarian.h +16 -0
- data/ext/stem_ISO_8859_2_romanian.h +16 -0
- data/ext/stem_UTF_8_hungarian.h +16 -0
- data/ext/stem_UTF_8_romanian.h +16 -0
- data/ext/stem_UTF_8_turkish.h +16 -0
- data/ext/stopwords.c +287 -278
- data/ext/store.c +57 -51
- data/ext/store.h +308 -286
- data/ext/symbol.c +10 -0
- data/ext/symbol.h +23 -0
- data/ext/term_vectors.c +14 -293
- data/ext/threading.h +22 -22
- data/ext/win32.h +12 -4
- data/lib/ferret.rb +2 -1
- data/lib/ferret/browser.rb +1 -1
- data/lib/ferret/field_symbol.rb +94 -0
- data/lib/ferret/index.rb +221 -34
- data/lib/ferret/number_tools.rb +6 -6
- data/lib/ferret/version.rb +3 -0
- data/test/{unit → long_running}/largefile/tc_largefile.rb +1 -1
- data/test/test_helper.rb +7 -2
- data/test/test_installed.rb +1 -0
- data/test/threading/thread_safety_index_test.rb +10 -1
- data/test/threading/thread_safety_read_write_test.rb +4 -7
- data/test/threading/thread_safety_test.rb +0 -0
- data/test/unit/analysis/tc_analyzer.rb +29 -27
- data/test/unit/analysis/tc_token_stream.rb +23 -16
- data/test/unit/index/tc_index.rb +116 -11
- data/test/unit/index/tc_index_reader.rb +27 -27
- data/test/unit/index/tc_index_writer.rb +10 -0
- data/test/unit/index/th_doc.rb +38 -21
- data/test/unit/search/tc_filter.rb +31 -10
- data/test/unit/search/tc_index_searcher.rb +6 -0
- data/test/unit/search/tm_searcher.rb +53 -1
- data/test/unit/store/tc_fs_store.rb +40 -2
- data/test/unit/store/tc_ram_store.rb +0 -0
- data/test/unit/store/tm_store.rb +0 -0
- data/test/unit/store/tm_store_lock.rb +7 -6
- data/test/unit/tc_field_symbol.rb +26 -0
- data/test/unit/ts_analysis.rb +0 -0
- data/test/unit/ts_index.rb +0 -0
- data/test/unit/ts_store.rb +0 -0
- data/test/unit/ts_utils.rb +0 -0
- data/test/unit/utils/tc_number_tools.rb +0 -0
- data/test/utils/content_generator.rb +226 -0
- metadata +262 -221
- data/ext/inc/lang.h +0 -48
- data/ext/inc/threading.h +0 -31
- data/ext/stem_ISO_8859_1_english.c +0 -1156
- data/ext/stem_ISO_8859_1_french.c +0 -1276
- data/ext/stem_ISO_8859_1_italian.c +0 -1091
- data/ext/stem_ISO_8859_1_norwegian.c +0 -296
- data/ext/stem_ISO_8859_1_spanish.c +0 -1119
- data/ext/stem_ISO_8859_1_swedish.c +0 -307
- data/ext/stem_UTF_8_danish.c +0 -344
- data/ext/stem_UTF_8_english.c +0 -1176
- data/ext/stem_UTF_8_french.c +0 -1296
- data/ext/stem_UTF_8_italian.c +0 -1113
- data/ext/stem_UTF_8_norwegian.c +0 -302
- data/ext/stem_UTF_8_portuguese.c +0 -1055
- data/ext/stem_UTF_8_russian.c +0 -709
- data/ext/stem_UTF_8_spanish.c +0 -1137
- data/ext/stem_UTF_8_swedish.c +0 -313
- data/lib/ferret_version.rb +0 -3
data/ext/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
|
-
*
|
12
|
+
* Hash
|
9
13
|
*
|
10
14
|
****************************************************************************/
|
11
15
|
|
12
|
-
#define
|
13
|
-
#define
|
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
|
23
|
+
typedef enum
|
20
24
|
{
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
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
|
-
}
|
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
|
42
|
-
* the
|
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
|
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
|
-
|
57
|
+
FrtHashEntry *table;
|
54
58
|
|
55
|
-
/* When a
|
56
|
-
* All
|
57
|
-
* table as the
|
58
|
-
|
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
|
62
|
-
|
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
|
-
}
|
72
|
+
} FrtHash;
|
68
73
|
|
69
74
|
/**
|
70
|
-
* Hashing function type used by
|
71
|
-
* passed to create a new
|
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 (*
|
81
|
+
typedef unsigned long (*frt_hash_ft)(const void *key);
|
77
82
|
|
78
83
|
/**
|
79
|
-
* Equals function type used by
|
80
|
-
* passed to create a new
|
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 (*
|
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
|
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
|
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
|
113
|
+
extern int frt_ptr_eq(const void *q1, const void *q2);
|
109
114
|
|
110
115
|
/**
|
111
|
-
* Create a new
|
112
|
-
*
|
113
|
-
* values when the
|
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
|
117
|
-
* @param eq function to determine the equality of to keys in the
|
118
|
-
* @param free_key function to free the key stored in the
|
119
|
-
* entry is deleted, replaced or when the
|
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
|
122
|
-
* an entry is deleted, replaced or when the
|
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
|
129
|
+
* @return A newly allocated Hash
|
125
130
|
*/
|
126
|
-
extern
|
127
|
-
|
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
|
131
|
-
*
|
132
|
-
* values when the
|
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
|
136
|
-
* entry is deleted, replaced or when the
|
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
|
139
|
-
* an entry is deleted, replaced or when the
|
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
|
148
|
+
* @return A newly allocated Hash
|
142
149
|
*/
|
143
|
-
extern
|
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
|
147
|
-
*
|
148
|
-
*
|
149
|
-
*
|
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
|
152
|
-
* an entry is deleted, replaced or when the
|
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
|
173
|
+
* @return A newly allocated Hash
|
155
174
|
*/
|
156
|
-
|
175
|
+
#define frt_h_new_ptr(free_value) frt_h_new_int(free_value)
|
157
176
|
|
158
177
|
/**
|
159
|
-
* Destroy the
|
160
|
-
* in the
|
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
|
181
|
+
* @param self the Hash to destroy
|
163
182
|
*/
|
164
|
-
extern void
|
183
|
+
extern void frt_h_destroy(FrtHash *self);
|
165
184
|
|
166
185
|
/**
|
167
|
-
* Clear the
|
168
|
-
* hash table, also destroying all keys and values in the
|
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
|
190
|
+
* @param self the Hash to clear
|
172
191
|
*/
|
173
|
-
extern void
|
192
|
+
extern void frt_h_clear(FrtHash *self);
|
174
193
|
|
175
194
|
/**
|
176
|
-
* Get the value in the
|
195
|
+
* Get the value in the Hash referenced by the key +key+.
|
177
196
|
*
|
178
|
-
* @param self the
|
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 *
|
202
|
+
extern void *frt_h_get(FrtHash *self, const void *key);
|
184
203
|
|
185
204
|
/**
|
186
|
-
* Delete the value in
|
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
|
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
|
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
|
220
|
+
extern int frt_h_del(FrtHash *self, const void *key);
|
202
221
|
|
203
222
|
/**
|
204
|
-
* Remove the value in
|
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
|
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
|
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
|
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 *
|
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
|
224
|
-
* for this
|
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
|
245
|
+
* Add the value +value+ to the Hash referencing it with key +key+.
|
227
246
|
*
|
228
|
-
* When a value is added to the
|
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
|
252
|
+
* are equal (according to the Hash's eq function) but seperately
|
234
253
|
* allocated objects.
|
235
254
|
*
|
236
|
-
* @param self the
|
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
|
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
|
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
|
253
|
-
* the key already exists in 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
|
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
|
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
|
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
|
290
|
+
* @param self the Hash to add the value to
|
271
291
|
* @param key the key to use to reference the value
|
272
|
-
* @
|
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
|
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
|
301
|
+
* Check whether key +key+ exists in the Hash.
|
279
302
|
*
|
280
|
-
* @param self the
|
281
|
-
* @param key the key to check for in the
|
282
|
-
* @return
|
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
|
317
|
+
extern FrtHashKeyStatus frt_h_has_key(FrtHash *self,
|
318
|
+
const void *key);
|
285
319
|
|
286
320
|
/**
|
287
|
-
* Get the value in the
|
321
|
+
* Get the value in the Hash referenced by an integer key +key+.
|
288
322
|
*
|
289
|
-
* @param self the
|
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 *
|
328
|
+
extern void *frt_h_get_int(FrtHash *self, const unsigned long key);
|
295
329
|
|
296
330
|
/**
|
297
|
-
* Delete the value in
|
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
|
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
|
345
|
+
extern int frt_h_del_int(FrtHash *self, const unsigned long key);
|
312
346
|
|
313
347
|
/**
|
314
|
-
* Remove the value in
|
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
|
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 *
|
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
|
363
|
+
* in the Hash, depending on how free_value was set for this Hash.
|
330
364
|
*
|
331
|
-
* Add the value +value+ to the
|
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
|
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
|
373
|
+
* are equal (according to the Hash's eq function) but seperately
|
340
374
|
* allocated objects.
|
341
375
|
*
|
342
|
-
* @param self the
|
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
|
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
|
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
|
359
|
-
* +key+. If the key already exists in the
|
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
|
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
|
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
|
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
|
407
|
+
* Check whether integer key +key+ exists in the Hash.
|
370
408
|
*
|
371
|
-
* @param self the
|
372
|
-
* @param key the integer key to check for in the
|
373
|
-
* @return true if the key exists in the
|
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
|
413
|
+
extern int frt_h_has_key_int(FrtHash *self, const unsigned long key);
|
376
414
|
|
377
|
-
typedef void (*
|
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
|
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
|
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(
|
441
|
+
* struct StringArray *h_extract_strings(Hash *ht)
|
404
442
|
* {
|
405
|
-
* struct StringArray *str_arr =
|
443
|
+
* struct StringArray *str_arr = FRT_ALLOC(struct StringArray);
|
406
444
|
*
|
407
|
-
* str_arr->strings =
|
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
|
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
|
-
*
|
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
|
422
|
-
|
423
|
-
|
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 *(*
|
463
|
+
typedef void *(*frt_h_clone_ft)(void *val);
|
426
464
|
/**
|
427
|
-
* Clone the
|
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
|
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
|
472
|
+
* @return a clone of the original Hash
|
435
473
|
*/
|
436
|
-
extern
|
437
|
-
|
438
|
-
|
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
|
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
|
492
|
+
extern FrtHashEntry *frt_h_lookup(FrtHash *ht,
|
493
|
+
register const void *key);
|
468
494
|
|
469
|
-
typedef
|
495
|
+
typedef FrtHashEntry *(*frt_h_lookup_ft)(FrtHash *ht,
|
496
|
+
register const void *key);
|
470
497
|
|
471
|
-
extern void
|
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
|