isomorfeus-ferret 0.12.6 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +101 -19
- data/README.md +85 -16
- data/ext/isomorfeus_ferret_ext/bm_bitvector.c +22 -30
- data/ext/isomorfeus_ferret_ext/bm_hash.c +6 -12
- data/ext/isomorfeus_ferret_ext/bm_micro_string.c +3 -6
- data/ext/isomorfeus_ferret_ext/bm_store.c +11 -22
- data/ext/isomorfeus_ferret_ext/brotli_common_constants.c +15 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_constants.h +200 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_context.c +156 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_context.h +113 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.c +5914 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.h +64 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_platform.c +22 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_platform.h +594 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_transform.c +291 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_transform.h +85 -0
- data/ext/isomorfeus_ferret_ext/brotli_common_version.h +26 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.c +76 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.h +351 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +2608 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.c +339 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.h +121 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_prefix.h +732 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_state.c +159 -0
- data/ext/isomorfeus_ferret_ext/brotli_dec_state.h +365 -0
- data/ext/isomorfeus_ferret_ext/brotli_decode.h +344 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.c +145 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.h +39 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.c +843 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.h +95 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_inc.h +163 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.c +35 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.h +63 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost_inc.h +127 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_block_encoder_inc.h +34 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.c +194 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.h +51 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter_inc.h +440 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.c +1314 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.h +84 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.c +56 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.h +48 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_cluster_inc.h +320 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_command.c +28 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_command.h +190 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.c +790 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.h +61 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.c +645 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.h +54 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.c +1846 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.h +25 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +1927 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.c +33 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.h +43 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.c +503 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.h +122 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode_static.h +539 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.c +105 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.h +66 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_find_match_length.h +79 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash.h +488 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_composite_inc.h +125 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_forgetful_chain_inc.h +293 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match64_inc.h +267 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_inc.h +262 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_quickly_inc.h +266 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_rolling_inc.h +212 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_hash_to_binary_tree_inc.h +329 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.c +100 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.h +63 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_histogram_inc.h +51 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.c +175 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.h +30 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_memory.c +170 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_memory.h +114 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.c +663 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.h +105 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_metablock_inc.h +183 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_params.h +46 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_prefix.h +53 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_quality.h +165 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_ringbuffer.h +167 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.c +486 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.h +40 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict_lut.h +5864 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.c +85 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.h +32 -0
- data/ext/isomorfeus_ferret_ext/brotli_enc_write_bits.h +87 -0
- data/ext/isomorfeus_ferret_ext/brotli_encode.h +448 -0
- data/ext/isomorfeus_ferret_ext/brotli_port.h +288 -0
- data/ext/isomorfeus_ferret_ext/brotli_types.h +83 -0
- data/ext/isomorfeus_ferret_ext/bzlib.c +1572 -0
- data/ext/isomorfeus_ferret_ext/bzlib.h +282 -0
- data/ext/isomorfeus_ferret_ext/bzlib_blocksort.c +1094 -0
- data/ext/isomorfeus_ferret_ext/bzlib_compress.c +672 -0
- data/ext/isomorfeus_ferret_ext/bzlib_crctable.c +104 -0
- data/ext/isomorfeus_ferret_ext/bzlib_decompress.c +652 -0
- data/ext/isomorfeus_ferret_ext/bzlib_huffman.c +205 -0
- data/ext/isomorfeus_ferret_ext/bzlib_private.h +509 -0
- data/ext/isomorfeus_ferret_ext/bzlib_randtable.c +84 -0
- data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -53
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +785 -1192
- data/ext/isomorfeus_ferret_ext/frb_index.c +513 -464
- data/ext/isomorfeus_ferret_ext/frb_qparser.c +48 -60
- data/ext/isomorfeus_ferret_ext/frb_search.c +1520 -1002
- data/ext/isomorfeus_ferret_ext/frb_store.c +96 -96
- data/ext/isomorfeus_ferret_ext/frb_threading.h +0 -1
- data/ext/isomorfeus_ferret_ext/frb_utils.c +147 -196
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +695 -1090
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +174 -170
- data/ext/isomorfeus_ferret_ext/frt_array.c +2 -4
- data/ext/isomorfeus_ferret_ext/frt_bitvector.c +9 -16
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +32 -81
- data/ext/isomorfeus_ferret_ext/frt_document.c +15 -20
- data/ext/isomorfeus_ferret_ext/frt_document.h +10 -9
- data/ext/isomorfeus_ferret_ext/frt_except.c +5 -12
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +3 -3
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +6 -7
- data/ext/isomorfeus_ferret_ext/frt_filter.c +35 -46
- data/ext/isomorfeus_ferret_ext/frt_fs_store.c +2 -0
- data/ext/isomorfeus_ferret_ext/frt_global.c +91 -200
- data/ext/isomorfeus_ferret_ext/frt_global.h +7 -18
- data/ext/isomorfeus_ferret_ext/frt_hash.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_ind.c +32 -35
- data/ext/isomorfeus_ferret_ext/frt_ind.h +9 -9
- data/ext/isomorfeus_ferret_ext/frt_index.c +714 -384
- data/ext/isomorfeus_ferret_ext/frt_index.h +274 -290
- data/ext/isomorfeus_ferret_ext/frt_lang.c +0 -2
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +4 -7
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +68 -91
- data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +35 -38
- data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +53 -72
- data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +25 -32
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +21 -23
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +66 -103
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +207 -195
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +20 -16
- data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +17 -14
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +102 -131
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +179 -178
- data/ext/isomorfeus_ferret_ext/frt_q_term.c +47 -60
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +18 -16
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +46 -84
- data/ext/isomorfeus_ferret_ext/frt_search.c +105 -146
- data/ext/isomorfeus_ferret_ext/frt_search.h +331 -320
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +5 -13
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +7 -12
- data/ext/isomorfeus_ferret_ext/frt_sort.c +105 -149
- data/ext/isomorfeus_ferret_ext/frt_store.c +13 -7
- data/ext/isomorfeus_ferret_ext/frt_store.h +10 -2
- data/ext/isomorfeus_ferret_ext/frt_threading.h +0 -1
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +22 -112
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +2 -32
- data/ext/isomorfeus_ferret_ext/lz4.c +2495 -0
- data/ext/isomorfeus_ferret_ext/lz4.h +774 -0
- data/ext/isomorfeus_ferret_ext/lz4frame.c +1899 -0
- data/ext/isomorfeus_ferret_ext/lz4frame.h +623 -0
- data/ext/isomorfeus_ferret_ext/lz4hc.c +1615 -0
- data/ext/isomorfeus_ferret_ext/lz4hc.h +413 -0
- data/ext/isomorfeus_ferret_ext/lz4xxhash.c +1030 -0
- data/ext/isomorfeus_ferret_ext/lz4xxhash.h +328 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.h +0 -86
- data/ext/isomorfeus_ferret_ext/test.c +0 -17
- data/ext/isomorfeus_ferret_ext/test_1710.c +11 -12
- data/ext/isomorfeus_ferret_ext/test_analysis.c +590 -583
- data/ext/isomorfeus_ferret_ext/test_compound_io.c +1 -1
- data/ext/isomorfeus_ferret_ext/test_document.c +19 -15
- data/ext/isomorfeus_ferret_ext/test_except.c +1 -2
- data/ext/isomorfeus_ferret_ext/test_fields.c +111 -100
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +10 -27
- data/ext/isomorfeus_ferret_ext/test_filter.c +11 -8
- data/ext/isomorfeus_ferret_ext/test_global.c +0 -46
- data/ext/isomorfeus_ferret_ext/test_hash.c +2 -2
- data/ext/isomorfeus_ferret_ext/test_hashset.c +1 -1
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +15 -11
- data/ext/isomorfeus_ferret_ext/test_index.c +373 -363
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +5 -3
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +5 -3
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +13 -10
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +45 -7
- data/ext/isomorfeus_ferret_ext/test_q_span.c +15 -12
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +3 -3
- data/ext/isomorfeus_ferret_ext/test_search.c +60 -64
- data/ext/isomorfeus_ferret_ext/test_segments.c +5 -4
- data/ext/isomorfeus_ferret_ext/test_sort.c +17 -14
- data/ext/isomorfeus_ferret_ext/test_store.c +2 -0
- data/ext/isomorfeus_ferret_ext/test_term.c +3 -1
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -10
- data/ext/isomorfeus_ferret_ext/test_test.c +1 -2
- data/ext/isomorfeus_ferret_ext/test_threading.c +9 -10
- data/ext/isomorfeus_ferret_ext/testhelper.c +1 -2
- data/lib/isomorfeus/ferret/version.rb +1 -1
- metadata +113 -58
- data/ext/isomorfeus_ferret_ext/email.rl +0 -21
- data/ext/isomorfeus_ferret_ext/frt_scanner.c +0 -900
- data/ext/isomorfeus_ferret_ext/frt_scanner.h +0 -28
- data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +0 -6706
- data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +0 -4420
- data/ext/isomorfeus_ferret_ext/scanner.h +0 -28
- data/ext/isomorfeus_ferret_ext/scanner.in +0 -43
- data/ext/isomorfeus_ferret_ext/scanner.rl +0 -84
- data/ext/isomorfeus_ferret_ext/scanner_mb.rl +0 -200
- data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +0 -85
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.c +0 -1167
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.c +0 -1433
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +0 -301
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +0 -590
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +0 -1049
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +0 -705
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +0 -1239
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +0 -477
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +0 -1217
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +0 -7
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.c +0 -394
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.c +0 -457
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +0 -1009
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +0 -259
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +0 -704
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +0 -948
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +0 -1028
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +0 -275
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.c +0 -849
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +0 -952
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +0 -669
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +0 -6
- data/ext/isomorfeus_ferret_ext/stem_modules.txt +0 -63
- data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +0 -1854
- data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +0 -1999
- data/ext/isomorfeus_ferret_ext/url.rl +0 -27
@@ -2,6 +2,9 @@
|
|
2
2
|
#include <string.h>
|
3
3
|
#include "frt_search.h"
|
4
4
|
|
5
|
+
#undef close
|
6
|
+
#undef read
|
7
|
+
|
5
8
|
#define TQ(query) ((FrtTermQuery *)(query))
|
6
9
|
#define TSc(scorer) ((TermScorer *)(scorer))
|
7
10
|
|
@@ -14,30 +17,27 @@
|
|
14
17
|
#define SCORE_CACHE_SIZE 32
|
15
18
|
#define TDE_READ_SIZE 32
|
16
19
|
|
17
|
-
typedef struct TermScorer
|
18
|
-
|
19
|
-
|
20
|
-
int
|
21
|
-
int
|
22
|
-
int
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
float weight_value;
|
20
|
+
typedef struct TermScorer {
|
21
|
+
FrtScorer super;
|
22
|
+
int docs[TDE_READ_SIZE];
|
23
|
+
int freqs[TDE_READ_SIZE];
|
24
|
+
int pointer;
|
25
|
+
int pointer_max;
|
26
|
+
float score_cache[SCORE_CACHE_SIZE];
|
27
|
+
FrtWeight *weight;
|
28
|
+
FrtTermDocEnum *tde;
|
29
|
+
frt_uchar *norms;
|
30
|
+
float weight_value;
|
29
31
|
} TermScorer;
|
30
32
|
|
31
|
-
static float tsc_score(FrtScorer *self)
|
32
|
-
{
|
33
|
+
static float tsc_score(FrtScorer *self) {
|
33
34
|
TermScorer *ts = TSc(self);
|
34
35
|
int freq = ts->freqs[ts->pointer];
|
35
36
|
float score;
|
36
37
|
/* compute tf(f)*weight */
|
37
38
|
if (freq < SCORE_CACHE_SIZE) { /* check cache */
|
38
39
|
score = ts->score_cache[freq]; /* cache hit */
|
39
|
-
}
|
40
|
-
else {
|
40
|
+
} else {
|
41
41
|
/* cache miss */
|
42
42
|
score = frt_sim_tf(self->similarity, (float)freq) * ts->weight_value;
|
43
43
|
}
|
@@ -46,19 +46,16 @@ static float tsc_score(FrtScorer *self)
|
|
46
46
|
return score;
|
47
47
|
}
|
48
48
|
|
49
|
-
static bool tsc_next(FrtScorer *self)
|
50
|
-
{
|
49
|
+
static bool tsc_next(FrtScorer *self) {
|
51
50
|
TermScorer *ts = TSc(self);
|
52
51
|
|
53
52
|
ts->pointer++;
|
54
53
|
if (ts->pointer >= ts->pointer_max) {
|
55
54
|
/* refill buffer */
|
56
|
-
ts->pointer_max = ts->tde->read(ts->tde, ts->docs, ts->freqs,
|
57
|
-
TDE_READ_SIZE);
|
55
|
+
ts->pointer_max = ts->tde->read(ts->tde, ts->docs, ts->freqs, TDE_READ_SIZE);
|
58
56
|
if (ts->pointer_max != 0) {
|
59
57
|
ts->pointer = 0;
|
60
|
-
}
|
61
|
-
else {
|
58
|
+
} else {
|
62
59
|
return false;
|
63
60
|
}
|
64
61
|
}
|
@@ -66,8 +63,7 @@ static bool tsc_next(FrtScorer *self)
|
|
66
63
|
return true;
|
67
64
|
}
|
68
65
|
|
69
|
-
static bool tsc_skip_to(FrtScorer *self, int doc_num)
|
70
|
-
{
|
66
|
+
static bool tsc_skip_to(FrtScorer *self, int doc_num) {
|
71
67
|
TermScorer *ts = TSc(self);
|
72
68
|
FrtTermDocEnum *tde = ts->tde;
|
73
69
|
|
@@ -86,14 +82,12 @@ static bool tsc_skip_to(FrtScorer *self, int doc_num)
|
|
86
82
|
ts->docs[0] = self->doc = tde->doc_num(tde);
|
87
83
|
ts->freqs[0] = tde->freq(tde);
|
88
84
|
return true;
|
89
|
-
}
|
90
|
-
else {
|
85
|
+
} else {
|
91
86
|
return false;
|
92
87
|
}
|
93
88
|
}
|
94
89
|
|
95
|
-
static FrtExplanation *tsc_explain(FrtScorer *self, int doc_num)
|
96
|
-
{
|
90
|
+
static FrtExplanation *tsc_explain(FrtScorer *self, int doc_num) {
|
97
91
|
TermScorer *ts = TSc(self);
|
98
92
|
FrtQuery *query = ts->weight->get_query(ts->weight);
|
99
93
|
int tf = 0;
|
@@ -107,14 +101,12 @@ static FrtExplanation *tsc_explain(FrtScorer *self, int doc_num)
|
|
107
101
|
rb_id2name(TQ(query)->field), TQ(query)->term, tf);
|
108
102
|
}
|
109
103
|
|
110
|
-
static void tsc_destroy(FrtScorer *self)
|
111
|
-
{
|
104
|
+
static void tsc_destroy(FrtScorer *self) {
|
112
105
|
TSc(self)->tde->close(TSc(self)->tde);
|
113
106
|
frt_scorer_destroy_i(self);
|
114
107
|
}
|
115
108
|
|
116
|
-
static FrtScorer *tsc_new(FrtWeight *weight, FrtTermDocEnum *tde, frt_uchar *norms)
|
117
|
-
{
|
109
|
+
static FrtScorer *tsc_new(FrtWeight *weight, FrtTermDocEnum *tde, frt_uchar *norms) {
|
118
110
|
int i;
|
119
111
|
FrtScorer *self = frt_scorer_new(TermScorer, weight->similarity);
|
120
112
|
TSc(self)->weight = weight;
|
@@ -141,8 +133,7 @@ static FrtScorer *tsc_new(FrtWeight *weight, FrtTermDocEnum *tde, frt_uchar *nor
|
|
141
133
|
*
|
142
134
|
***************************************************************************/
|
143
135
|
|
144
|
-
static FrtScorer *tw_scorer(FrtWeight *self, FrtIndexReader *ir)
|
145
|
-
{
|
136
|
+
static FrtScorer *tw_scorer(FrtWeight *self, FrtIndexReader *ir) {
|
146
137
|
FrtTermQuery *tq = TQ(self->query);
|
147
138
|
FrtTermDocEnum *tde = ir_term_docs_for(ir, tq->field, tq->term);
|
148
139
|
/* ir_term_docs_for should always return a TermDocEnum */
|
@@ -151,8 +142,7 @@ static FrtScorer *tw_scorer(FrtWeight *self, FrtIndexReader *ir)
|
|
151
142
|
return tsc_new(self, tde, frt_ir_get_norms(ir, tq->field));
|
152
143
|
}
|
153
144
|
|
154
|
-
static FrtExplanation *tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_num)
|
155
|
-
{
|
145
|
+
static FrtExplanation *tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_num) {
|
156
146
|
FrtExplanation *qnorm_expl;
|
157
147
|
FrtExplanation *field_expl;
|
158
148
|
FrtScorer *scorer;
|
@@ -160,7 +150,7 @@ static FrtExplanation *tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_n
|
|
160
150
|
frt_uchar *field_norms;
|
161
151
|
float field_norm;
|
162
152
|
FrtExplanation *field_norm_expl;
|
163
|
-
char *query_str = self->query->to_s(self->query, (
|
153
|
+
char *query_str = self->query->to_s(self->query, (ID)NULL);
|
164
154
|
FrtTermQuery *tq = TQ(self->query);
|
165
155
|
char *term = tq->term;
|
166
156
|
FrtExplanation *expl = frt_expl_new(0.0, "weight(%s in %d), product of:", query_str, doc_num);
|
@@ -203,14 +193,12 @@ static FrtExplanation *tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_n
|
|
203
193
|
}
|
204
194
|
}
|
205
195
|
|
206
|
-
static char *tw_to_s(FrtWeight *self)
|
207
|
-
{
|
196
|
+
static char *tw_to_s(FrtWeight *self) {
|
208
197
|
return frt_strfmt("TermWeight(%f)", self->value);
|
209
198
|
}
|
210
199
|
|
211
|
-
static FrtWeight *tw_new(FrtQuery *query, FrtSearcher *searcher)
|
212
|
-
|
213
|
-
FrtWeight *self = w_new(FrtWeight, query);
|
200
|
+
static FrtWeight *tw_new(FrtQuery *query, FrtSearcher *searcher) {
|
201
|
+
FrtWeight *self = w_new(FrtWeight, query);
|
214
202
|
self->scorer = &tw_scorer;
|
215
203
|
self->explain = &tw_explain;
|
216
204
|
self->to_s = &tw_to_s;
|
@@ -231,14 +219,12 @@ static FrtWeight *tw_new(FrtQuery *query, FrtSearcher *searcher)
|
|
231
219
|
*
|
232
220
|
***************************************************************************/
|
233
221
|
|
234
|
-
static void tq_destroy(FrtQuery *self)
|
235
|
-
{
|
222
|
+
static void tq_destroy(FrtQuery *self) {
|
236
223
|
free(TQ(self)->term);
|
237
224
|
frt_q_destroy_i(self);
|
238
225
|
}
|
239
226
|
|
240
|
-
static char *tq_to_s(FrtQuery *self,
|
241
|
-
{
|
227
|
+
static char *tq_to_s(FrtQuery *self, ID default_field) {
|
242
228
|
const char *field_name = rb_id2name(TQ(self)->field);
|
243
229
|
size_t flen = strlen(field_name);
|
244
230
|
const char *term = TQ(self)->term;
|
@@ -260,25 +246,19 @@ static char *tq_to_s(FrtQuery *self, FrtSymbol default_field)
|
|
260
246
|
return buffer;
|
261
247
|
}
|
262
248
|
|
263
|
-
static void tq_extract_terms(FrtQuery *self, FrtHashSet *terms)
|
264
|
-
{
|
249
|
+
static void tq_extract_terms(FrtQuery *self, FrtHashSet *terms) {
|
265
250
|
frt_hs_add(terms, frt_term_new(TQ(self)->field, TQ(self)->term));
|
266
251
|
}
|
267
252
|
|
268
|
-
static unsigned long long tq_hash(FrtQuery *self)
|
269
|
-
{
|
253
|
+
static unsigned long long tq_hash(FrtQuery *self) {
|
270
254
|
return frt_str_hash(TQ(self)->term) ^ frt_str_hash(rb_id2name(TQ(self)->field));
|
271
255
|
}
|
272
256
|
|
273
|
-
static int tq_eq(FrtQuery *self, FrtQuery *o)
|
274
|
-
|
275
|
-
return (strcmp(TQ(self)->term, TQ(o)->term) == 0)
|
276
|
-
&& (TQ(self)->field == TQ(o)->field);
|
257
|
+
static int tq_eq(FrtQuery *self, FrtQuery *o) {
|
258
|
+
return (strcmp(TQ(self)->term, TQ(o)->term) == 0) && (TQ(self)->field == TQ(o)->field);
|
277
259
|
}
|
278
260
|
|
279
|
-
static FrtMatchVector *tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv,
|
280
|
-
FrtTermVector *tv)
|
281
|
-
{
|
261
|
+
static FrtMatchVector *tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv, FrtTermVector *tv) {
|
282
262
|
if (tv->field == TQ(self)->field) {
|
283
263
|
int i;
|
284
264
|
FrtTVTerm *tv_term = frt_tv_get_tv_term(tv, TQ(self)->term);
|
@@ -292,9 +272,11 @@ static FrtMatchVector *tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv,
|
|
292
272
|
return mv;
|
293
273
|
}
|
294
274
|
|
295
|
-
FrtQuery *
|
296
|
-
|
297
|
-
|
275
|
+
FrtQuery *frt_tq_alloc(void) {
|
276
|
+
return frt_q_new(FrtTermQuery);
|
277
|
+
}
|
278
|
+
|
279
|
+
FrtQuery *frt_tq_init(FrtQuery *self, ID field, const char *term) {
|
298
280
|
TQ(self)->field = field;
|
299
281
|
TQ(self)->term = frt_estrdup(term);
|
300
282
|
self->type = TERM_QUERY;
|
@@ -309,3 +291,8 @@ FrtQuery *frt_tq_new(FrtSymbol field, const char *term)
|
|
309
291
|
|
310
292
|
return self;
|
311
293
|
}
|
294
|
+
|
295
|
+
FrtQuery *frt_tq_new(ID field, const char *term) {
|
296
|
+
FrtQuery *self = frt_tq_alloc();
|
297
|
+
return frt_tq_init(self, field, term);
|
298
|
+
}
|
@@ -2,6 +2,8 @@
|
|
2
2
|
#include "frt_global.h"
|
3
3
|
#include "frt_search.h"
|
4
4
|
|
5
|
+
#undef close
|
6
|
+
|
5
7
|
/****************************************************************************
|
6
8
|
*
|
7
9
|
* FrtWildCardQuery
|
@@ -10,8 +12,7 @@
|
|
10
12
|
|
11
13
|
#define WCQ(query) ((FrtWildCardQuery *)(query))
|
12
14
|
|
13
|
-
static char *wcq_to_s(FrtQuery *self,
|
14
|
-
{
|
15
|
+
static char *wcq_to_s(FrtQuery *self, ID default_field) {
|
15
16
|
char *buffer, *bptr;
|
16
17
|
const char *field_name = rb_id2name(WCQ(self)->field);
|
17
18
|
const char *pattern = WCQ(self)->pattern;
|
@@ -30,8 +31,7 @@ static char *wcq_to_s(FrtQuery *self, FrtSymbol default_field)
|
|
30
31
|
return buffer;
|
31
32
|
}
|
32
33
|
|
33
|
-
bool frt_wc_match(const char *pattern, const char *text)
|
34
|
-
{
|
34
|
+
bool frt_wc_match(const char *pattern, const char *text) {
|
35
35
|
const char *p = pattern, *t = text, *xt;
|
36
36
|
|
37
37
|
/* include '\0' as we need to match empty string */
|
@@ -77,8 +77,7 @@ bool frt_wc_match(const char *pattern, const char *text)
|
|
77
77
|
return false;
|
78
78
|
}
|
79
79
|
|
80
|
-
static FrtQuery *wcq_rewrite(FrtQuery *self, FrtIndexReader *ir)
|
81
|
-
{
|
80
|
+
static FrtQuery *wcq_rewrite(FrtQuery *self, FrtIndexReader *ir) {
|
82
81
|
FrtQuery *q;
|
83
82
|
const char *pattern = WCQ(self)->pattern;
|
84
83
|
const char *first_star = strchr(pattern, FRT_WILD_STRING);
|
@@ -129,30 +128,28 @@ static FrtQuery *wcq_rewrite(FrtQuery *self, FrtIndexReader *ir)
|
|
129
128
|
return q;
|
130
129
|
}
|
131
130
|
|
132
|
-
static void wcq_destroy(FrtQuery *self)
|
133
|
-
{
|
131
|
+
static void wcq_destroy(FrtQuery *self) {
|
134
132
|
free(WCQ(self)->pattern);
|
135
133
|
frt_q_destroy_i(self);
|
136
134
|
}
|
137
135
|
|
138
|
-
static unsigned long long wcq_hash(FrtQuery *self)
|
139
|
-
{
|
136
|
+
static unsigned long long wcq_hash(FrtQuery *self) {
|
140
137
|
return frt_str_hash(rb_id2name(WCQ(self)->field)) ^ frt_str_hash(WCQ(self)->pattern);
|
141
138
|
}
|
142
139
|
|
143
|
-
static int wcq_eq(FrtQuery *self, FrtQuery *o)
|
144
|
-
{
|
140
|
+
static int wcq_eq(FrtQuery *self, FrtQuery *o) {
|
145
141
|
return (strcmp(WCQ(self)->pattern, WCQ(o)->pattern) == 0)
|
146
142
|
&& (WCQ(self)->field == WCQ(o)->field);
|
147
143
|
}
|
148
144
|
|
149
|
-
FrtQuery *
|
150
|
-
|
151
|
-
|
145
|
+
FrtQuery *frt_wcq_alloc(void) {
|
146
|
+
return frt_q_new(FrtWildCardQuery);
|
147
|
+
}
|
152
148
|
|
149
|
+
FrtQuery *frt_wcq_init(FrtQuery *self, ID field, const char *pattern) {
|
153
150
|
WCQ(self)->field = field;
|
154
151
|
WCQ(self)->pattern = frt_estrdup(pattern);
|
155
|
-
FrtMTQMaxTerms(self)
|
152
|
+
FrtMTQMaxTerms(self) = FRT_WILD_CARD_QUERY_MAX_TERMS;
|
156
153
|
|
157
154
|
self->type = WILD_CARD_QUERY;
|
158
155
|
self->rewrite = &wcq_rewrite;
|
@@ -164,3 +161,8 @@ FrtQuery *frt_wcq_new(FrtSymbol field, const char *pattern)
|
|
164
161
|
|
165
162
|
return self;
|
166
163
|
}
|
164
|
+
|
165
|
+
FrtQuery *frt_wcq_new(ID field, const char *pattern) {
|
166
|
+
FrtQuery *self = frt_wcq_alloc();
|
167
|
+
return frt_wcq_init(self, field, pattern);
|
168
|
+
}
|
@@ -1,8 +1,7 @@
|
|
1
1
|
#include "frt_store.h"
|
2
2
|
#include <string.h>
|
3
3
|
|
4
|
-
static FrtRAMFile *rf_new(const char *name)
|
5
|
-
{
|
4
|
+
static FrtRAMFile *rf_new(const char *name) {
|
6
5
|
FrtRAMFile *rf = FRT_ALLOC(FrtRAMFile);
|
7
6
|
rf->buffers = FRT_ALLOC(frt_uchar *);
|
8
7
|
rf->buffers[0] = FRT_ALLOC_N(frt_uchar, FRT_BUFFER_SIZE);
|
@@ -13,16 +12,14 @@ static FrtRAMFile *rf_new(const char *name)
|
|
13
12
|
return rf;
|
14
13
|
}
|
15
14
|
|
16
|
-
static void rf_extend_if_necessary(FrtRAMFile *rf, int buf_num)
|
17
|
-
{
|
15
|
+
static void rf_extend_if_necessary(FrtRAMFile *rf, int buf_num) {
|
18
16
|
while (rf->bufcnt <= buf_num) {
|
19
17
|
FRT_REALLOC_N(rf->buffers, frt_uchar *, (rf->bufcnt + 1));
|
20
18
|
rf->buffers[rf->bufcnt++] = FRT_ALLOC_N(frt_uchar, FRT_BUFFER_SIZE);
|
21
19
|
}
|
22
20
|
}
|
23
21
|
|
24
|
-
static void rf_close(void *p)
|
25
|
-
{
|
22
|
+
static void rf_close(void *p) {
|
26
23
|
int i;
|
27
24
|
FrtRAMFile *rf = (FrtRAMFile *)p;
|
28
25
|
if (rf->ref_cnt > 0) {
|
@@ -36,38 +33,32 @@ static void rf_close(void *p)
|
|
36
33
|
free(rf);
|
37
34
|
}
|
38
35
|
|
39
|
-
static void ram_touch(FrtStore *store, const char *filename)
|
40
|
-
{
|
36
|
+
static void ram_touch(FrtStore *store, const char *filename) {
|
41
37
|
if (frt_h_get(store->dir.ht, filename) == NULL) {
|
42
38
|
frt_h_set(store->dir.ht, filename, rf_new(filename));
|
43
39
|
}
|
44
40
|
}
|
45
41
|
|
46
|
-
static int ram_exists(FrtStore *store, const char *filename)
|
47
|
-
{
|
42
|
+
static int ram_exists(FrtStore *store, const char *filename) {
|
48
43
|
if (frt_h_get(store->dir.ht, filename) != NULL) {
|
49
44
|
return true;
|
50
|
-
}
|
51
|
-
else {
|
45
|
+
} else {
|
52
46
|
return false;
|
53
47
|
}
|
54
48
|
}
|
55
49
|
|
56
|
-
static int ram_remove(FrtStore *store, const char *filename)
|
57
|
-
{
|
50
|
+
static int ram_remove(FrtStore *store, const char *filename) {
|
58
51
|
FrtRAMFile *rf = (FrtRAMFile *)frt_h_rem(store->dir.ht, filename, false);
|
59
52
|
if (rf != NULL) {
|
60
53
|
FRT_DEREF(rf);
|
61
54
|
rf_close(rf);
|
62
55
|
return true;
|
63
|
-
}
|
64
|
-
else {
|
56
|
+
} else {
|
65
57
|
return false;
|
66
58
|
}
|
67
59
|
}
|
68
60
|
|
69
|
-
static void ram_rename(FrtStore *store, const char *from, const char *to)
|
70
|
-
{
|
61
|
+
static void ram_rename(FrtStore *store, const char *from, const char *to) {
|
71
62
|
FrtRAMFile *rf = (FrtRAMFile *)frt_h_rem(store->dir.ht, from, false);
|
72
63
|
FrtRAMFile *tmp;
|
73
64
|
|
@@ -89,14 +80,11 @@ static void ram_rename(FrtStore *store, const char *from, const char *to)
|
|
89
80
|
frt_h_set(store->dir.ht, rf->name, rf);
|
90
81
|
}
|
91
82
|
|
92
|
-
static int ram_count(FrtStore *store)
|
93
|
-
{
|
83
|
+
static int ram_count(FrtStore *store) {
|
94
84
|
return store->dir.ht->size;
|
95
85
|
}
|
96
86
|
|
97
|
-
static void ram_each(FrtStore *store,
|
98
|
-
void (*func)(const char *fname, void *arg), void *arg)
|
99
|
-
{
|
87
|
+
static void ram_each(FrtStore *store, void (*func)(const char *fname, void *arg), void *arg) {
|
100
88
|
FrtHash *ht = store->dir.ht;
|
101
89
|
int i;
|
102
90
|
for (i = 0; i <= ht->mask; i++) {
|
@@ -110,8 +98,7 @@ static void ram_each(FrtStore *store,
|
|
110
98
|
}
|
111
99
|
}
|
112
100
|
|
113
|
-
static void ram_close_i(FrtStore *store)
|
114
|
-
{
|
101
|
+
static void ram_close_i(FrtStore *store) {
|
115
102
|
FrtHash *ht = store->dir.ht;
|
116
103
|
int i;
|
117
104
|
for (i = 0; i <= ht->mask; i++) {
|
@@ -127,8 +114,7 @@ static void ram_close_i(FrtStore *store)
|
|
127
114
|
/*
|
128
115
|
* Be sure to keep the locks
|
129
116
|
*/
|
130
|
-
static void ram_clear(FrtStore *store)
|
131
|
-
{
|
117
|
+
static void ram_clear(FrtStore *store) {
|
132
118
|
int i;
|
133
119
|
FrtHash *ht = store->dir.ht;
|
134
120
|
for (i = 0; i <= ht->mask; i++) {
|
@@ -140,8 +126,7 @@ static void ram_clear(FrtStore *store)
|
|
140
126
|
}
|
141
127
|
}
|
142
128
|
|
143
|
-
static void ram_clear_locks(FrtStore *store)
|
144
|
-
{
|
129
|
+
static void ram_clear_locks(FrtStore *store) {
|
145
130
|
int i;
|
146
131
|
FrtHash *ht = store->dir.ht;
|
147
132
|
for (i = 0; i <= ht->mask; i++) {
|
@@ -153,8 +138,7 @@ static void ram_clear_locks(FrtStore *store)
|
|
153
138
|
}
|
154
139
|
}
|
155
140
|
|
156
|
-
static void ram_clear_all(FrtStore *store)
|
157
|
-
{
|
141
|
+
static void ram_clear_all(FrtStore *store) {
|
158
142
|
int i;
|
159
143
|
FrtHash *ht = store->dir.ht;
|
160
144
|
for (i = 0; i <= ht->mask; i++) {
|
@@ -166,19 +150,17 @@ static void ram_clear_all(FrtStore *store)
|
|
166
150
|
}
|
167
151
|
}
|
168
152
|
|
169
|
-
static off_t ram_length(FrtStore *store, const char *filename)
|
170
|
-
{
|
153
|
+
static off_t ram_length(FrtStore *store, const char *filename) {
|
171
154
|
FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(store->dir.ht, filename);
|
172
155
|
if (rf != NULL) {
|
173
156
|
return rf->len;
|
174
|
-
}
|
175
|
-
else {
|
157
|
+
} else {
|
176
158
|
return 0;
|
177
159
|
}
|
178
160
|
}
|
179
161
|
|
180
|
-
static void ramo_flush_i(FrtOutStream *os, const frt_uchar *src, int len)
|
181
|
-
{
|
162
|
+
static void ramo_flush_i(FrtOutStream *os, const frt_uchar *src, int len) {
|
163
|
+
if (len == 0) { return; }
|
182
164
|
frt_uchar *buffer;
|
183
165
|
FrtRAMFile *rf = os->file.rf;
|
184
166
|
int buffer_number, buffer_offset, bytes_in_buffer, bytes_to_copy;
|
@@ -211,26 +193,22 @@ static void ramo_flush_i(FrtOutStream *os, const frt_uchar *src, int len)
|
|
211
193
|
}
|
212
194
|
}
|
213
195
|
|
214
|
-
static void ramo_seek_i(FrtOutStream *os, off_t pos)
|
215
|
-
{
|
196
|
+
static void ramo_seek_i(FrtOutStream *os, off_t pos) {
|
216
197
|
os->pointer = pos;
|
217
198
|
}
|
218
199
|
|
219
|
-
void frt_ramo_reset(FrtOutStream *os)
|
220
|
-
{
|
200
|
+
void frt_ramo_reset(FrtOutStream *os) {
|
221
201
|
frt_os_seek(os, 0);
|
222
202
|
os->file.rf->len = 0;
|
223
203
|
}
|
224
204
|
|
225
|
-
static void ramo_close_i(FrtOutStream *os)
|
226
|
-
{
|
205
|
+
static void ramo_close_i(FrtOutStream *os) {
|
227
206
|
FrtRAMFile *rf = os->file.rf;
|
228
207
|
FRT_DEREF(rf);
|
229
208
|
rf_close(rf);
|
230
209
|
}
|
231
210
|
|
232
|
-
void frt_ramo_write_to(FrtOutStream *os, FrtOutStream *other_o)
|
233
|
-
{
|
211
|
+
void frt_ramo_write_to(FrtOutStream *os, FrtOutStream *other_o) {
|
234
212
|
int i, len;
|
235
213
|
FrtRAMFile *rf = os->file.rf;
|
236
214
|
int last_buffer_number;
|
@@ -251,8 +229,7 @@ static const struct FrtOutStreamMethods RAM_OUT_STREAM_METHODS = {
|
|
251
229
|
ramo_close_i
|
252
230
|
};
|
253
231
|
|
254
|
-
FrtOutStream *frt_ram_new_buffer()
|
255
|
-
{
|
232
|
+
FrtOutStream *frt_ram_new_buffer(void) {
|
256
233
|
FrtRAMFile *rf = rf_new("");
|
257
234
|
FrtOutStream *os = frt_os_new();
|
258
235
|
|
@@ -263,14 +240,12 @@ FrtOutStream *frt_ram_new_buffer()
|
|
263
240
|
return os;
|
264
241
|
}
|
265
242
|
|
266
|
-
void frt_ram_destroy_buffer(FrtOutStream *os)
|
267
|
-
{
|
243
|
+
void frt_ram_destroy_buffer(FrtOutStream *os) {
|
268
244
|
rf_close(os->file.rf);
|
269
245
|
free(os);
|
270
246
|
}
|
271
247
|
|
272
|
-
static FrtOutStream *ram_new_output(FrtStore *store, const char *filename)
|
273
|
-
{
|
248
|
+
static FrtOutStream *ram_new_output(FrtStore *store, const char *filename) {
|
274
249
|
FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(store->dir.ht, filename);
|
275
250
|
FrtOutStream *os = frt_os_new();
|
276
251
|
|
@@ -285,8 +260,7 @@ static FrtOutStream *ram_new_output(FrtStore *store, const char *filename)
|
|
285
260
|
return os;
|
286
261
|
}
|
287
262
|
|
288
|
-
static void rami_read_i(FrtInStream *is, frt_uchar *b, int len)
|
289
|
-
{
|
263
|
+
static void rami_read_i(FrtInStream *is, frt_uchar *b, int len) {
|
290
264
|
FrtRAMFile *rf = is->file.rf;
|
291
265
|
|
292
266
|
int offset = 0;
|
@@ -302,8 +276,7 @@ static void rami_read_i(FrtInStream *is, frt_uchar *b, int len)
|
|
302
276
|
|
303
277
|
if (bytes_in_buffer >= remainder) {
|
304
278
|
bytes_to_copy = remainder;
|
305
|
-
}
|
306
|
-
else {
|
279
|
+
} else {
|
307
280
|
bytes_to_copy = bytes_in_buffer;
|
308
281
|
}
|
309
282
|
buffer = rf->buffers[buffer_number];
|
@@ -316,18 +289,15 @@ static void rami_read_i(FrtInStream *is, frt_uchar *b, int len)
|
|
316
289
|
is->d.pointer += len;
|
317
290
|
}
|
318
291
|
|
319
|
-
static off_t rami_length_i(FrtInStream *is)
|
320
|
-
{
|
292
|
+
static off_t rami_length_i(FrtInStream *is) {
|
321
293
|
return is->file.rf->len;
|
322
294
|
}
|
323
295
|
|
324
|
-
static void rami_seek_i(FrtInStream *is, off_t pos)
|
325
|
-
{
|
296
|
+
static void rami_seek_i(FrtInStream *is, off_t pos) {
|
326
297
|
is->d.pointer = pos;
|
327
298
|
}
|
328
299
|
|
329
|
-
static void rami_close_i(FrtInStream *is)
|
330
|
-
{
|
300
|
+
static void rami_close_i(FrtInStream *is) {
|
331
301
|
FrtRAMFile *rf = is->file.rf;
|
332
302
|
FRT_DEREF(rf);
|
333
303
|
rf_close(rf);
|
@@ -340,8 +310,7 @@ static const struct FrtInStreamMethods RAM_IN_STREAM_METHODS = {
|
|
340
310
|
rami_close_i
|
341
311
|
};
|
342
312
|
|
343
|
-
static FrtInStream *ram_open_input(FrtStore *store, const char *filename)
|
344
|
-
{
|
313
|
+
static FrtInStream *ram_open_input(FrtStore *store, const char *filename) {
|
345
314
|
FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(store->dir.ht, filename);
|
346
315
|
FrtInStream *is = NULL;
|
347
316
|
|
@@ -359,8 +328,7 @@ static FrtInStream *ram_open_input(FrtStore *store, const char *filename)
|
|
359
328
|
|
360
329
|
#define LOCK_OBTAIN_TIMEOUT 5
|
361
330
|
|
362
|
-
static int ram_lock_obtain(FrtLock *lock)
|
363
|
-
{
|
331
|
+
static int ram_lock_obtain(FrtLock *lock) {
|
364
332
|
int ret = true;
|
365
333
|
if (ram_exists(lock->store, lock->name)) {
|
366
334
|
ret = false;
|
@@ -369,18 +337,15 @@ static int ram_lock_obtain(FrtLock *lock)
|
|
369
337
|
return ret;
|
370
338
|
}
|
371
339
|
|
372
|
-
static int ram_lock_is_locked(FrtLock *lock)
|
373
|
-
{
|
340
|
+
static int ram_lock_is_locked(FrtLock *lock) {
|
374
341
|
return ram_exists(lock->store, lock->name);
|
375
342
|
}
|
376
343
|
|
377
|
-
static void ram_lock_release(FrtLock *lock)
|
378
|
-
{
|
344
|
+
static void ram_lock_release(FrtLock *lock) {
|
379
345
|
ram_remove(lock->store, lock->name);
|
380
346
|
}
|
381
347
|
|
382
|
-
static FrtLock *ram_open_lock_i(FrtStore *store, const char *lockname)
|
383
|
-
{
|
348
|
+
static FrtLock *ram_open_lock_i(FrtStore *store, const char *lockname) {
|
384
349
|
FrtLock *lock = FRT_ALLOC(FrtLock);
|
385
350
|
char lname[100];
|
386
351
|
snprintf(lname, 100, "%s%s.lck", FRT_LOCK_PREFIX, lockname);
|
@@ -389,19 +354,19 @@ static FrtLock *ram_open_lock_i(FrtStore *store, const char *lockname)
|
|
389
354
|
lock->obtain = &ram_lock_obtain;
|
390
355
|
lock->release = &ram_lock_release;
|
391
356
|
lock->is_locked = &ram_lock_is_locked;
|
357
|
+
lock->rlock = Qnil;
|
392
358
|
return lock;
|
393
359
|
}
|
394
360
|
|
395
|
-
static void ram_close_lock_i(FrtLock *lock)
|
396
|
-
{
|
361
|
+
static void ram_close_lock_i(FrtLock *lock) {
|
397
362
|
free(lock->name);
|
398
363
|
free(lock);
|
399
364
|
}
|
400
365
|
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
366
|
+
FrtStore *frt_open_ram_store(FrtStore *new_store) {
|
367
|
+
if (new_store == NULL)
|
368
|
+
new_store = frt_store_alloc();
|
369
|
+
frt_store_init(new_store);
|
405
370
|
|
406
371
|
new_store->dir.ht = frt_h_new_str(NULL, rf_close);
|
407
372
|
new_store->touch = &ram_touch;
|
@@ -422,13 +387,11 @@ FrtStore *frt_open_ram_store()
|
|
422
387
|
return new_store;
|
423
388
|
}
|
424
389
|
|
425
|
-
struct CopyFileArg
|
426
|
-
{
|
390
|
+
struct CopyFileArg {
|
427
391
|
FrtStore *to_store, *from_store;
|
428
392
|
};
|
429
393
|
|
430
|
-
static void copy_files(const char *fname, void *arg)
|
431
|
-
{
|
394
|
+
static void copy_files(const char *fname, void *arg) {
|
432
395
|
struct CopyFileArg *cfa = (struct CopyFileArg *)arg;
|
433
396
|
FrtOutStream *os = cfa->to_store->new_output(cfa->to_store, fname);
|
434
397
|
FrtInStream *is = cfa->from_store->open_input(cfa->from_store, fname);
|
@@ -443,9 +406,8 @@ static void copy_files(const char *fname, void *arg)
|
|
443
406
|
free(buffer);
|
444
407
|
}
|
445
408
|
|
446
|
-
FrtStore *frt_open_ram_store_and_copy(FrtStore *from_store, bool close_dir)
|
447
|
-
|
448
|
-
FrtStore *store = frt_open_ram_store();
|
409
|
+
FrtStore *frt_open_ram_store_and_copy(FrtStore *store, FrtStore *from_store, bool close_dir) {
|
410
|
+
store = frt_open_ram_store(store);
|
449
411
|
struct CopyFileArg cfa;
|
450
412
|
cfa.to_store = store;
|
451
413
|
cfa.from_store = from_store;
|