ferret 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/Makefile +2 -2
- data/ext/ferret.c +27 -2
- data/ext/ferret.h +59 -16
- data/ext/ferret_ext.so +0 -0
- data/ext/index_io.c +72 -77
- data/ext/priority_queue.c +150 -145
- data/ext/ram_directory.c +47 -42
- data/ext/segment_merge_queue.c +4 -8
- data/ext/segment_term_enum.c +324 -0
- data/ext/similarity.c +59 -0
- data/ext/string_helper.c +2 -2
- data/ext/tags +150 -46
- data/ext/term.c +107 -152
- data/ext/term_buffer.c +105 -174
- data/ext/term_infos_reader.c +54 -0
- data/ext/terminfo.c +160 -0
- data/ext/token.c +93 -0
- data/lib/ferret.rb +1 -1
- data/lib/ferret/analysis/analyzers.rb +18 -0
- data/lib/ferret/analysis/standard_tokenizer.rb +19 -14
- data/lib/ferret/analysis/token.rb +8 -1
- data/lib/ferret/analysis/tokenizers.rb +10 -5
- data/lib/ferret/document/field.rb +33 -11
- data/lib/ferret/index/document_writer.rb +3 -2
- data/lib/ferret/index/field_infos.rb +38 -12
- data/lib/ferret/index/fields_io.rb +10 -4
- data/lib/ferret/index/index.rb +20 -4
- data/lib/ferret/index/index_reader.rb +19 -4
- data/lib/ferret/index/index_writer.rb +1 -1
- data/lib/ferret/index/multi_reader.rb +21 -7
- data/lib/ferret/index/segment_merge_info.rb +24 -22
- data/lib/ferret/index/segment_merge_queue.rb +2 -2
- data/lib/ferret/index/segment_merger.rb +28 -11
- data/lib/ferret/index/segment_reader.rb +19 -4
- data/lib/ferret/index/segment_term_enum.rb +3 -11
- data/lib/ferret/index/term_buffer.rb +13 -16
- data/lib/ferret/index/term_doc_enum.rb +8 -5
- data/lib/ferret/index/term_enum.rb +2 -2
- data/lib/ferret/index/term_info.rb +1 -5
- data/lib/ferret/index/term_infos_io.rb +2 -0
- data/lib/ferret/query_parser/query_parser.tab.rb +7 -7
- data/lib/ferret/search/phrase_scorer.rb +0 -1
- data/lib/ferret/search/similarity.rb +2 -2
- data/lib/ferret/search/term_scorer.rb +2 -2
- data/lib/ferret/store/directory.rb +2 -0
- data/lib/ferret/store/fs_store.rb +16 -3
- data/lib/ferret/store/ram_store.rb +2 -2
- data/test/unit/document/tc_field.rb +9 -0
- data/test/unit/index/tc_field_infos.rb +29 -21
- data/test/unit/index/tc_index.rb +44 -7
- data/test/unit/index/tc_term_buffer.rb +3 -3
- data/test/unit/index/tc_term_info.rb +1 -1
- data/test/unit/query_parser/tc_query_parser.rb +1 -1
- data/test/unit/search/tc_index_searcher.rb +3 -0
- data/test/unit/store/tc_fs_store.rb +47 -16
- data/test/unit/store/tc_ram_store.rb +1 -1
- metadata +8 -3
data/ext/Makefile
CHANGED
@@ -71,8 +71,8 @@ extout_prefix =
|
|
71
71
|
target_prefix =
|
72
72
|
LOCAL_LIBS =
|
73
73
|
LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lcrypt -lm -lc
|
74
|
-
SRCS = index_io.c term_buffer.c ram_directory.c priority_queue.c string_helper.c segment_merge_queue.c ferret.c term.c util.c
|
75
|
-
OBJS = index_io.o term_buffer.o ram_directory.o priority_queue.o string_helper.o segment_merge_queue.o ferret.o term.o util.o
|
74
|
+
SRCS = index_io.c term_buffer.c ram_directory.c priority_queue.c string_helper.c segment_merge_queue.c ferret.c term.c util.c token.c segment_term_enum.c terminfo.c term_infos_reader.c similarity.c
|
75
|
+
OBJS = index_io.o term_buffer.o ram_directory.o priority_queue.o string_helper.o segment_merge_queue.o ferret.o term.o util.o token.o segment_term_enum.o terminfo.o term_infos_reader.o similarity.o
|
76
76
|
TARGET = ferret_ext
|
77
77
|
DLLIB = $(TARGET).so
|
78
78
|
STATIC_LIB =
|
data/ext/ferret.c
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
#include "ferret.h"
|
2
2
|
|
3
3
|
/* IDs */
|
4
|
-
ID
|
4
|
+
ID id_new;
|
5
|
+
ID id_close;
|
6
|
+
ID id_size;
|
7
|
+
ID id_iv_size;
|
5
8
|
|
6
9
|
/* Modules */
|
7
10
|
VALUE mFerret;
|
8
11
|
VALUE mStore;
|
9
12
|
VALUE mIndex;
|
10
13
|
VALUE mUtils;
|
14
|
+
VALUE mAnalysis;
|
15
|
+
VALUE mSearch;
|
11
16
|
VALUE mStringHelper;
|
12
17
|
|
13
18
|
/* Classes */
|
@@ -22,27 +27,47 @@ VALUE cRAMIndexOut;
|
|
22
27
|
VALUE cRAMIndexIn;
|
23
28
|
VALUE cTerm;
|
24
29
|
VALUE cTermBuffer;
|
30
|
+
VALUE cTermInfo;
|
31
|
+
VALUE cToken;
|
25
32
|
VALUE cPriorityQueue;
|
26
33
|
VALUE cSegmentMergeQueue;
|
34
|
+
VALUE cSegmentTermEnum;
|
35
|
+
VALUE cTermEnum;
|
36
|
+
VALUE cTermInfosReader;
|
37
|
+
VALUE cSimilarity;
|
38
|
+
VALUE cDefaultSimilarity;
|
27
39
|
|
28
40
|
void
|
29
41
|
Init_ferret_ext(void)
|
30
42
|
{
|
31
43
|
/* IDs */
|
32
|
-
|
44
|
+
id_new = rb_intern("new");
|
45
|
+
id_close = rb_intern("close");
|
46
|
+
id_size = rb_intern("size");
|
47
|
+
id_iv_size = rb_intern("@size");
|
33
48
|
|
34
49
|
/* Modules */
|
35
50
|
mFerret = rb_define_module("Ferret");
|
36
51
|
mStore = rb_define_module_under(mFerret, "Store");
|
37
52
|
mIndex = rb_define_module_under(mFerret, "Index");
|
38
53
|
mUtils = rb_define_module_under(mFerret, "Utils");
|
54
|
+
mAnalysis = rb_define_module_under(mFerret, "Analysis");
|
55
|
+
mSearch = rb_define_module_under(mFerret, "Search");
|
56
|
+
|
57
|
+
/* Classes */
|
58
|
+
cTermEnum = rb_define_class_under(mIndex, "TermEnum", rb_cObject);
|
39
59
|
|
40
60
|
/* Inits */
|
41
61
|
Init_indexio();
|
42
62
|
Init_term();
|
43
63
|
Init_term_buffer();
|
64
|
+
Init_term_info();
|
65
|
+
Init_term_infos_reader();
|
66
|
+
Init_token();
|
44
67
|
Init_priority_queue();
|
45
68
|
Init_segment_merge_queue();
|
69
|
+
Init_segment_term_enum();
|
46
70
|
Init_ram_directory();
|
47
71
|
Init_string_helper();
|
72
|
+
Init_similarity();
|
48
73
|
}
|
data/ext/ferret.h
CHANGED
@@ -15,24 +15,23 @@ typedef struct IndexBuffer {
|
|
15
15
|
} IndexBuffer;
|
16
16
|
|
17
17
|
typedef struct Term {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
int tlen;
|
18
|
+
VALUE field;
|
19
|
+
char *text;
|
20
|
+
int tlen;
|
22
21
|
} Term;
|
23
22
|
|
24
23
|
typedef struct PriorityQueue {
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
VALUE *heap;
|
25
|
+
int len;
|
26
|
+
int size;
|
28
27
|
} PriorityQueue;
|
29
28
|
|
30
|
-
typedef struct
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
29
|
+
typedef struct TermInfo {
|
30
|
+
int doc_freq;
|
31
|
+
long freq_pointer;
|
32
|
+
long prox_pointer;
|
33
|
+
int skip_offset;
|
34
|
+
} TermInfo;
|
36
35
|
|
37
36
|
typedef struct RAMFile {
|
38
37
|
void **buffers;
|
@@ -42,14 +41,38 @@ typedef struct RAMFile {
|
|
42
41
|
int length;
|
43
42
|
} RAMFile;
|
44
43
|
|
44
|
+
typedef struct SegmentTermEnum {
|
45
|
+
VALUE input;
|
46
|
+
IndexBuffer *buf;
|
47
|
+
VALUE field_infos;
|
48
|
+
VALUE rtb_curr;
|
49
|
+
Term *tb_curr;
|
50
|
+
VALUE rtb_prev;
|
51
|
+
Term *tb_prev;
|
52
|
+
TermInfo *ti;
|
53
|
+
int is_index;
|
54
|
+
int size;
|
55
|
+
int position;
|
56
|
+
int index_pointer;
|
57
|
+
int index_interval;
|
58
|
+
int skip_interval;
|
59
|
+
int format;
|
60
|
+
int format_m1skip_interval;
|
61
|
+
} SegmentTermEnum;
|
62
|
+
|
45
63
|
/* IDs */
|
46
|
-
extern ID
|
64
|
+
extern ID id_new;
|
65
|
+
extern ID id_close;
|
66
|
+
extern ID id_size;
|
67
|
+
extern ID id_iv_size;
|
47
68
|
|
48
69
|
/* Modules */
|
49
70
|
extern VALUE mFerret;
|
50
71
|
extern VALUE mStore;
|
51
72
|
extern VALUE mIndex;
|
52
73
|
extern VALUE mUtils;
|
74
|
+
extern VALUE mAnalysis;
|
75
|
+
extern VALUE mSearch;
|
53
76
|
extern VALUE mStringHelper;
|
54
77
|
|
55
78
|
/* Classes */
|
@@ -64,22 +87,42 @@ extern VALUE cRAMIndexOut;
|
|
64
87
|
extern VALUE cRAMIndexIn;
|
65
88
|
extern VALUE cTerm;
|
66
89
|
extern VALUE cTermBuffer;
|
90
|
+
extern VALUE cTermInfo;
|
91
|
+
extern VALUE cToken;
|
67
92
|
extern VALUE cPriorityQueue;
|
68
93
|
extern VALUE cSegmentMergeQueue;
|
94
|
+
extern VALUE cTermEnum;
|
95
|
+
extern VALUE cTermInfosReader;
|
96
|
+
extern VALUE cSegmentTermEnum;
|
97
|
+
extern VALUE cSimilarity;
|
98
|
+
extern VALUE cDefaultSimilarity;
|
69
99
|
|
70
100
|
/* Ferret Inits */
|
71
101
|
extern void Init_indexio();
|
72
102
|
extern void Init_term();
|
73
|
-
extern void
|
103
|
+
extern void Init_term_info();
|
104
|
+
extern void Init_term_infos_reader();
|
74
105
|
extern void Init_term_buffer();
|
106
|
+
extern void Init_priority_queue();
|
107
|
+
extern void Init_token();
|
75
108
|
extern void Init_segment_merge_queue();
|
109
|
+
extern void Init_segment_term_enum();
|
76
110
|
extern void Init_ram_directory();
|
77
111
|
extern void Init_string_helper();
|
112
|
+
extern void Init_similarity();
|
78
113
|
|
79
114
|
/* External functions */
|
80
115
|
extern int frt_hash(register char *p, register int len);
|
81
|
-
extern unsigned long long frt_read_vint(VALUE self);
|
116
|
+
extern unsigned long long frt_read_vint(VALUE self, IndexBuffer *my_buf);
|
117
|
+
extern VALUE frt_indexin_read_long(VALUE self);
|
118
|
+
extern VALUE frt_indexin_read_int(VALUE self);
|
119
|
+
extern VALUE frt_indexin_seek(VALUE self, VALUE pos);
|
120
|
+
extern VALUE frt_termbuffer_to_term(VALUE self);
|
82
121
|
extern void frt_read_chars(VALUE self, char *buf, int offset, int len);
|
83
122
|
extern void frt_write_bytes(VALUE self, byte_t *buf, int len);
|
84
123
|
extern int frt_term_compare_to_int(VALUE self, VALUE rother);
|
124
|
+
extern VALUE frt_termbuffer_init_copy(VALUE self, VALUE rother);
|
125
|
+
extern VALUE frt_termbuffer_read(VALUE self, VALUE input, VALUE info);
|
126
|
+
extern inline int frt_term_cmp(Term *t1, Term *t2);
|
127
|
+
|
85
128
|
#endif
|
data/ext/ferret_ext.so
CHANGED
Binary file
|
data/ext/index_io.c
CHANGED
@@ -12,43 +12,37 @@ void
|
|
12
12
|
frt_indexbuffer_free(void *p)
|
13
13
|
{
|
14
14
|
IndexBuffer *my_buf = (IndexBuffer *)p;
|
15
|
-
free(
|
15
|
+
free(my_buf->buffer);
|
16
16
|
free(p);
|
17
17
|
}
|
18
18
|
|
19
19
|
static VALUE
|
20
20
|
frt_indexbuffer_alloc(VALUE klass)
|
21
21
|
{
|
22
|
-
byte_t *buffer;
|
23
22
|
IndexBuffer *my_buf;
|
24
23
|
|
25
|
-
my_buf =
|
26
|
-
|
27
|
-
|
28
|
-
my_buf->start = 0;
|
29
|
-
my_buf->pos = 0;
|
30
|
-
my_buf->len = 0;
|
31
|
-
my_buf->buffer = buffer;
|
24
|
+
my_buf = ALLOC(IndexBuffer);
|
25
|
+
MEMZERO(my_buf, IndexBuffer, 1);
|
26
|
+
my_buf->buffer = ALLOC_N(byte_t, BUFFER_SIZE);
|
32
27
|
|
33
28
|
return Data_Wrap_Struct(klass, NULL, frt_indexbuffer_free, my_buf);
|
34
29
|
}
|
35
30
|
|
31
|
+
#define GET_MY_BUF IndexBuffer *my_buf; Data_Get_Struct(self, IndexBuffer, my_buf)
|
36
32
|
static VALUE
|
37
33
|
frt_indexin_init_copy(VALUE self, VALUE orig)
|
38
34
|
{
|
39
35
|
IndexBuffer *orig_buf;
|
40
|
-
IndexBuffer *my_buf;
|
41
36
|
int len;
|
37
|
+
GET_MY_BUF;
|
42
38
|
if (self == orig)
|
43
39
|
return self;
|
44
40
|
|
45
|
-
Data_Get_Struct(self, IndexBuffer, my_buf);
|
46
41
|
Data_Get_Struct(orig, IndexBuffer, orig_buf);
|
47
42
|
|
48
43
|
len = orig_buf->len;
|
49
44
|
my_buf->len = len;
|
50
45
|
my_buf->pos = orig_buf->pos;
|
51
|
-
my_buf->len = orig_buf->len;
|
52
46
|
my_buf->start = orig_buf->start;
|
53
47
|
|
54
48
|
MEMCPY(my_buf->buffer, orig_buf->buffer, byte_t, len);
|
@@ -59,12 +53,11 @@ frt_indexin_init_copy(VALUE self, VALUE orig)
|
|
59
53
|
static VALUE
|
60
54
|
frt_indexin_refill(VALUE self)
|
61
55
|
{
|
62
|
-
IndexBuffer *my_buf;
|
63
56
|
long start;
|
57
|
+
VALUE rStr;
|
64
58
|
int stop, len_to_read;
|
65
59
|
int input_len = FIX2INT(rb_funcall(self, frt_length, 0, NULL));
|
66
|
-
|
67
|
-
Data_Get_Struct(self, IndexBuffer, my_buf);
|
60
|
+
GET_MY_BUF;
|
68
61
|
|
69
62
|
start = my_buf->start + my_buf->pos;
|
70
63
|
stop = start + BUFFER_SIZE;
|
@@ -77,7 +70,7 @@ frt_indexin_refill(VALUE self)
|
|
77
70
|
rb_raise(rb_eEOFError, "IndexInput: Read past End of File");
|
78
71
|
}
|
79
72
|
|
80
|
-
|
73
|
+
rStr = rb_str_new((char *)my_buf->buffer, BUFFER_SIZE);
|
81
74
|
rb_funcall(self, frt_read_internal, 3,
|
82
75
|
rStr, INT2FIX(0), INT2FIX(len_to_read));
|
83
76
|
|
@@ -91,23 +84,19 @@ frt_indexin_refill(VALUE self)
|
|
91
84
|
return Qnil;
|
92
85
|
}
|
93
86
|
|
94
|
-
byte_t
|
95
|
-
frt_read_byte(VALUE self)
|
87
|
+
static inline byte_t
|
88
|
+
frt_read_byte(VALUE self, IndexBuffer *my_buf)
|
96
89
|
{
|
97
|
-
IndexBuffer *my_buf;
|
98
|
-
Data_Get_Struct(self, IndexBuffer, my_buf);
|
99
|
-
|
100
90
|
if (my_buf->pos >= my_buf->len)
|
101
91
|
frt_indexin_refill(self);
|
102
|
-
|
103
|
-
byte_t res = my_buf->buffer[my_buf->pos++];
|
104
|
-
return res;
|
92
|
+
return my_buf->buffer[my_buf->pos++];
|
105
93
|
}
|
106
94
|
|
107
95
|
static VALUE
|
108
96
|
frt_indexin_read_byte(VALUE self)
|
109
97
|
{
|
110
|
-
|
98
|
+
GET_MY_BUF;
|
99
|
+
return INT2FIX(frt_read_byte(self, my_buf));
|
111
100
|
}
|
112
101
|
|
113
102
|
static VALUE
|
@@ -122,16 +111,17 @@ static VALUE
|
|
122
111
|
frt_read_bytes(VALUE self, VALUE rbuffer, int offset, int len)
|
123
112
|
{
|
124
113
|
int i;
|
125
|
-
IndexBuffer *my_buf;
|
126
114
|
VALUE rbuf = StringValue(rbuffer);
|
127
115
|
|
116
|
+
GET_MY_BUF;
|
117
|
+
|
128
118
|
if (RSTRING(rbuf)->len < (offset + len)) {
|
129
119
|
rb_str_resize(rbuf, offset + len);
|
130
120
|
}
|
131
121
|
if ((len + offset) < BUFFER_SIZE) {
|
132
122
|
rb_str_modify(rbuf);
|
133
123
|
for (i = offset; i < offset + len; i++) {
|
134
|
-
RSTRING(rbuf)->ptr[i] = frt_read_byte(self);
|
124
|
+
RSTRING(rbuf)->ptr[i] = frt_read_byte(self, my_buf);
|
135
125
|
}
|
136
126
|
} else {
|
137
127
|
VALUE start = frt_indexin_pos(self);
|
@@ -139,8 +129,6 @@ frt_read_bytes(VALUE self, VALUE rbuffer, int offset, int len)
|
|
139
129
|
rb_funcall(self, frt_read_internal, 3,
|
140
130
|
rbuf, INT2FIX(offset), INT2FIX(len));
|
141
131
|
|
142
|
-
Data_Get_Struct(self, IndexBuffer, my_buf);
|
143
|
-
|
144
132
|
my_buf->start = my_buf->start + len;
|
145
133
|
my_buf->pos = 0;
|
146
134
|
my_buf->len = 0; /* trigger refill() on read() */
|
@@ -160,12 +148,12 @@ frt_indexin_read_bytes(VALUE self, VALUE rbuf, VALUE roffset, VALUE rlen)
|
|
160
148
|
return frt_read_bytes(self, rbuf, offset, len);
|
161
149
|
}
|
162
150
|
|
163
|
-
|
151
|
+
VALUE
|
164
152
|
frt_indexin_seek(VALUE self, VALUE rpos)
|
165
153
|
{
|
166
154
|
int pos = FIX2INT(rpos);
|
167
|
-
|
168
|
-
|
155
|
+
|
156
|
+
GET_MY_BUF;
|
169
157
|
|
170
158
|
if ((pos >= my_buf->start) && (pos < (my_buf->start + my_buf->len))) {
|
171
159
|
my_buf->pos = pos - my_buf->start; /* seek within buffer */
|
@@ -178,61 +166,65 @@ frt_indexin_seek(VALUE self, VALUE rpos)
|
|
178
166
|
return Qnil;
|
179
167
|
}
|
180
168
|
|
181
|
-
|
169
|
+
VALUE
|
182
170
|
frt_indexin_read_int(VALUE self)
|
183
171
|
{
|
184
|
-
|
185
|
-
|
186
|
-
((long)frt_read_byte(self) <<
|
187
|
-
|
172
|
+
GET_MY_BUF;
|
173
|
+
return LONG2NUM(((long)frt_read_byte(self, my_buf) << 24) |
|
174
|
+
((long)frt_read_byte(self, my_buf) << 16) |
|
175
|
+
((long)frt_read_byte(self, my_buf) << 8) |
|
176
|
+
(long)frt_read_byte(self, my_buf));
|
188
177
|
}
|
189
178
|
|
190
|
-
|
179
|
+
VALUE
|
191
180
|
frt_indexin_read_long(VALUE self)
|
192
181
|
{
|
193
|
-
|
194
|
-
|
195
|
-
((long long)frt_read_byte(self) <<
|
196
|
-
((long long)frt_read_byte(self) <<
|
197
|
-
((long long)frt_read_byte(self) <<
|
198
|
-
((long long)frt_read_byte(self) <<
|
199
|
-
((long long)frt_read_byte(self) <<
|
200
|
-
|
182
|
+
GET_MY_BUF;
|
183
|
+
return LL2NUM(((long long)frt_read_byte(self, my_buf) << 56) |
|
184
|
+
((long long)frt_read_byte(self, my_buf) << 48) |
|
185
|
+
((long long)frt_read_byte(self, my_buf) << 40) |
|
186
|
+
((long long)frt_read_byte(self, my_buf) << 32) |
|
187
|
+
((long long)frt_read_byte(self, my_buf) << 24) |
|
188
|
+
((long long)frt_read_byte(self, my_buf) << 16) |
|
189
|
+
((long long)frt_read_byte(self, my_buf) << 8) |
|
190
|
+
(long long)frt_read_byte(self, my_buf));
|
201
191
|
}
|
202
192
|
|
203
193
|
static VALUE
|
204
194
|
frt_indexin_read_uint(VALUE self)
|
205
195
|
{
|
206
|
-
|
207
|
-
|
208
|
-
((unsigned long)frt_read_byte(self) <<
|
209
|
-
|
196
|
+
GET_MY_BUF;
|
197
|
+
return ULONG2NUM(((unsigned long)frt_read_byte(self, my_buf) << 24) |
|
198
|
+
((unsigned long)frt_read_byte(self, my_buf) << 16) |
|
199
|
+
((unsigned long)frt_read_byte(self, my_buf) << 8) |
|
200
|
+
(unsigned long)frt_read_byte(self, my_buf));
|
210
201
|
}
|
211
202
|
|
212
203
|
static VALUE
|
213
204
|
frt_indexin_read_ulong(VALUE self)
|
214
205
|
{
|
215
|
-
|
216
|
-
|
217
|
-
((unsigned long long)frt_read_byte(self) <<
|
218
|
-
((unsigned long long)frt_read_byte(self) <<
|
219
|
-
((unsigned long long)frt_read_byte(self) <<
|
220
|
-
((unsigned long long)frt_read_byte(self) <<
|
221
|
-
((unsigned long long)frt_read_byte(self) <<
|
222
|
-
|
206
|
+
GET_MY_BUF;
|
207
|
+
return ULL2NUM(((unsigned long long)frt_read_byte(self, my_buf) << 56) |
|
208
|
+
((unsigned long long)frt_read_byte(self, my_buf) << 48) |
|
209
|
+
((unsigned long long)frt_read_byte(self, my_buf) << 40) |
|
210
|
+
((unsigned long long)frt_read_byte(self, my_buf) << 32) |
|
211
|
+
((unsigned long long)frt_read_byte(self, my_buf) << 24) |
|
212
|
+
((unsigned long long)frt_read_byte(self, my_buf) << 16) |
|
213
|
+
((unsigned long long)frt_read_byte(self, my_buf) << 8) |
|
214
|
+
(unsigned long long)frt_read_byte(self, my_buf));
|
223
215
|
}
|
224
216
|
|
225
217
|
unsigned long long
|
226
|
-
frt_read_vint(VALUE self)
|
218
|
+
frt_read_vint(VALUE self, IndexBuffer *my_buf)
|
227
219
|
{
|
228
220
|
register unsigned long long i, b;
|
229
221
|
register int shift = 7;
|
230
222
|
|
231
|
-
b = frt_read_byte(self);
|
223
|
+
b = frt_read_byte(self, my_buf);
|
232
224
|
i = b & 0x7F; /* 0x7F = 0b01111111 */
|
233
225
|
|
234
226
|
while ((b & 0x80) != 0) {/* 0x80 = 0b10000000 */
|
235
|
-
b = frt_read_byte(self);
|
227
|
+
b = frt_read_byte(self, my_buf);
|
236
228
|
i |= (b & 0x7F) << shift;
|
237
229
|
shift += 7;
|
238
230
|
}
|
@@ -243,27 +235,34 @@ frt_read_vint(VALUE self)
|
|
243
235
|
static VALUE
|
244
236
|
frt_indexin_read_vint(VALUE self)
|
245
237
|
{
|
246
|
-
|
238
|
+
GET_MY_BUF;
|
239
|
+
return ULL2NUM(frt_read_vint(self, my_buf));
|
247
240
|
}
|
248
241
|
|
249
242
|
void
|
250
243
|
frt_read_chars(VALUE self, char* buffer, int off, int len)
|
251
244
|
{
|
252
|
-
|
253
|
-
|
245
|
+
/* byte_t b, b1, b2; */
|
246
|
+
int end, i;
|
247
|
+
|
248
|
+
GET_MY_BUF;
|
254
249
|
|
255
|
-
|
250
|
+
end = off + len;
|
256
251
|
|
257
|
-
|
258
|
-
|
252
|
+
|
253
|
+
for(i = off; i < end; i++) {
|
254
|
+
buffer[i] = frt_read_byte(self, my_buf);
|
259
255
|
}
|
260
256
|
}
|
261
257
|
|
262
258
|
static VALUE
|
263
259
|
frt_indexin_read_string(VALUE self)
|
264
260
|
{
|
265
|
-
int length
|
266
|
-
char *str
|
261
|
+
int length;
|
262
|
+
char *str;
|
263
|
+
GET_MY_BUF;
|
264
|
+
length = (int)frt_read_vint(self, my_buf);
|
265
|
+
str = ALLOC_N(char, length);
|
267
266
|
|
268
267
|
frt_read_chars(self, str, 0, length);
|
269
268
|
|
@@ -279,8 +278,7 @@ frt_indexin_read_string(VALUE self)
|
|
279
278
|
static VALUE
|
280
279
|
frt_indexout_flush(VALUE self)
|
281
280
|
{
|
282
|
-
|
283
|
-
Data_Get_Struct(self, IndexBuffer, my_buf);
|
281
|
+
GET_MY_BUF;
|
284
282
|
|
285
283
|
rb_funcall(self, frt_flush_buffer, 2,
|
286
284
|
rb_str_new((char *)my_buf->buffer, BUFFER_SIZE), INT2FIX(my_buf->pos));
|
@@ -294,8 +292,7 @@ frt_indexout_flush(VALUE self)
|
|
294
292
|
static VALUE
|
295
293
|
frt_write_byte(VALUE self, byte_t b)
|
296
294
|
{
|
297
|
-
|
298
|
-
Data_Get_Struct(self, IndexBuffer, my_buf);
|
295
|
+
GET_MY_BUF;
|
299
296
|
|
300
297
|
my_buf->buffer[my_buf->pos++] = b;
|
301
298
|
|
@@ -336,16 +333,14 @@ frt_indexout_write_bytes(VALUE self, VALUE rbuffer, VALUE rlen)
|
|
336
333
|
static VALUE
|
337
334
|
frt_indexout_pos(VALUE self)
|
338
335
|
{
|
339
|
-
|
340
|
-
Data_Get_Struct(self, IndexBuffer, my_buf);
|
336
|
+
GET_MY_BUF;
|
341
337
|
return INT2FIX(my_buf->start + my_buf->pos);
|
342
338
|
}
|
343
339
|
|
344
340
|
static VALUE
|
345
341
|
frt_indexout_seek(VALUE self, VALUE pos)
|
346
342
|
{
|
347
|
-
|
348
|
-
Data_Get_Struct(self, IndexBuffer, my_buf);
|
343
|
+
GET_MY_BUF;
|
349
344
|
|
350
345
|
frt_indexout_flush(self);
|
351
346
|
my_buf->start = FIX2INT(pos);
|