sdsykes-ferret 0.11.6.19
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +24 -0
- data/MIT-LICENSE +20 -0
- data/README +102 -0
- data/Rakefile +338 -0
- data/TODO +17 -0
- data/TUTORIAL +231 -0
- data/bin/ferret-browser +79 -0
- data/ext/analysis.c +1555 -0
- data/ext/analysis.h +219 -0
- data/ext/api.c +69 -0
- data/ext/api.h +27 -0
- data/ext/array.c +123 -0
- data/ext/array.h +53 -0
- data/ext/bitvector.c +540 -0
- data/ext/bitvector.h +272 -0
- data/ext/compound_io.c +383 -0
- data/ext/config.h +42 -0
- data/ext/document.c +156 -0
- data/ext/document.h +53 -0
- data/ext/except.c +120 -0
- data/ext/except.h +168 -0
- data/ext/extconf.rb +14 -0
- data/ext/ferret.c +402 -0
- data/ext/ferret.h +91 -0
- data/ext/filter.c +156 -0
- data/ext/fs_store.c +483 -0
- data/ext/global.c +418 -0
- data/ext/global.h +117 -0
- data/ext/hash.c +567 -0
- data/ext/hash.h +473 -0
- data/ext/hashset.c +170 -0
- data/ext/hashset.h +187 -0
- data/ext/header.h +58 -0
- data/ext/helper.c +62 -0
- data/ext/helper.h +13 -0
- data/ext/inc/lang.h +48 -0
- data/ext/inc/threading.h +31 -0
- data/ext/index.c +6425 -0
- data/ext/index.h +961 -0
- data/ext/lang.h +66 -0
- data/ext/libstemmer.c +92 -0
- data/ext/libstemmer.h +79 -0
- data/ext/mempool.c +87 -0
- data/ext/mempool.h +35 -0
- data/ext/modules.h +162 -0
- data/ext/multimapper.c +310 -0
- data/ext/multimapper.h +51 -0
- data/ext/posh.c +1006 -0
- data/ext/posh.h +1007 -0
- data/ext/priorityqueue.c +151 -0
- data/ext/priorityqueue.h +143 -0
- data/ext/q_boolean.c +1608 -0
- data/ext/q_const_score.c +161 -0
- data/ext/q_filtered_query.c +209 -0
- data/ext/q_fuzzy.c +268 -0
- data/ext/q_match_all.c +148 -0
- data/ext/q_multi_term.c +677 -0
- data/ext/q_parser.c +2825 -0
- data/ext/q_phrase.c +1126 -0
- data/ext/q_prefix.c +100 -0
- data/ext/q_range.c +350 -0
- data/ext/q_span.c +2402 -0
- data/ext/q_term.c +337 -0
- data/ext/q_wildcard.c +171 -0
- data/ext/r_analysis.c +2575 -0
- data/ext/r_index.c +3472 -0
- data/ext/r_qparser.c +585 -0
- data/ext/r_search.c +4105 -0
- data/ext/r_store.c +513 -0
- data/ext/r_utils.c +963 -0
- data/ext/ram_store.c +471 -0
- data/ext/search.c +1741 -0
- data/ext/search.h +885 -0
- data/ext/similarity.c +150 -0
- data/ext/similarity.h +82 -0
- data/ext/sort.c +983 -0
- data/ext/stem_ISO_8859_1_danish.c +338 -0
- data/ext/stem_ISO_8859_1_danish.h +16 -0
- data/ext/stem_ISO_8859_1_dutch.c +635 -0
- data/ext/stem_ISO_8859_1_dutch.h +16 -0
- data/ext/stem_ISO_8859_1_english.c +1156 -0
- data/ext/stem_ISO_8859_1_english.h +16 -0
- data/ext/stem_ISO_8859_1_finnish.c +792 -0
- data/ext/stem_ISO_8859_1_finnish.h +16 -0
- data/ext/stem_ISO_8859_1_french.c +1276 -0
- data/ext/stem_ISO_8859_1_french.h +16 -0
- data/ext/stem_ISO_8859_1_german.c +512 -0
- data/ext/stem_ISO_8859_1_german.h +16 -0
- data/ext/stem_ISO_8859_1_italian.c +1091 -0
- data/ext/stem_ISO_8859_1_italian.h +16 -0
- data/ext/stem_ISO_8859_1_norwegian.c +296 -0
- data/ext/stem_ISO_8859_1_norwegian.h +16 -0
- data/ext/stem_ISO_8859_1_porter.c +776 -0
- data/ext/stem_ISO_8859_1_porter.h +16 -0
- data/ext/stem_ISO_8859_1_portuguese.c +1035 -0
- data/ext/stem_ISO_8859_1_portuguese.h +16 -0
- data/ext/stem_ISO_8859_1_spanish.c +1119 -0
- data/ext/stem_ISO_8859_1_spanish.h +16 -0
- data/ext/stem_ISO_8859_1_swedish.c +307 -0
- data/ext/stem_ISO_8859_1_swedish.h +16 -0
- data/ext/stem_KOI8_R_russian.c +701 -0
- data/ext/stem_KOI8_R_russian.h +16 -0
- data/ext/stem_UTF_8_danish.c +344 -0
- data/ext/stem_UTF_8_danish.h +16 -0
- data/ext/stem_UTF_8_dutch.c +653 -0
- data/ext/stem_UTF_8_dutch.h +16 -0
- data/ext/stem_UTF_8_english.c +1176 -0
- data/ext/stem_UTF_8_english.h +16 -0
- data/ext/stem_UTF_8_finnish.c +808 -0
- data/ext/stem_UTF_8_finnish.h +16 -0
- data/ext/stem_UTF_8_french.c +1296 -0
- data/ext/stem_UTF_8_french.h +16 -0
- data/ext/stem_UTF_8_german.c +526 -0
- data/ext/stem_UTF_8_german.h +16 -0
- data/ext/stem_UTF_8_italian.c +1113 -0
- data/ext/stem_UTF_8_italian.h +16 -0
- data/ext/stem_UTF_8_norwegian.c +302 -0
- data/ext/stem_UTF_8_norwegian.h +16 -0
- data/ext/stem_UTF_8_porter.c +794 -0
- data/ext/stem_UTF_8_porter.h +16 -0
- data/ext/stem_UTF_8_portuguese.c +1055 -0
- data/ext/stem_UTF_8_portuguese.h +16 -0
- data/ext/stem_UTF_8_russian.c +709 -0
- data/ext/stem_UTF_8_russian.h +16 -0
- data/ext/stem_UTF_8_spanish.c +1137 -0
- data/ext/stem_UTF_8_spanish.h +16 -0
- data/ext/stem_UTF_8_swedish.c +313 -0
- data/ext/stem_UTF_8_swedish.h +16 -0
- data/ext/stopwords.c +401 -0
- data/ext/store.c +692 -0
- data/ext/store.h +777 -0
- data/ext/term_vectors.c +352 -0
- data/ext/threading.h +31 -0
- data/ext/utilities.c +446 -0
- data/ext/win32.h +54 -0
- data/lib/ferret.rb +29 -0
- data/lib/ferret/browser.rb +246 -0
- data/lib/ferret/browser/s/global.js +192 -0
- data/lib/ferret/browser/s/style.css +148 -0
- data/lib/ferret/browser/views/document/list.rhtml +49 -0
- data/lib/ferret/browser/views/document/show.rhtml +27 -0
- data/lib/ferret/browser/views/error/index.rhtml +7 -0
- data/lib/ferret/browser/views/help/index.rhtml +8 -0
- data/lib/ferret/browser/views/home/index.rhtml +29 -0
- data/lib/ferret/browser/views/layout.rhtml +22 -0
- data/lib/ferret/browser/views/term-vector/index.rhtml +4 -0
- data/lib/ferret/browser/views/term/index.rhtml +199 -0
- data/lib/ferret/browser/views/term/termdocs.rhtml +1 -0
- data/lib/ferret/browser/webrick.rb +14 -0
- data/lib/ferret/document.rb +130 -0
- data/lib/ferret/field_infos.rb +44 -0
- data/lib/ferret/index.rb +786 -0
- data/lib/ferret/number_tools.rb +157 -0
- data/lib/ferret_version.rb +3 -0
- data/setup.rb +1555 -0
- data/test/test_all.rb +5 -0
- data/test/test_helper.rb +24 -0
- data/test/threading/number_to_spoken.rb +132 -0
- data/test/threading/thread_safety_index_test.rb +79 -0
- data/test/threading/thread_safety_read_write_test.rb +76 -0
- data/test/threading/thread_safety_test.rb +133 -0
- data/test/unit/analysis/tc_analyzer.rb +548 -0
- data/test/unit/analysis/tc_token_stream.rb +646 -0
- data/test/unit/index/tc_index.rb +762 -0
- data/test/unit/index/tc_index_reader.rb +699 -0
- data/test/unit/index/tc_index_writer.rb +437 -0
- data/test/unit/index/th_doc.rb +315 -0
- data/test/unit/largefile/tc_largefile.rb +46 -0
- data/test/unit/query_parser/tc_query_parser.rb +238 -0
- data/test/unit/search/tc_filter.rb +135 -0
- data/test/unit/search/tc_fuzzy_query.rb +147 -0
- data/test/unit/search/tc_index_searcher.rb +61 -0
- data/test/unit/search/tc_multi_searcher.rb +128 -0
- data/test/unit/search/tc_multiple_search_requests.rb +58 -0
- data/test/unit/search/tc_search_and_sort.rb +179 -0
- data/test/unit/search/tc_sort.rb +49 -0
- data/test/unit/search/tc_sort_field.rb +27 -0
- data/test/unit/search/tc_spans.rb +190 -0
- data/test/unit/search/tm_searcher.rb +384 -0
- data/test/unit/store/tc_fs_store.rb +77 -0
- data/test/unit/store/tc_ram_store.rb +35 -0
- data/test/unit/store/tm_store.rb +34 -0
- data/test/unit/store/tm_store_lock.rb +68 -0
- data/test/unit/tc_document.rb +81 -0
- data/test/unit/ts_analysis.rb +2 -0
- data/test/unit/ts_index.rb +2 -0
- data/test/unit/ts_largefile.rb +4 -0
- data/test/unit/ts_query_parser.rb +2 -0
- data/test/unit/ts_search.rb +2 -0
- data/test/unit/ts_store.rb +2 -0
- data/test/unit/ts_utils.rb +2 -0
- data/test/unit/utils/tc_bit_vector.rb +295 -0
- data/test/unit/utils/tc_number_tools.rb +117 -0
- data/test/unit/utils/tc_priority_queue.rb +106 -0
- metadata +285 -0
data/ext/hashset.c
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
#include "hashset.h"
|
2
|
+
#include <string.h>
|
3
|
+
|
4
|
+
/*
|
5
|
+
* The HashSet contains an array +elems+ of the elements that have been added.
|
6
|
+
* It always has +size+ elements so +size+ ane +elems+ can be used to iterate
|
7
|
+
* over all alements in the HashSet. It also uses a HashTable to keep track of
|
8
|
+
* which elements have been added and their index in the +elems+ array.
|
9
|
+
*/
|
10
|
+
static HashSet *hs_alloc(void (*free_elem) (void *p))
|
11
|
+
{
|
12
|
+
HashSet *hs = ALLOC(HashSet);
|
13
|
+
hs->size = 0;
|
14
|
+
hs->capa = HS_MIN_SIZE;
|
15
|
+
hs->elems = ALLOC_N(void *, HS_MIN_SIZE);
|
16
|
+
hs->free_elem_i = free_elem ? free_elem : &dummy_free;
|
17
|
+
return hs;
|
18
|
+
}
|
19
|
+
|
20
|
+
HashSet *hs_new(unsigned long (*hash)(const void *p),
|
21
|
+
int (*eq)(const void *p1, const void *p2),
|
22
|
+
void (*free_elem)(void *p))
|
23
|
+
{
|
24
|
+
HashSet *hs = hs_alloc(free_elem);
|
25
|
+
hs->ht = h_new(hash, eq, NULL, &free);
|
26
|
+
return hs;
|
27
|
+
}
|
28
|
+
|
29
|
+
HashSet *hs_new_str(void (*free_elem) (void *p))
|
30
|
+
{
|
31
|
+
HashSet *hs = hs_alloc(free_elem);
|
32
|
+
hs->ht = h_new_str((free_ft) NULL, &free);
|
33
|
+
return hs;
|
34
|
+
}
|
35
|
+
|
36
|
+
void hs_free(HashSet *hs)
|
37
|
+
{
|
38
|
+
h_destroy(hs->ht);
|
39
|
+
free(hs->elems);
|
40
|
+
free(hs);
|
41
|
+
}
|
42
|
+
|
43
|
+
void hs_clear(HashSet *hs)
|
44
|
+
{
|
45
|
+
int i;
|
46
|
+
for (i = hs->size - 1; i >= 0; i--) {
|
47
|
+
hs_del(hs, hs->elems[i]);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
void hs_destroy(HashSet *hs)
|
52
|
+
{
|
53
|
+
int i;
|
54
|
+
if (hs->free_elem_i != &dummy_free) {
|
55
|
+
for (i = 0; i < hs->size; i++) {
|
56
|
+
hs->free_elem_i(hs->elems[i]);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
h_destroy(hs->ht);
|
60
|
+
free(hs->elems);
|
61
|
+
free(hs);
|
62
|
+
}
|
63
|
+
|
64
|
+
int hs_add(HashSet *hs, void *elem)
|
65
|
+
{
|
66
|
+
int has_elem = h_has_key(hs->ht, elem);
|
67
|
+
if (has_elem == HASH_KEY_EQUAL) {
|
68
|
+
/* We don't want to keep two of the same elem so free if necessary */
|
69
|
+
hs->free_elem_i(elem);
|
70
|
+
}
|
71
|
+
else if (has_elem == HASH_KEY_SAME) {
|
72
|
+
/* No need to do anything */
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
/* add the elem to the array, resizing if necessary */
|
76
|
+
if (hs->size >= hs->capa) {
|
77
|
+
hs->capa *= 2;
|
78
|
+
REALLOC_N(hs->elems, void *, hs->capa);
|
79
|
+
}
|
80
|
+
hs->elems[hs->size] = elem;
|
81
|
+
h_set(hs->ht, elem, imalloc(hs->size));
|
82
|
+
hs->size++;
|
83
|
+
}
|
84
|
+
return has_elem;
|
85
|
+
}
|
86
|
+
|
87
|
+
int hs_add_safe(HashSet *hs, void *elem)
|
88
|
+
{
|
89
|
+
int has_elem = h_has_key(hs->ht, elem);
|
90
|
+
if (has_elem == HASH_KEY_EQUAL) {
|
91
|
+
/* element can't be added */
|
92
|
+
return false;
|
93
|
+
}
|
94
|
+
else if (has_elem == HASH_KEY_SAME) {
|
95
|
+
/* the exact same element has already been added */
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
/* add the elem to the array, resizing if necessary */
|
100
|
+
if (hs->size >= hs->capa) {
|
101
|
+
hs->capa *= 2;
|
102
|
+
REALLOC_N(hs->elems, void *, hs->capa);
|
103
|
+
}
|
104
|
+
hs->elems[hs->size] = elem;
|
105
|
+
h_set(hs->ht, elem, imalloc(hs->size));
|
106
|
+
hs->size++;
|
107
|
+
return true;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
int hs_del(HashSet *hs, void *elem)
|
112
|
+
{
|
113
|
+
void *tmp_elem = hs_rem(hs, elem);
|
114
|
+
if (tmp_elem != NULL) {
|
115
|
+
hs->free_elem_i(tmp_elem);
|
116
|
+
return 1;
|
117
|
+
}
|
118
|
+
else {
|
119
|
+
return 0;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
void *hs_rem(HashSet *hs, void *elem)
|
124
|
+
{
|
125
|
+
void *ret_elem;
|
126
|
+
int *index = (int *)h_get(hs->ht, elem);
|
127
|
+
if (index == NULL) {
|
128
|
+
return NULL;
|
129
|
+
}
|
130
|
+
else {
|
131
|
+
int i = *index;
|
132
|
+
int j;
|
133
|
+
ret_elem = hs->elems[i];
|
134
|
+
h_del(hs->ht, elem);
|
135
|
+
hs->size--;
|
136
|
+
for (j = i; j < hs->size; j++) {
|
137
|
+
hs->elems[j] = hs->elems[j+1];
|
138
|
+
h_set(hs->ht, hs->elems[j], imalloc(j));
|
139
|
+
}
|
140
|
+
return ret_elem;
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
int hs_exists(HashSet *hs, void *elem)
|
145
|
+
{
|
146
|
+
return h_has_key(hs->ht, elem);
|
147
|
+
}
|
148
|
+
|
149
|
+
HashSet *hs_merge(HashSet *hs, HashSet * other)
|
150
|
+
{
|
151
|
+
int i;
|
152
|
+
for (i = 0; i < other->size; i++) {
|
153
|
+
hs_add(hs, other->elems[i]);
|
154
|
+
}
|
155
|
+
/* Now free the other hashset. It is no longer needed. No need, however, to
|
156
|
+
* delete the elements as they're either destroyed or in the new hash set */
|
157
|
+
hs_free(other);
|
158
|
+
return hs;
|
159
|
+
}
|
160
|
+
|
161
|
+
void *hs_orig(HashSet *hs, void *elem)
|
162
|
+
{
|
163
|
+
int *index = h_get(hs->ht, elem);
|
164
|
+
if (index) {
|
165
|
+
return hs->elems[*index];
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
return NULL;
|
169
|
+
}
|
170
|
+
}
|
data/ext/hashset.h
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
#ifndef FRT_HASHSET_H
|
2
|
+
#define FRT_HASHSET_H
|
3
|
+
|
4
|
+
#include "hash.h"
|
5
|
+
#include "global.h"
|
6
|
+
|
7
|
+
#define HS_MIN_SIZE 4
|
8
|
+
|
9
|
+
typedef struct HashSet
|
10
|
+
{
|
11
|
+
/* used internally to allocate space to elems */
|
12
|
+
int capa;
|
13
|
+
|
14
|
+
/* the number of elements in the HashSet */
|
15
|
+
int size;
|
16
|
+
|
17
|
+
/* the elements in the HashSet. The elements will be found in the order
|
18
|
+
* they were added and can be iterated over from 0 to .size */
|
19
|
+
void **elems;
|
20
|
+
|
21
|
+
/* HashTable used internally */
|
22
|
+
HashTable *ht;
|
23
|
+
|
24
|
+
/* Internal: Frees elements added to the HashSet. Should never be NULL */
|
25
|
+
void (*free_elem_i)(void *p);
|
26
|
+
} HashSet;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Create a new HashSet. The function will allocate a HashSet Struct setting
|
30
|
+
* the functions used to hash the objects it will contain and the eq function.
|
31
|
+
* This should be used for non-string types.
|
32
|
+
*
|
33
|
+
* @param hash function to hash objects added to the HashSet
|
34
|
+
* @param eq function to determine whether two items are equal
|
35
|
+
* @param free_elem function used to free elements as added to the HashSet
|
36
|
+
* when the HashSet if destroyed or duplicate elements are added to the Set
|
37
|
+
* @return a newly allocated HashSet structure
|
38
|
+
*/
|
39
|
+
extern HashSet *hs_new(unsigned long (*hash)(const void *p),
|
40
|
+
int (*eq)(const void *p1, const void *p2),
|
41
|
+
void (*free_elem)(void *p));
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Create a new HashSet specifically for strings. This will create a HashSet
|
45
|
+
* as if you used hs_new with the standard string hash and eq functions.
|
46
|
+
*
|
47
|
+
* @param free_elem function used to free elements as added to the HashSet
|
48
|
+
* when the HashSet if destroyed or duplicate elements are added to the Set
|
49
|
+
* @return a newly allocated HashSet structure
|
50
|
+
*/
|
51
|
+
extern HashSet *hs_new_str(void (*free_elem) (void *p));
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Free the memory allocated by the HashSet, but don't free the elements added
|
55
|
+
* to the HashSet. If you'd like to free everything in the HashSet you should
|
56
|
+
* use hs_destroy
|
57
|
+
*
|
58
|
+
* @param hs the HashSet to free
|
59
|
+
*/
|
60
|
+
extern void hs_free(HashSet *self);
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Destroy the HashSet including all elements added to the HashSet. If you'd
|
64
|
+
* like to free the memory allocated to the HashSet without touching the
|
65
|
+
* elements in the HashSet then use hs_free
|
66
|
+
*
|
67
|
+
* @param hs the HashSet to destroy
|
68
|
+
*/
|
69
|
+
extern void hs_destroy(HashSet *self);
|
70
|
+
|
71
|
+
/**
|
72
|
+
* WARNING: this function may destroy some elements if you add them to a
|
73
|
+
* HashSet were equivalent elements already exist, depending on how free_elem
|
74
|
+
* was set.
|
75
|
+
*
|
76
|
+
* Add the element to the HashSet whether or not it was already in the
|
77
|
+
* HashSet.
|
78
|
+
*
|
79
|
+
* When a element is added to the HashTable where it already exists, free_elem
|
80
|
+
* is called on it, ie the element you tried to add might get destroyed.
|
81
|
+
*
|
82
|
+
* @param hs the HashSet to add the element to
|
83
|
+
* @param elem the element to add to the HashSet
|
84
|
+
* @return one of three values;
|
85
|
+
* <pre>
|
86
|
+
* HASH_KEY_DOES_NOT_EXIST the element was not already in the HashSet.
|
87
|
+
* This value is equal to 0 or false
|
88
|
+
* HASH_KEY_SAME the element was identical (same memory
|
89
|
+
* pointer) to an existing element so no freeing
|
90
|
+
* was done
|
91
|
+
* HASH_KEY_EQUAL the element was equal to an element already in
|
92
|
+
* the HashSet so the new_elem was freed if
|
93
|
+
* free_elem was set
|
94
|
+
* </pre>
|
95
|
+
*/
|
96
|
+
extern int hs_add(HashSet *self, void *elem);
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Add element to the HashSet. If the element already existed in the HashSet
|
100
|
+
* and the new element was equal but not the same (same pointer/memory) then
|
101
|
+
* don't add the element and return false, otherwise return true.
|
102
|
+
*
|
103
|
+
* @param hs the HashSet to add the element to
|
104
|
+
* @param elem the element to add to the HashSet
|
105
|
+
* @return true if the element was successfully added or false otherwise
|
106
|
+
*/
|
107
|
+
extern int hs_add_safe(HashSet *self, void *elem);
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Delete the element from the HashSet. Returns true if the item was
|
111
|
+
* successfully deleted or false if the element never existed.
|
112
|
+
*
|
113
|
+
* @param hs the HashSet to delete from
|
114
|
+
* @param elem the element to delete
|
115
|
+
* @return true if the element was deleted or false if the element never
|
116
|
+
* existed
|
117
|
+
*/
|
118
|
+
extern int hs_del(HashSet *self, void *elem);
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Remove an item from the HashSet without actually freeing the item. This
|
122
|
+
* function should return the item itself so that it can be freed later if
|
123
|
+
* necessary.
|
124
|
+
*
|
125
|
+
* @param hs the HashSet to remove the element from.
|
126
|
+
* @param elem the element to remove
|
127
|
+
* @param the element that was removed or NULL otherwise
|
128
|
+
*/
|
129
|
+
extern void *hs_rem(HashSet *self, void *elem);
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Check if the element exists and return the appropriate value described
|
133
|
+
* bellow.
|
134
|
+
*
|
135
|
+
* @param hs the HashSet to check in
|
136
|
+
* @param elem the element to check for
|
137
|
+
* @return one of the following values
|
138
|
+
* <pre>
|
139
|
+
* HASH_KEY_DOES_NOT_EXIST the element was not already in the HashSet.
|
140
|
+
* This value is equal to 0 or false
|
141
|
+
* HASH_KEY_SAME the element was identical (same memory
|
142
|
+
* pointer) to an existing element so no freeing
|
143
|
+
* was done
|
144
|
+
* HASH_KEY_EQUAL the element was equal to an element already in
|
145
|
+
* the HashSet so the new_elem was freed if
|
146
|
+
* free_elem was set
|
147
|
+
* </pre>
|
148
|
+
*/
|
149
|
+
extern int hs_exists(HashSet *self, void *elem);
|
150
|
+
|
151
|
+
/**
|
152
|
+
* Merge two HashSets. When a merge is done the merger (self) HashTable is
|
153
|
+
* returned and the mergee is destroyed. All elements from mergee that were
|
154
|
+
* not found in merger (self) will be added to self, otherwise they will be
|
155
|
+
* destroyed.
|
156
|
+
*
|
157
|
+
* @param self the HashSet to merge into
|
158
|
+
* @param other HastSet to be merged into self
|
159
|
+
* @return the merged HashSet
|
160
|
+
*/
|
161
|
+
extern HashSet *hs_merge(HashSet *self, HashSet *other);
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Return the original version of +elem+. So if you allocate two elements
|
165
|
+
* which are equal and add the first to the HashSet, calling this function
|
166
|
+
* with the second element will return the first element from the HashSet.
|
167
|
+
*/
|
168
|
+
extern void *hs_orig(HashSet *self, void *elem);
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Clear all elements from the HashSet. If free_elem was set then use it to
|
172
|
+
* free all elements as they are cleared. After the method is called, the
|
173
|
+
* HashSets size will be 0.
|
174
|
+
*
|
175
|
+
* @param self the HashSet to clear
|
176
|
+
*/
|
177
|
+
extern void hs_clear(HashSet *self);
|
178
|
+
|
179
|
+
/* TODO: finish these functions.
|
180
|
+
int hs_osf(HashSet *hs, void *elem);
|
181
|
+
HashSet hs_or(HashSet *hs1, HashSet *h2);
|
182
|
+
HashSet hs_excl_or(HashSet *hs1, HashSet *h2);
|
183
|
+
HashSet hs_and(HashSet *hs1, HashSet *h2);
|
184
|
+
HashSet hs_mask(HashSet *hs1, HashSet *h2);
|
185
|
+
*/
|
186
|
+
|
187
|
+
#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
|
+
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, unsigned char * s, int min, int max);
|
29
|
+
extern int in_grouping_b_U(struct SN_env * z, unsigned char * s, int min, int max);
|
30
|
+
extern int out_grouping_U(struct SN_env * z, unsigned char * s, int min, int max);
|
31
|
+
extern int out_grouping_b_U(struct SN_env * z, unsigned char * s, int min, int max);
|
32
|
+
|
33
|
+
extern int in_grouping(struct SN_env * z, unsigned char * s, int min, int max);
|
34
|
+
extern int in_grouping_b(struct SN_env * z, unsigned char * s, int min, int max);
|
35
|
+
extern int out_grouping(struct SN_env * z, unsigned char * s, int min, int max);
|
36
|
+
extern int out_grouping_b(struct SN_env * z, unsigned char * s, int min, int max);
|
37
|
+
|
38
|
+
extern int eq_s(struct SN_env * z, int s_size, symbol * s);
|
39
|
+
extern int eq_s_b(struct SN_env * z, int s_size, symbol * s);
|
40
|
+
extern int eq_v(struct SN_env * z, symbol * p);
|
41
|
+
extern int eq_v_b(struct SN_env * z, symbol * p);
|
42
|
+
|
43
|
+
extern int find_among(struct SN_env * z, struct among * v, int v_size);
|
44
|
+
extern int find_among_b(struct SN_env * z, 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, symbol * s);
|
48
|
+
extern int slice_from_v(struct SN_env * z, 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, symbol * s);
|
52
|
+
extern int insert_v(struct SN_env * z, int bra, int ket, 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
|
+
|
data/ext/helper.c
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#include "helper.h"
|
2
|
+
|
3
|
+
int hlp_string_diff(register const char *const s1,
|
4
|
+
register const char *const s2)
|
5
|
+
{
|
6
|
+
register int i = 0;
|
7
|
+
while (s1[i] && (s1[i] == s2[i])) {
|
8
|
+
i++;
|
9
|
+
}
|
10
|
+
return i;
|
11
|
+
}
|
12
|
+
|
13
|
+
f_i32 float2int(float f)
|
14
|
+
{
|
15
|
+
union { f_i32 i; float f; } tmp;
|
16
|
+
tmp.f = f;
|
17
|
+
return tmp.i;
|
18
|
+
}
|
19
|
+
|
20
|
+
float int2float(f_i32 i32)
|
21
|
+
{
|
22
|
+
union { f_i32 i; float f; } tmp;
|
23
|
+
tmp.i = i32;
|
24
|
+
return tmp.f;
|
25
|
+
}
|
26
|
+
|
27
|
+
float byte2float(unsigned char b)
|
28
|
+
{
|
29
|
+
if (b == 0) {
|
30
|
+
return 0.0;
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
f_u32 mantissa = b & 0x07;
|
34
|
+
f_u32 exponent = (b >> 3) & 0x1f;
|
35
|
+
|
36
|
+
return int2float((mantissa << 21) | ((exponent + 48) << 24));
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
unsigned char float2byte(float f)
|
41
|
+
{
|
42
|
+
if (f <= 0.0) {
|
43
|
+
return 0;
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
/* correctly order the bytes for encoding */
|
47
|
+
f_u32 i32 = float2int(f);
|
48
|
+
int mantissa = (i32 & 0xEf0000) >> 21;
|
49
|
+
int exponent = ((i32 >> 24) - 48);
|
50
|
+
|
51
|
+
if (exponent > 0x1f) {
|
52
|
+
exponent = 0x1f; /* 0x1f = 31 = 0b00011111 */
|
53
|
+
mantissa = 0x07; /* 0x07 = 7 = 0b00000111 */
|
54
|
+
}
|
55
|
+
|
56
|
+
if (exponent < 0) {
|
57
|
+
exponent = 0;
|
58
|
+
mantissa = 1;
|
59
|
+
}
|
60
|
+
return ((exponent<<3) | mantissa);
|
61
|
+
}
|
62
|
+
}
|