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
@@ -1,41 +1,50 @@
|
|
1
1
|
#include "frt_bitvector.h"
|
2
2
|
#include "frt_multimapper.h"
|
3
3
|
#include "isomorfeus_ferret.h"
|
4
|
-
#include <ruby
|
4
|
+
#include <ruby.h>
|
5
5
|
|
6
6
|
/*****************
|
7
7
|
*** BitVector ***
|
8
8
|
*****************/
|
9
9
|
static VALUE cBitVector;
|
10
10
|
|
11
|
-
static void
|
12
|
-
frb_bv_free(void *p)
|
13
|
-
{
|
14
|
-
object_del(p);
|
11
|
+
static void frb_bv_free(void *p) {
|
15
12
|
frt_bv_destroy((FrtBitVector *)p);
|
16
13
|
}
|
17
14
|
|
18
|
-
static
|
19
|
-
|
20
|
-
|
15
|
+
static size_t frb_bv_size(const void *p) {
|
16
|
+
return sizeof(FrtBitVector);
|
17
|
+
(void)p;
|
18
|
+
}
|
19
|
+
|
20
|
+
const rb_data_type_t frb_bv_t = {
|
21
|
+
.wrap_struct_name = "FrbBitVector",
|
22
|
+
.function = {
|
23
|
+
.dmark = NULL,
|
24
|
+
.dfree = frb_bv_free,
|
25
|
+
.dsize = frb_bv_size,
|
26
|
+
.dcompact = NULL,
|
27
|
+
.reserved = {0},
|
28
|
+
},
|
29
|
+
.parent = NULL,
|
30
|
+
.data = NULL,
|
31
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
32
|
+
};
|
33
|
+
|
34
|
+
static VALUE frb_bv_alloc(VALUE klass) {
|
21
35
|
FrtBitVector *bv = frt_bv_new();
|
22
|
-
|
23
|
-
|
24
|
-
return rbv;
|
36
|
+
bv->rbv = TypedData_Wrap_Struct(klass, &frb_bv_t, bv);
|
37
|
+
return bv->rbv;
|
25
38
|
}
|
26
39
|
|
27
|
-
#define GET_BV(bv, self)
|
40
|
+
#define GET_BV(bv, self) TypedData_Get_Struct(self, FrtBitVector, &frb_bv_t, bv)
|
28
41
|
|
29
|
-
VALUE
|
30
|
-
|
31
|
-
|
32
|
-
VALUE rbv;
|
33
|
-
if ((rbv = object_get(bv)) == Qnil) {
|
34
|
-
rbv = Data_Wrap_Struct(cBitVector, NULL, &frb_bv_free, bv);
|
42
|
+
VALUE frb_get_bv(FrtBitVector *bv) {
|
43
|
+
if (bv->rbv == 0 || bv->rbv == Qnil) {
|
44
|
+
bv->rbv = TypedData_Wrap_Struct(cBitVector, &frb_bv_t, bv);
|
35
45
|
FRT_REF(bv);
|
36
|
-
object_add(bv, rbv);
|
37
46
|
}
|
38
|
-
return rbv;
|
47
|
+
return bv->rbv;
|
39
48
|
}
|
40
49
|
|
41
50
|
/*
|
@@ -44,9 +53,7 @@ frb_get_bv(FrtBitVector *bv)
|
|
44
53
|
*
|
45
54
|
* Returns a new empty bit vector object
|
46
55
|
*/
|
47
|
-
static VALUE
|
48
|
-
frb_bv_init(VALUE self)
|
49
|
-
{
|
56
|
+
static VALUE frb_bv_init(VALUE self) {
|
50
57
|
return self;
|
51
58
|
}
|
52
59
|
|
@@ -57,9 +64,7 @@ frb_bv_init(VALUE self)
|
|
57
64
|
* Set the bit and _i_ to *val* (+true+ or
|
58
65
|
* +false+).
|
59
66
|
*/
|
60
|
-
VALUE
|
61
|
-
frb_bv_set(VALUE self, VALUE rindex, VALUE rstate)
|
62
|
-
{
|
67
|
+
VALUE frb_bv_set(VALUE self, VALUE rindex, VALUE rstate) {
|
63
68
|
FrtBitVector *bv;
|
64
69
|
int index = FIX2INT(rindex);
|
65
70
|
GET_BV(bv, self);
|
@@ -68,8 +73,7 @@ frb_bv_set(VALUE self, VALUE rindex, VALUE rstate)
|
|
68
73
|
}
|
69
74
|
if (RTEST(rstate)) {
|
70
75
|
frt_bv_set(bv, index);
|
71
|
-
}
|
72
|
-
else {
|
76
|
+
} else {
|
73
77
|
frt_bv_unset(bv, index);
|
74
78
|
}
|
75
79
|
|
@@ -82,9 +86,7 @@ frb_bv_set(VALUE self, VALUE rindex, VALUE rstate)
|
|
82
86
|
*
|
83
87
|
* Set the bit at _i_ to *on* (+true+)
|
84
88
|
*/
|
85
|
-
VALUE
|
86
|
-
frb_bv_set_on(VALUE self, VALUE rindex)
|
87
|
-
{
|
89
|
+
VALUE frb_bv_set_on(VALUE self, VALUE rindex) {
|
88
90
|
frb_bv_set(self, rindex, Qtrue);
|
89
91
|
return self;
|
90
92
|
}
|
@@ -95,9 +97,7 @@ frb_bv_set_on(VALUE self, VALUE rindex)
|
|
95
97
|
*
|
96
98
|
* Set the bit at _i_ to *off* (+false+)
|
97
99
|
*/
|
98
|
-
VALUE
|
99
|
-
frb_bv_set_off(VALUE self, VALUE rindex)
|
100
|
-
{
|
100
|
+
VALUE frb_bv_set_off(VALUE self, VALUE rindex) {
|
101
101
|
frb_bv_set(self, rindex, Qfalse);
|
102
102
|
return self;
|
103
103
|
}
|
@@ -109,9 +109,7 @@ frb_bv_set_off(VALUE self, VALUE rindex)
|
|
109
109
|
*
|
110
110
|
* Get the bit value at _i_
|
111
111
|
*/
|
112
|
-
VALUE
|
113
|
-
frb_bv_get(VALUE self, VALUE rindex)
|
114
|
-
{
|
112
|
+
VALUE frb_bv_get(VALUE self, VALUE rindex) {
|
115
113
|
FrtBitVector *bv;
|
116
114
|
int index = FIX2INT(rindex);
|
117
115
|
GET_BV(bv, self);
|
@@ -130,9 +128,7 @@ frb_bv_get(VALUE self, VALUE rindex)
|
|
130
128
|
* negated using +#not+ then count the number of unset bits
|
131
129
|
* instead.
|
132
130
|
*/
|
133
|
-
VALUE
|
134
|
-
frb_bv_count(VALUE self)
|
135
|
-
{
|
131
|
+
VALUE frb_bv_count(VALUE self) {
|
136
132
|
FrtBitVector *bv;
|
137
133
|
GET_BV(bv, self);
|
138
134
|
return INT2FIX(bv->count);
|
@@ -145,9 +141,7 @@ frb_bv_count(VALUE self)
|
|
145
141
|
* Clears all set bits in the bit vector. Negated bit vectors will still have
|
146
142
|
* all bits set to *off*.
|
147
143
|
*/
|
148
|
-
VALUE
|
149
|
-
frb_bv_clear(VALUE self)
|
150
|
-
{
|
144
|
+
VALUE frb_bv_clear(VALUE self) {
|
151
145
|
FrtBitVector *bv;
|
152
146
|
GET_BV(bv, self);
|
153
147
|
frt_bv_clear(bv);
|
@@ -164,9 +158,7 @@ frb_bv_clear(VALUE self)
|
|
164
158
|
* Compares two bit vectors and returns true if both bit vectors have the same
|
165
159
|
* bits set.
|
166
160
|
*/
|
167
|
-
VALUE
|
168
|
-
frb_bv_eql(VALUE self, VALUE other)
|
169
|
-
{
|
161
|
+
VALUE frb_bv_eql(VALUE self, VALUE other) {
|
170
162
|
FrtBitVector *bv1, *bv2;
|
171
163
|
GET_BV(bv1, self);
|
172
164
|
GET_BV(bv2, other);
|
@@ -180,9 +172,7 @@ frb_bv_eql(VALUE self, VALUE other)
|
|
180
172
|
* Used to store bit vectors in Hashes. Especially useful if you want to
|
181
173
|
* cache them.
|
182
174
|
*/
|
183
|
-
VALUE
|
184
|
-
frb_bv_hash(VALUE self)
|
185
|
-
{
|
175
|
+
VALUE frb_bv_hash(VALUE self) {
|
186
176
|
FrtBitVector *bv;
|
187
177
|
GET_BV(bv, self);
|
188
178
|
return ULONG2NUM(frt_bv_hash(bv));
|
@@ -196,13 +186,13 @@ frb_bv_hash(VALUE self)
|
|
196
186
|
* Perform a boolean _and_ operation on +bv1+ and
|
197
187
|
* +bv2+
|
198
188
|
*/
|
199
|
-
VALUE
|
200
|
-
|
201
|
-
{
|
202
|
-
FrtBitVector *bv1, *bv2;
|
189
|
+
VALUE frb_bv_and(VALUE self, VALUE other) {
|
190
|
+
FrtBitVector *bv1, *bv2, *bv3;
|
203
191
|
GET_BV(bv1, self);
|
204
192
|
GET_BV(bv2, other);
|
205
|
-
|
193
|
+
bv3 = frt_bv_and(bv1, bv2);
|
194
|
+
bv3->rbv = TypedData_Wrap_Struct(cBitVector, &frb_bv_t, bv3);
|
195
|
+
return bv3->rbv;
|
206
196
|
}
|
207
197
|
|
208
198
|
/*
|
@@ -212,9 +202,7 @@ frb_bv_and(VALUE self, VALUE other)
|
|
212
202
|
* Perform a boolean _and_ operation on +bv1+ and
|
213
203
|
* +bv2+ in place on +bv1+
|
214
204
|
*/
|
215
|
-
VALUE
|
216
|
-
frb_bv_and_x(VALUE self, VALUE other)
|
217
|
-
{
|
205
|
+
VALUE frb_bv_and_x(VALUE self, VALUE other) {
|
218
206
|
FrtBitVector *bv1, *bv2;
|
219
207
|
GET_BV(bv1, self);
|
220
208
|
GET_BV(bv2, other);
|
@@ -230,13 +218,13 @@ frb_bv_and_x(VALUE self, VALUE other)
|
|
230
218
|
* Perform a boolean _or_ operation on +bv1+ and
|
231
219
|
* +bv2+
|
232
220
|
*/
|
233
|
-
VALUE
|
234
|
-
|
235
|
-
{
|
236
|
-
FrtBitVector *bv1, *bv2;
|
221
|
+
VALUE frb_bv_or(VALUE self, VALUE other) {
|
222
|
+
FrtBitVector *bv1, *bv2, *bv3;
|
237
223
|
GET_BV(bv1, self);
|
238
224
|
GET_BV(bv2, other);
|
239
|
-
|
225
|
+
bv3 = frt_bv_or(bv1, bv2);
|
226
|
+
bv3->rbv = TypedData_Wrap_Struct(cBitVector, &frb_bv_t, bv3);
|
227
|
+
return bv3->rbv;
|
240
228
|
}
|
241
229
|
|
242
230
|
/*
|
@@ -246,9 +234,7 @@ frb_bv_or(VALUE self, VALUE other)
|
|
246
234
|
* Perform a boolean _or_ operation on +bv1+ and
|
247
235
|
* +bv2+ in place on +bv1+
|
248
236
|
*/
|
249
|
-
VALUE
|
250
|
-
frb_bv_or_x(VALUE self, VALUE other)
|
251
|
-
{
|
237
|
+
VALUE frb_bv_or_x(VALUE self, VALUE other) {
|
252
238
|
FrtBitVector *bv1, *bv2;
|
253
239
|
GET_BV(bv1, self);
|
254
240
|
GET_BV(bv2, other);
|
@@ -264,13 +250,13 @@ frb_bv_or_x(VALUE self, VALUE other)
|
|
264
250
|
* Perform a boolean _xor_ operation on +bv1+ and
|
265
251
|
* +bv2+
|
266
252
|
*/
|
267
|
-
VALUE
|
268
|
-
|
269
|
-
{
|
270
|
-
FrtBitVector *bv1, *bv2;
|
253
|
+
VALUE frb_bv_xor(VALUE self, VALUE other) {
|
254
|
+
FrtBitVector *bv1, *bv2, *bv3;
|
271
255
|
GET_BV(bv1, self);
|
272
256
|
GET_BV(bv2, other);
|
273
|
-
|
257
|
+
bv3 = frt_bv_xor(bv1, bv2);
|
258
|
+
bv3->rbv = TypedData_Wrap_Struct(cBitVector, &frb_bv_t, bv3);
|
259
|
+
return bv3->rbv;
|
274
260
|
}
|
275
261
|
|
276
262
|
/*
|
@@ -280,9 +266,7 @@ frb_bv_xor(VALUE self, VALUE other)
|
|
280
266
|
* Perform a boolean _xor_ operation on +bv1+ and
|
281
267
|
* +bv2+ in place on +bv1+
|
282
268
|
*/
|
283
|
-
VALUE
|
284
|
-
frb_bv_xor_x(VALUE self, VALUE other)
|
285
|
-
{
|
269
|
+
VALUE frb_bv_xor_x(VALUE self, VALUE other) {
|
286
270
|
FrtBitVector *bv1, *bv2;
|
287
271
|
GET_BV(bv1, self);
|
288
272
|
GET_BV(bv2, other);
|
@@ -297,12 +281,12 @@ frb_bv_xor_x(VALUE self, VALUE other)
|
|
297
281
|
*
|
298
282
|
* Perform a boolean _not_ operation on +bv+
|
299
283
|
* */
|
300
|
-
VALUE
|
301
|
-
|
302
|
-
{
|
303
|
-
FrtBitVector *bv;
|
284
|
+
VALUE frb_bv_not(VALUE self) {
|
285
|
+
FrtBitVector *bv, *bv3;
|
304
286
|
GET_BV(bv, self);
|
305
|
-
|
287
|
+
bv3 = frt_bv_not(bv);
|
288
|
+
bv3->rbv = TypedData_Wrap_Struct(cBitVector, &frb_bv_t, bv3);
|
289
|
+
return bv3->rbv;
|
306
290
|
}
|
307
291
|
|
308
292
|
/*
|
@@ -311,9 +295,7 @@ frb_bv_not(VALUE self)
|
|
311
295
|
*
|
312
296
|
* Perform a boolean _not_ operation on +bv+ in-place
|
313
297
|
*/
|
314
|
-
VALUE
|
315
|
-
frb_bv_not_x(VALUE self)
|
316
|
-
{
|
298
|
+
VALUE frb_bv_not_x(VALUE self) {
|
317
299
|
FrtBitVector *bv;
|
318
300
|
GET_BV(bv, self);
|
319
301
|
frt_bv_not_x(bv);
|
@@ -328,9 +310,7 @@ frb_bv_not_x(VALUE self)
|
|
328
310
|
* before calling +#next+ or +#next_unset+. It isn't
|
329
311
|
* necessary for the other scan methods or for the +#each+ method.
|
330
312
|
*/
|
331
|
-
VALUE
|
332
|
-
frb_bv_reset_scan(VALUE self)
|
333
|
-
{
|
313
|
+
VALUE frb_bv_reset_scan(VALUE self) {
|
334
314
|
FrtBitVector *bv;
|
335
315
|
GET_BV(bv, self);
|
336
316
|
frt_bv_scan_reset(bv);
|
@@ -346,9 +326,7 @@ frb_bv_reset_scan(VALUE self)
|
|
346
326
|
* if you want to scan from the beginning. It is automatically reset when you
|
347
327
|
* first create the bit vector.
|
348
328
|
*/
|
349
|
-
VALUE
|
350
|
-
frb_bv_next(VALUE self)
|
351
|
-
{
|
329
|
+
VALUE frb_bv_next(VALUE self) {
|
352
330
|
FrtBitVector *bv;
|
353
331
|
GET_BV(bv, self);
|
354
332
|
return INT2FIX(frt_bv_scan_next(bv));
|
@@ -364,9 +342,7 @@ frb_bv_next(VALUE self)
|
|
364
342
|
* calling this method if you want to scan from the beginning. It is
|
365
343
|
* automatically reset when you first create the bit vector.
|
366
344
|
*/
|
367
|
-
VALUE
|
368
|
-
frb_bv_next_unset(VALUE self)
|
369
|
-
{
|
345
|
+
VALUE frb_bv_next_unset(VALUE self) {
|
370
346
|
FrtBitVector *bv;
|
371
347
|
GET_BV(bv, self);
|
372
348
|
return INT2FIX(frt_bv_scan_next_unset(bv));
|
@@ -382,9 +358,7 @@ frb_bv_next_unset(VALUE self)
|
|
382
358
|
* return the number 10. If the bit vector has been negated than you should
|
383
359
|
* use the +#next_unset_from+ method.
|
384
360
|
*/
|
385
|
-
VALUE
|
386
|
-
frb_bv_next_from(VALUE self, VALUE rfrom)
|
387
|
-
{
|
361
|
+
VALUE frb_bv_next_from(VALUE self, VALUE rfrom) {
|
388
362
|
FrtBitVector *bv;
|
389
363
|
int from = FIX2INT(rfrom);
|
390
364
|
GET_BV(bv, self);
|
@@ -404,9 +378,7 @@ frb_bv_next_from(VALUE self, VALUE rfrom)
|
|
404
378
|
* return the number 10. If the bit vector has not been negated than you
|
405
379
|
* should use the +#next_from+ method.
|
406
380
|
*/
|
407
|
-
VALUE
|
408
|
-
frb_bv_next_unset_from(VALUE self, VALUE rfrom)
|
409
|
-
{
|
381
|
+
VALUE frb_bv_next_unset_from(VALUE self, VALUE rfrom) {
|
410
382
|
FrtBitVector *bv;
|
411
383
|
int from = FIX2INT(rfrom);
|
412
384
|
GET_BV(bv, self);
|
@@ -423,9 +395,7 @@ frb_bv_next_unset_from(VALUE self, VALUE rfrom)
|
|
423
395
|
* Iterate through all the set bits in the bit vector yielding each one in
|
424
396
|
* order
|
425
397
|
*/
|
426
|
-
VALUE
|
427
|
-
frb_bv_each(VALUE self)
|
428
|
-
{
|
398
|
+
VALUE frb_bv_each(VALUE self) {
|
429
399
|
FrtBitVector *bv;
|
430
400
|
int bit;
|
431
401
|
GET_BV(bv, self);
|
@@ -434,8 +404,7 @@ frb_bv_each(VALUE self)
|
|
434
404
|
while ((bit = frt_bv_scan_next_unset(bv)) >= 0) {
|
435
405
|
rb_yield(INT2FIX(bit));
|
436
406
|
}
|
437
|
-
}
|
438
|
-
else {
|
407
|
+
} else {
|
439
408
|
while ((bit = frt_bv_scan_next(bv)) >= 0) {
|
440
409
|
rb_yield(INT2FIX(bit));
|
441
410
|
}
|
@@ -454,9 +423,7 @@ frb_bv_each(VALUE self)
|
|
454
423
|
*
|
455
424
|
* bv = [1, 12, 45, 367, 455].inject(FrtBitVector.new) {|bv, i| bv.set(i)}
|
456
425
|
*/
|
457
|
-
VALUE
|
458
|
-
frb_bv_to_a(VALUE self)
|
459
|
-
{
|
426
|
+
VALUE frb_bv_to_a(VALUE self) {
|
460
427
|
FrtBitVector *bv;
|
461
428
|
int bit;
|
462
429
|
VALUE ary;
|
@@ -467,8 +434,7 @@ frb_bv_to_a(VALUE self)
|
|
467
434
|
while ((bit = frt_bv_scan_next_unset(bv)) >= 0) {
|
468
435
|
rb_ary_push(ary, INT2FIX(bit));
|
469
436
|
}
|
470
|
-
}
|
471
|
-
else {
|
437
|
+
} else {
|
472
438
|
while ((bit = frt_bv_scan_next(bv)) >= 0) {
|
473
439
|
rb_ary_push(ary, INT2FIX(bit));
|
474
440
|
}
|
@@ -524,9 +490,7 @@ static VALUE mUtils;
|
|
524
490
|
* automatically scan unset bits if the BitVector has been flipped (using
|
525
491
|
* +not+).
|
526
492
|
*/
|
527
|
-
static void
|
528
|
-
Init_BitVector(void)
|
529
|
-
{
|
493
|
+
static void Init_BitVector(void) {
|
530
494
|
/* BitVector */
|
531
495
|
cBitVector = rb_define_class_under(mUtils, "BitVector", rb_cObject);
|
532
496
|
rb_define_alloc_func(cBitVector, frb_bv_alloc);
|
@@ -568,26 +532,37 @@ Init_BitVector(void)
|
|
568
532
|
*******************/
|
569
533
|
static VALUE cMultiMapper;
|
570
534
|
|
571
|
-
static void
|
572
|
-
frb_mulmap_free(void *p)
|
573
|
-
{
|
574
|
-
object_del(p);
|
535
|
+
static void frb_mulmap_free(void *p) {
|
575
536
|
frt_mulmap_destroy((FrtMultiMapper *)p);
|
576
537
|
}
|
577
538
|
|
578
|
-
static
|
579
|
-
|
580
|
-
|
539
|
+
static size_t frb_mulmap_size(const void *p) {
|
540
|
+
return sizeof(FrtMultiMapper);
|
541
|
+
(void)p;
|
542
|
+
}
|
543
|
+
|
544
|
+
const rb_data_type_t frb_mulmap_t = {
|
545
|
+
.wrap_struct_name = "FrbMultiMapper",
|
546
|
+
.function = {
|
547
|
+
.dmark = NULL,
|
548
|
+
.dfree = frb_mulmap_free,
|
549
|
+
.dsize = frb_mulmap_size,
|
550
|
+
.dcompact = NULL,
|
551
|
+
.reserved = {0},
|
552
|
+
},
|
553
|
+
.parent = NULL,
|
554
|
+
.data = NULL,
|
555
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
556
|
+
};
|
557
|
+
|
558
|
+
static VALUE frb_mulmap_alloc(VALUE klass) {
|
581
559
|
FrtMultiMapper *mulmap = frt_mulmap_new();
|
582
|
-
VALUE rmulmap =
|
583
|
-
object_add(mulmap, rmulmap);
|
560
|
+
VALUE rmulmap = TypedData_Wrap_Struct(klass, &frb_mulmap_t, mulmap);
|
584
561
|
return rmulmap;
|
585
562
|
}
|
586
563
|
|
587
564
|
/* XXX: Duplication from frb_add_mapping_i in r_analysis.c */
|
588
|
-
static void frb_mulmap_add_mapping_i(FrtMultiMapper *mulmap, VALUE from,
|
589
|
-
const char *to)
|
590
|
-
{
|
565
|
+
static void frb_mulmap_add_mapping_i(FrtMultiMapper *mulmap, VALUE from, const char *to) {
|
591
566
|
switch (TYPE(from)) {
|
592
567
|
case T_STRING:
|
593
568
|
frt_mulmap_add_mapping(mulmap, rs2s(from), to);
|
@@ -596,16 +571,13 @@ static void frb_mulmap_add_mapping_i(FrtMultiMapper *mulmap, VALUE from,
|
|
596
571
|
frt_mulmap_add_mapping(mulmap, rb_id2name(SYM2ID(from)), to);
|
597
572
|
break;
|
598
573
|
default:
|
599
|
-
rb_raise(rb_eArgError,
|
600
|
-
"cannot map from %s with MappingFilter",
|
601
|
-
rs2s(rb_obj_as_string(from)));
|
574
|
+
rb_raise(rb_eArgError, "cannot map from %s with MappingFilter", rs2s(rb_obj_as_string(from)));
|
602
575
|
break;
|
603
576
|
}
|
604
577
|
}
|
605
578
|
|
606
579
|
/* XXX: Duplication from frb_add_mappings_i in r_analysis.c */
|
607
|
-
static int frb_mulmap_add_mappings_i(VALUE key, VALUE value, VALUE arg)
|
608
|
-
{
|
580
|
+
static int frb_mulmap_add_mappings_i(VALUE key, VALUE value, VALUE arg) {
|
609
581
|
if (key == Qundef) {
|
610
582
|
return ST_CONTINUE;
|
611
583
|
} else {
|
@@ -619,9 +591,7 @@ static int frb_mulmap_add_mappings_i(VALUE key, VALUE value, VALUE arg)
|
|
619
591
|
to = rb_id2name(SYM2ID(value));
|
620
592
|
break;
|
621
593
|
default:
|
622
|
-
rb_raise(rb_eArgError,
|
623
|
-
"cannot map to %s with MultiMapper",
|
624
|
-
rs2s(rb_obj_as_string(key)));
|
594
|
+
rb_raise(rb_eArgError, "cannot map to %s with MultiMapper", rs2s(rb_obj_as_string(key)));
|
625
595
|
break;
|
626
596
|
}
|
627
597
|
if (TYPE(key) == T_ARRAY) {
|
@@ -645,9 +615,7 @@ static int frb_mulmap_add_mappings_i(VALUE key, VALUE value, VALUE arg)
|
|
645
615
|
*
|
646
616
|
* Note that MultiMapper is immutable.
|
647
617
|
*/
|
648
|
-
static VALUE
|
649
|
-
frb_mulmap_init(VALUE self, VALUE rmappings)
|
650
|
-
{
|
618
|
+
static VALUE frb_mulmap_init(VALUE self, VALUE rmappings) {
|
651
619
|
FrtMultiMapper *mulmap = DATA_PTR(self);
|
652
620
|
rb_hash_foreach(rmappings, frb_mulmap_add_mappings_i, (VALUE)mulmap);
|
653
621
|
frt_mulmap_compile(mulmap);
|
@@ -661,9 +629,7 @@ frb_mulmap_init(VALUE self, VALUE rmappings)
|
|
661
629
|
*
|
662
630
|
* Performs all the mappings on the string.
|
663
631
|
*/
|
664
|
-
VALUE
|
665
|
-
frb_mulmap_map(VALUE self, VALUE rstring)
|
666
|
-
{
|
632
|
+
VALUE frb_mulmap_map(VALUE self, VALUE rstring) {
|
667
633
|
FrtMultiMapper *mulmap = DATA_PTR(self);
|
668
634
|
char *string = rs2s(rb_obj_as_string(rstring));
|
669
635
|
char *mapped_string = frt_mulmap_dynamic_map(mulmap, string);
|
@@ -712,13 +678,10 @@ frb_mulmap_map(VALUE self, VALUE rstring)
|
|
712
678
|
* mapper = MultiMapper.new(mapping)
|
713
679
|
* mapped_string = mapper.map(string)
|
714
680
|
*/
|
715
|
-
static void
|
716
|
-
Init_MultiMapper(void)
|
717
|
-
{
|
681
|
+
static void Init_MultiMapper(void) {
|
718
682
|
/* MultiMapper */
|
719
683
|
cMultiMapper = rb_define_class_under(mUtils, "MultiMapper", rb_cObject);
|
720
684
|
rb_define_alloc_func(cMultiMapper, frb_mulmap_alloc);
|
721
|
-
|
722
685
|
rb_define_method(cMultiMapper, "initialize", frb_mulmap_init, 1);
|
723
686
|
rb_define_method(cMultiMapper, "map", frb_mulmap_map, 1);
|
724
687
|
}
|
@@ -726,8 +689,7 @@ Init_MultiMapper(void)
|
|
726
689
|
/*********************
|
727
690
|
*** PriorityQueue ***
|
728
691
|
*********************/
|
729
|
-
typedef struct PriQ
|
730
|
-
{
|
692
|
+
typedef struct PriQ {
|
731
693
|
int size;
|
732
694
|
int capa;
|
733
695
|
int mem_capa;
|
@@ -737,18 +699,15 @@ typedef struct PriQ
|
|
737
699
|
|
738
700
|
#define PQ_START_CAPA 32
|
739
701
|
|
740
|
-
static bool frb_pq_lt(VALUE proc, VALUE v1, VALUE v2)
|
741
|
-
{
|
702
|
+
static bool frb_pq_lt(VALUE proc, VALUE v1, VALUE v2) {
|
742
703
|
if (proc == Qnil) {
|
743
704
|
return RTEST(rb_funcall(v1, id_lt, 1, v2));
|
744
|
-
}
|
745
|
-
else {
|
705
|
+
} else {
|
746
706
|
return RTEST(rb_funcall(proc, id_call, 2, v1, v2));
|
747
707
|
}
|
748
708
|
}
|
749
709
|
|
750
|
-
static void frb_pq_up(PriQ *pq)
|
751
|
-
{
|
710
|
+
static void frb_pq_up(PriQ *pq) {
|
752
711
|
VALUE *heap = pq->heap;
|
753
712
|
VALUE node;
|
754
713
|
int i = pq->size;
|
@@ -764,8 +723,7 @@ static void frb_pq_up(PriQ *pq)
|
|
764
723
|
heap[i] = node;
|
765
724
|
}
|
766
725
|
|
767
|
-
static void frb_pq_down(PriQ *pq)
|
768
|
-
{
|
726
|
+
static void frb_pq_down(PriQ *pq) {
|
769
727
|
register int i = 1;
|
770
728
|
register int j = 2; /* i << 1; */
|
771
729
|
register int k = 3; /* j + 1; */
|
@@ -789,8 +747,7 @@ static void frb_pq_down(PriQ *pq)
|
|
789
747
|
heap[i] = node;
|
790
748
|
}
|
791
749
|
|
792
|
-
static void frb_pq_push(PriQ *pq, VALUE elem)
|
793
|
-
{
|
750
|
+
static void frb_pq_push(PriQ *pq, VALUE elem) {
|
794
751
|
pq->size++;
|
795
752
|
if (pq->size >= pq->mem_capa) {
|
796
753
|
pq->mem_capa <<= 1;
|
@@ -802,34 +759,50 @@ static void frb_pq_push(PriQ *pq, VALUE elem)
|
|
802
759
|
|
803
760
|
static VALUE cPriorityQueue;
|
804
761
|
|
805
|
-
static void
|
806
|
-
frb_pq_mark(void *p)
|
807
|
-
{
|
762
|
+
static void frb_pq_mark(void *p) {
|
808
763
|
PriQ *pq = (PriQ *)p;
|
809
764
|
int i;
|
810
765
|
for (i = pq->size; i > 0; i--) {
|
811
|
-
|
766
|
+
if (pq->heap[i])
|
767
|
+
rb_gc_mark_maybe(pq->heap[i]);
|
812
768
|
}
|
813
769
|
}
|
814
770
|
|
815
|
-
static void frb_pq_free(
|
816
|
-
|
771
|
+
static void frb_pq_free(void *p) {
|
772
|
+
PriQ *pq = (PriQ *)p;
|
817
773
|
free(pq->heap);
|
818
774
|
free(pq);
|
819
775
|
}
|
820
776
|
|
821
|
-
static
|
822
|
-
|
823
|
-
|
777
|
+
static size_t frb_pq_t_size(const void *p) {
|
778
|
+
return sizeof(PriQ);
|
779
|
+
(void)p;
|
780
|
+
}
|
781
|
+
|
782
|
+
const rb_data_type_t frb_pq_t = {
|
783
|
+
.wrap_struct_name = "FrbPriorityQueue",
|
784
|
+
.function = {
|
785
|
+
.dmark = frb_pq_mark,
|
786
|
+
.dfree = frb_pq_free,
|
787
|
+
.dsize = frb_pq_t_size,
|
788
|
+
.dcompact = NULL,
|
789
|
+
.reserved = {0},
|
790
|
+
},
|
791
|
+
.parent = NULL,
|
792
|
+
.data = NULL,
|
793
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
794
|
+
};
|
795
|
+
|
796
|
+
static VALUE frb_pq_alloc(VALUE klass) {
|
824
797
|
PriQ *pq = FRT_ALLOC_AND_ZERO(PriQ);
|
825
798
|
pq->capa = PQ_START_CAPA;
|
826
799
|
pq->mem_capa = PQ_START_CAPA;
|
827
800
|
pq->heap = FRT_ALLOC_N(VALUE, PQ_START_CAPA);
|
828
801
|
pq->proc = Qnil;
|
829
|
-
return
|
802
|
+
return TypedData_Wrap_Struct(klass, &frb_pq_t, pq);
|
830
803
|
}
|
831
804
|
|
832
|
-
#define GET_PQ(pq, self)
|
805
|
+
#define GET_PQ(pq, self) TypedData_Get_Struct(self, PriQ, &frb_pq_t, pq)
|
833
806
|
/*
|
834
807
|
* call-seq:
|
835
808
|
* PriorityQueue.new(capacity = 32) -> new_pq
|
@@ -842,9 +815,7 @@ frb_pq_alloc(VALUE klass)
|
|
842
815
|
* automatically popped off the top of the queue as more elements are
|
843
816
|
* inserted into the queue.
|
844
817
|
*/
|
845
|
-
static VALUE
|
846
|
-
frb_pq_init(int argc, VALUE *argv, VALUE self)
|
847
|
-
{
|
818
|
+
static VALUE frb_pq_init(int argc, VALUE *argv, VALUE self) {
|
848
819
|
if (argc >= 1) {
|
849
820
|
PriQ *pq;
|
850
821
|
VALUE options = argv[0];
|
@@ -897,16 +868,14 @@ frb_pq_init(int argc, VALUE *argv, VALUE self)
|
|
897
868
|
* Returns a shallow clone of the priority queue. That is only the priority
|
898
869
|
* queue is cloned, its contents are not cloned.
|
899
870
|
*/
|
900
|
-
static VALUE
|
901
|
-
frb_pq_clone(VALUE self)
|
902
|
-
{
|
871
|
+
static VALUE frb_pq_clone(VALUE self) {
|
903
872
|
PriQ *pq, *new_pq = ALLOC(PriQ);
|
904
873
|
GET_PQ(pq, self);
|
905
874
|
memcpy(new_pq, pq, sizeof(PriQ));
|
906
875
|
new_pq->heap = FRT_ALLOC_N(VALUE, new_pq->mem_capa);
|
907
876
|
memcpy(new_pq->heap, pq->heap, sizeof(VALUE) * (new_pq->size + 1));
|
908
877
|
|
909
|
-
return
|
878
|
+
return TypedData_Wrap_Struct(cPriorityQueue, &frb_pq_t, new_pq);
|
910
879
|
}
|
911
880
|
|
912
881
|
/*
|
@@ -915,9 +884,7 @@ frb_pq_clone(VALUE self)
|
|
915
884
|
*
|
916
885
|
* Clears all elements from the priority queue. The size will be reset to 0.
|
917
886
|
*/
|
918
|
-
static VALUE
|
919
|
-
frb_pq_clear(VALUE self)
|
920
|
-
{
|
887
|
+
static VALUE frb_pq_clear(VALUE self) {
|
921
888
|
PriQ *pq;
|
922
889
|
GET_PQ(pq, self);
|
923
890
|
pq->size = 0;
|
@@ -932,9 +899,7 @@ frb_pq_clear(VALUE self)
|
|
932
899
|
* Insert an element into a queue. It will be inserted into the correct
|
933
900
|
* position in the queue according to its priority.
|
934
901
|
*/
|
935
|
-
static VALUE
|
936
|
-
frb_pq_insert(VALUE self, VALUE elem)
|
937
|
-
{
|
902
|
+
static VALUE frb_pq_insert(VALUE self, VALUE elem) {
|
938
903
|
PriQ *pq;
|
939
904
|
GET_PQ(pq, self);
|
940
905
|
if (pq->size < pq->capa) {
|
@@ -956,9 +921,7 @@ frb_pq_insert(VALUE self, VALUE elem)
|
|
956
921
|
* priority changes. When you do this you need to reorder the queue and you
|
957
922
|
* do this by calling the adjust method.
|
958
923
|
*/
|
959
|
-
static VALUE
|
960
|
-
frb_pq_adjust(VALUE self)
|
961
|
-
{
|
924
|
+
static VALUE frb_pq_adjust(VALUE self) {
|
962
925
|
PriQ *pq;
|
963
926
|
GET_PQ(pq, self);
|
964
927
|
frb_pq_down(pq);
|
@@ -972,9 +935,7 @@ frb_pq_adjust(VALUE self)
|
|
972
935
|
* Returns the top element in the queue but does not remove it from the
|
973
936
|
* queue.
|
974
937
|
*/
|
975
|
-
static VALUE
|
976
|
-
frb_pq_top(VALUE self)
|
977
|
-
{
|
938
|
+
static VALUE frb_pq_top(VALUE self) {
|
978
939
|
PriQ *pq;
|
979
940
|
GET_PQ(pq, self);
|
980
941
|
return (pq->size > 0) ? pq->heap[1] : Qnil;
|
@@ -986,9 +947,7 @@ frb_pq_top(VALUE self)
|
|
986
947
|
*
|
987
948
|
* Returns the top element in the queue removing it from the queue.
|
988
949
|
*/
|
989
|
-
static VALUE
|
990
|
-
frb_pq_pop(VALUE self)
|
991
|
-
{
|
950
|
+
static VALUE frb_pq_pop(VALUE self) {
|
992
951
|
PriQ *pq;
|
993
952
|
GET_PQ(pq, self);
|
994
953
|
if (pq->size > 0) {
|
@@ -1012,9 +971,7 @@ frb_pq_pop(VALUE self)
|
|
1012
971
|
* in the queue. The _size_ of a PriorityQueue can never be greater than
|
1013
972
|
* its _capacity_
|
1014
973
|
*/
|
1015
|
-
static VALUE
|
1016
|
-
frb_pq_size(VALUE self)
|
1017
|
-
{
|
974
|
+
static VALUE frb_pq_size(VALUE self) {
|
1018
975
|
PriQ *pq;
|
1019
976
|
GET_PQ(pq, self);
|
1020
977
|
return INT2FIX(pq->size);
|
@@ -1029,9 +986,7 @@ frb_pq_size(VALUE self)
|
|
1029
986
|
* _size_ of a PriorityQueue can never be greater than its
|
1030
987
|
* _capacity_
|
1031
988
|
*/
|
1032
|
-
static VALUE
|
1033
|
-
frb_pq_capa(VALUE self)
|
1034
|
-
{
|
989
|
+
static VALUE frb_pq_capa(VALUE self) {
|
1035
990
|
PriQ *pq;
|
1036
991
|
GET_PQ(pq, self);
|
1037
992
|
return INT2FIX(pq->capa);
|
@@ -1079,9 +1034,7 @@ frb_pq_capa(VALUE self)
|
|
1079
1034
|
* word = q.pop #=> "xxxyyyy"
|
1080
1035
|
* word = q.pop #=> nil
|
1081
1036
|
*/
|
1082
|
-
static void
|
1083
|
-
Init_PriorityQueue(void)
|
1084
|
-
{
|
1037
|
+
static void Init_PriorityQueue(void) {
|
1085
1038
|
/* PriorityQueue */
|
1086
1039
|
cPriorityQueue = rb_define_class_under(mUtils, "PriorityQueue", rb_cObject);
|
1087
1040
|
rb_define_alloc_func(cPriorityQueue, frb_pq_alloc);
|
@@ -1116,9 +1069,7 @@ extern VALUE mFerret = rb_define_module("Ferret");
|
|
1116
1069
|
* These helper classes could also be quite useful outside of Ferret and may
|
1117
1070
|
* one day find themselves in their own separate library.
|
1118
1071
|
*/
|
1119
|
-
void
|
1120
|
-
Init_Utils(void)
|
1121
|
-
{
|
1072
|
+
void Init_Utils(void) {
|
1122
1073
|
mUtils = rb_define_module_under(mFerret, "Utils");
|
1123
1074
|
|
1124
1075
|
Init_BitVector();
|