ferret 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/priority_queue.c
CHANGED
@@ -16,188 +16,193 @@ frt_priq_free(void *p)
|
|
16
16
|
static VALUE
|
17
17
|
frt_priq_alloc(VALUE klass)
|
18
18
|
{
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
PriorityQueue *priq;
|
20
|
+
VALUE rpriq;
|
21
|
+
priq = (PriorityQueue *)ALLOC(PriorityQueue);
|
22
|
+
priq->len = 0;
|
23
|
+
priq->size = 0;
|
24
|
+
rpriq = Data_Wrap_Struct(klass, NULL, frt_priq_free, priq);
|
25
|
+
return rpriq;
|
25
26
|
}
|
26
27
|
|
27
28
|
static VALUE
|
28
29
|
frt_priq_init(VALUE self, VALUE rsize)
|
29
30
|
{
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
VALUE heap;
|
32
|
+
PriorityQueue *priq;
|
33
|
+
|
34
|
+
int size = FIX2INT(rsize);
|
35
|
+
heap = rb_ary_new2(size+1);
|
36
|
+
Data_Get_Struct(self, PriorityQueue, priq);
|
37
|
+
|
38
|
+
priq->heap = RARRAY(heap)->ptr;
|
39
|
+
priq->size = size;
|
40
|
+
rb_iv_set(self, "@heap", heap);
|
41
|
+
return self;
|
41
42
|
}
|
42
43
|
|
43
44
|
void
|
44
45
|
priq_up(PriorityQueue *priq, VALUE self, VALUE rary)
|
45
46
|
{
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
47
|
+
int i,j;
|
48
|
+
VALUE *heap, node;
|
49
|
+
|
50
|
+
i = priq->len;
|
51
|
+
heap = priq->heap;
|
52
|
+
node = heap[i];
|
53
|
+
j = i >> 1;
|
54
|
+
while((j > 0) && rb_funcall(self, less_than, 2, node, heap[j])){
|
55
|
+
heap[i] = heap[j];
|
56
|
+
i = j;
|
57
|
+
j = j >> 1;
|
58
|
+
}
|
59
|
+
rb_ary_store(rary, i, node);
|
59
60
|
}
|
60
61
|
|
61
62
|
void
|
62
63
|
priq_down(PriorityQueue *priq, VALUE self, VALUE rary)
|
63
64
|
{
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
65
|
+
int i, j, k, len;
|
66
|
+
VALUE *heap, node;
|
67
|
+
|
68
|
+
i = 1;
|
69
|
+
heap = priq->heap;
|
70
|
+
len = priq->len;
|
71
|
+
node = heap[i];
|
72
|
+
j = i << 1;
|
73
|
+
k = j + 1;
|
74
|
+
|
75
|
+
if ((k <= len) && rb_funcall(self, less_than, 2, heap[k], heap[j]))
|
76
|
+
j = k;
|
77
|
+
|
78
|
+
while((j <= len) && rb_funcall(self, less_than, 2, heap[j], node)){
|
79
|
+
heap[i] = heap[j];
|
80
|
+
i = j;
|
81
|
+
j = i << 1;
|
82
|
+
k = j + 1;
|
83
|
+
if((k <= len) && rb_funcall(self, less_than, 2, heap[k], heap[j]))
|
84
|
+
j = k;
|
85
|
+
}
|
86
|
+
rb_ary_store(rary,i, node);
|
86
87
|
}
|
87
88
|
|
88
89
|
static VALUE
|
89
90
|
frt_priq_push(VALUE self, VALUE e)
|
90
91
|
{
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
92
|
+
PriorityQueue *priq;
|
93
|
+
int len;
|
94
|
+
VALUE rary;
|
95
|
+
Data_Get_Struct(self, PriorityQueue, priq);
|
96
|
+
len = priq->len;
|
97
|
+
rary = rb_iv_get(self, "@heap");
|
98
|
+
|
99
|
+
len++;
|
100
|
+
rb_ary_store(rary, len, e);
|
101
|
+
priq->len = len;
|
102
|
+
priq_up(priq, self, rary);
|
103
|
+
|
104
|
+
return Qnil;
|
102
105
|
}
|
103
106
|
|
104
107
|
static VALUE
|
105
108
|
frt_priq_insert(VALUE self, VALUE e)
|
106
109
|
{
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
110
|
+
PriorityQueue *priq;
|
111
|
+
VALUE *heap, rary;
|
112
|
+
int len, size;
|
113
|
+
rary = rb_iv_get(self, "@heap");
|
114
|
+
|
115
|
+
Data_Get_Struct(self, PriorityQueue, priq);
|
116
|
+
len = priq->len;
|
117
|
+
size = priq->size;
|
118
|
+
heap = priq->heap;
|
119
|
+
|
120
|
+
if(len < size){
|
121
|
+
frt_priq_push(self, e);
|
122
|
+
return 1;
|
123
|
+
} else if ((len > 0) && !rb_funcall(self, less_than, 2, e, heap[1])) {
|
124
|
+
heap[1] = e;
|
125
|
+
priq_down(priq, self, rary);
|
126
|
+
return 1;
|
127
|
+
} else {
|
128
|
+
return 0;
|
126
129
|
}
|
127
130
|
}
|
128
131
|
|
129
132
|
static VALUE
|
130
133
|
frt_priq_top(VALUE self)
|
131
134
|
{
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
135
|
+
PriorityQueue *priq;
|
136
|
+
VALUE *heap;
|
137
|
+
int len;
|
138
|
+
|
139
|
+
Data_Get_Struct(self, PriorityQueue, priq);
|
140
|
+
len = priq->len;
|
141
|
+
heap = priq->heap;
|
142
|
+
|
143
|
+
if(len > 0)
|
144
|
+
return heap[1];
|
145
|
+
else
|
146
|
+
return Qnil;
|
144
147
|
}
|
145
148
|
|
146
149
|
static VALUE
|
147
150
|
frt_priq_pop(VALUE self)
|
148
151
|
{
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
152
|
+
PriorityQueue *priq;
|
153
|
+
VALUE *heap, rary;
|
154
|
+
int len;
|
155
|
+
|
156
|
+
Data_Get_Struct(self, PriorityQueue, priq);
|
157
|
+
rary = rb_iv_get(self, "@heap");
|
158
|
+
len = priq->len;
|
159
|
+
heap = priq->heap;
|
160
|
+
|
161
|
+
if(len > 0){
|
162
|
+
VALUE res = heap[1];
|
163
|
+
heap[1] = heap[len];
|
164
|
+
heap[len] = Qnil;
|
165
|
+
len--;
|
166
|
+
priq->len = len;
|
167
|
+
priq_down(priq, self, rary);
|
168
|
+
return res;
|
169
|
+
} else
|
170
|
+
return Qnil;
|
168
171
|
}
|
169
172
|
|
170
173
|
static VALUE
|
171
174
|
frt_priq_clear(VALUE self)
|
172
175
|
{
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
176
|
+
PriorityQueue *priq;
|
177
|
+
VALUE heap;
|
178
|
+
Data_Get_Struct(self, PriorityQueue, priq);
|
179
|
+
heap = rb_ary_new2(priq->size+1);
|
180
|
+
rb_iv_set(self, "@heap", heap);
|
181
|
+
priq->heap = RARRAY(heap)->ptr;
|
182
|
+
priq->len = 0;
|
183
|
+
return Qnil;
|
184
|
+
|
181
185
|
}
|
182
186
|
|
183
187
|
static VALUE
|
184
188
|
frt_priq_size(VALUE self)
|
185
189
|
{
|
186
|
-
|
187
|
-
|
188
|
-
|
190
|
+
PriorityQueue *priq;
|
191
|
+
Data_Get_Struct(self, PriorityQueue, priq);
|
192
|
+
return INT2FIX(priq->len);
|
189
193
|
}
|
190
194
|
|
191
195
|
static VALUE
|
192
196
|
frt_priq_adjust_top(VALUE self)
|
193
197
|
{
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
198
|
+
PriorityQueue *priq;
|
199
|
+
VALUE rary;
|
200
|
+
Data_Get_Struct(self, PriorityQueue, priq);
|
201
|
+
rary = rb_iv_get(self, "@heap");
|
202
|
+
|
203
|
+
priq_down(priq, self, rary);
|
204
|
+
|
205
|
+
return Qnil;
|
201
206
|
}
|
202
207
|
|
203
208
|
|
@@ -210,18 +215,18 @@ frt_priq_adjust_top(VALUE self)
|
|
210
215
|
void
|
211
216
|
Init_priority_queue(void)
|
212
217
|
{
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
218
|
+
less_than = rb_intern("less_than");
|
219
|
+
put_heap = rb_intern("put_heap");
|
220
|
+
|
221
|
+
cPriorityQueue = rb_define_class_under(mUtils, "PriorityQueue", rb_cObject);
|
222
|
+
rb_define_alloc_func(cPriorityQueue, frt_priq_alloc);
|
223
|
+
|
224
|
+
rb_define_method(cPriorityQueue, "initialize", frt_priq_init, 1);
|
225
|
+
rb_define_method(cPriorityQueue, "pop", frt_priq_pop, 0);
|
226
|
+
rb_define_method(cPriorityQueue, "top", frt_priq_top, 0);
|
227
|
+
rb_define_method(cPriorityQueue, "clear", frt_priq_clear, 0);
|
228
|
+
rb_define_method(cPriorityQueue, "insert", frt_priq_insert, 1);
|
229
|
+
rb_define_method(cPriorityQueue, "push", frt_priq_push, 1);
|
230
|
+
rb_define_method(cPriorityQueue, "size", frt_priq_size, 0);
|
231
|
+
rb_define_method(cPriorityQueue, "adjust_top", frt_priq_adjust_top, 0);
|
227
232
|
}
|
data/ext/ram_directory.c
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#include "ferret.h"
|
2
2
|
|
3
|
-
ID flush, seek;
|
3
|
+
ID flush, seek, id_file, id_pointer;
|
4
4
|
|
5
5
|
/****************************************************************************
|
6
6
|
*
|
@@ -33,23 +33,24 @@ frt_rf_alloc(VALUE klass)
|
|
33
33
|
{
|
34
34
|
RAMFile *rf;
|
35
35
|
byte_t *buf;
|
36
|
+
VALUE rrf;
|
36
37
|
|
37
|
-
rf =
|
38
|
-
buf =
|
39
|
-
rf->buffers =
|
38
|
+
rf = ALLOC(RAMFile);
|
39
|
+
buf = ALLOC_N(byte_t, BUFFER_SIZE);
|
40
|
+
rf->buffers = ALLOC_N(void *, 1);
|
40
41
|
rf->buffers[0] = buf;
|
41
42
|
rf->bufcnt = 1;
|
42
43
|
rf->length = 0;
|
43
|
-
rf->mtime = rb_funcall(rb_cTime,
|
44
|
+
rf->mtime = rb_funcall(rb_cTime, id_new, 0);
|
44
45
|
|
45
|
-
|
46
|
+
rrf = Data_Wrap_Struct(klass, frt_rf_mark, frt_rf_free, rf);
|
46
47
|
return rrf;
|
47
48
|
}
|
48
49
|
|
49
50
|
void
|
50
51
|
frt_rf_extend(RAMFile *rf)
|
51
52
|
{
|
52
|
-
byte_t *buf =
|
53
|
+
byte_t *buf = ALLOC_N(byte_t, BUFFER_SIZE);
|
53
54
|
rf->bufcnt++;
|
54
55
|
REALLOC_N(rf->buffers, void *, rf->bufcnt);
|
55
56
|
rf->buffers[rf->bufcnt - 1] = buf;
|
@@ -73,17 +74,17 @@ frt_rf_length(VALUE self)
|
|
73
74
|
static VALUE
|
74
75
|
frt_rio_init(VALUE self, VALUE ramfile)
|
75
76
|
{
|
76
|
-
|
77
|
-
|
77
|
+
rb_ivar_set(self, id_file, ramfile);
|
78
|
+
rb_ivar_set(self, id_pointer, INT2FIX(0));
|
78
79
|
return self;
|
79
80
|
}
|
80
81
|
|
81
82
|
static VALUE
|
82
83
|
frt_rio_length(VALUE self)
|
83
84
|
{
|
84
|
-
|
85
|
+
VALUE file = rb_ivar_get(self, id_file);
|
85
86
|
RAMFile *rf;
|
86
|
-
|
87
|
+
Data_Get_Struct(file, RAMFile, rf);
|
87
88
|
return INT2FIX(rf->length);
|
88
89
|
}
|
89
90
|
|
@@ -102,11 +103,12 @@ frt_rio_flush_buffer(VALUE self, VALUE rsrc, VALUE rlen)
|
|
102
103
|
int src_offset;
|
103
104
|
int len = FIX2INT(rlen);
|
104
105
|
/* char *src = StringValuePtr(rsrc); */
|
105
|
-
int pointer = FIX2INT(
|
106
|
+
int pointer = FIX2INT(rb_ivar_get(self, id_pointer));
|
107
|
+
byte_t *buffer;
|
106
108
|
|
107
|
-
|
109
|
+
VALUE file = rb_ivar_get(self, id_file);
|
108
110
|
RAMFile *rf;
|
109
|
-
|
111
|
+
Data_Get_Struct(file, RAMFile, rf);
|
110
112
|
|
111
113
|
buffer_number = (int)(pointer / BUFFER_SIZE);
|
112
114
|
buffer_offset = pointer % BUFFER_SIZE;
|
@@ -115,7 +117,7 @@ frt_rio_flush_buffer(VALUE self, VALUE rsrc, VALUE rlen)
|
|
115
117
|
|
116
118
|
frt_extend_buffer_if_necessary(rf, buffer_number);
|
117
119
|
|
118
|
-
|
120
|
+
buffer = rf->buffers[buffer_number];
|
119
121
|
MEMCPY(buffer + buffer_offset, RSTRING(rsrc)->ptr, byte_t, bytes_to_copy);
|
120
122
|
|
121
123
|
if (bytes_to_copy < len) {
|
@@ -128,12 +130,12 @@ frt_rio_flush_buffer(VALUE self, VALUE rsrc, VALUE rlen)
|
|
128
130
|
MEMCPY(buffer, RSTRING(rsrc)->ptr + src_offset, byte_t, bytes_to_copy);
|
129
131
|
}
|
130
132
|
pointer += len;
|
131
|
-
|
133
|
+
rb_ivar_set(self, id_pointer, INT2FIX(pointer));
|
132
134
|
|
133
135
|
if (pointer > rf->length)
|
134
136
|
rf->length = pointer;
|
135
137
|
|
136
|
-
rf->mtime =
|
138
|
+
rf->mtime = rb_class_new_instance(0, NULL, rb_cTime);
|
137
139
|
return Qnil;
|
138
140
|
}
|
139
141
|
|
@@ -142,7 +144,7 @@ frt_rio_seek(VALUE self, VALUE rpos)
|
|
142
144
|
{
|
143
145
|
rb_call_super(1, &rpos);
|
144
146
|
|
145
|
-
|
147
|
+
rb_ivar_set(self, id_pointer, rpos);
|
146
148
|
|
147
149
|
return rpos;
|
148
150
|
}
|
@@ -150,24 +152,23 @@ frt_rio_seek(VALUE self, VALUE rpos)
|
|
150
152
|
static VALUE
|
151
153
|
frt_rio_reset(VALUE self)
|
152
154
|
{
|
153
|
-
|
155
|
+
VALUE file = rb_ivar_get(self, id_file);
|
154
156
|
RAMFile *rf;
|
155
|
-
|
156
|
-
|
157
|
-
rf->length = 0;
|
157
|
+
Data_Get_Struct(file, RAMFile, rf);
|
158
158
|
|
159
159
|
rb_funcall(self, seek, 1, INT2FIX(0));
|
160
160
|
|
161
|
+
rf->length = 0;
|
161
162
|
return Qnil;
|
162
163
|
}
|
163
164
|
|
164
165
|
static VALUE
|
165
166
|
frt_rio_close(VALUE self)
|
166
167
|
{
|
167
|
-
|
168
|
+
VALUE file = rb_ivar_get(self, id_file);
|
168
169
|
RAMFile *rf;
|
169
|
-
|
170
|
-
rf->mtime = rb_funcall(rb_cTime,
|
170
|
+
Data_Get_Struct(file, RAMFile, rf);
|
171
|
+
rf->mtime = rb_funcall(rb_cTime, id_new, 0);
|
171
172
|
rb_call_super(0, NULL);
|
172
173
|
return Qnil;
|
173
174
|
}
|
@@ -176,14 +177,15 @@ static VALUE
|
|
176
177
|
frt_rio_write_to(VALUE self, VALUE routput)
|
177
178
|
{
|
178
179
|
int i, len;
|
179
|
-
|
180
|
+
int last_buffer_number, last_buffer_offset;
|
181
|
+
VALUE file = rb_ivar_get(self, id_file);
|
180
182
|
RAMFile *rf;
|
181
|
-
|
183
|
+
Data_Get_Struct(file, RAMFile, rf);
|
182
184
|
|
183
185
|
rb_funcall(self, flush, 0);
|
184
186
|
|
185
|
-
|
186
|
-
|
187
|
+
last_buffer_number = (int)(rf->length / BUFFER_SIZE);
|
188
|
+
last_buffer_offset = rf->length % BUFFER_SIZE;
|
187
189
|
|
188
190
|
for (i = 0; i < rf->bufcnt; i++) {
|
189
191
|
len = ((i == last_buffer_number) ? last_buffer_offset : BUFFER_SIZE);
|
@@ -202,36 +204,36 @@ frt_rio_write_to(VALUE self, VALUE routput)
|
|
202
204
|
static VALUE
|
203
205
|
frt_rii_init(VALUE self, VALUE ramfile)
|
204
206
|
{
|
205
|
-
|
206
|
-
|
207
|
+
rb_ivar_set(self, id_file, ramfile);
|
208
|
+
rb_ivar_set(self, id_pointer, INT2FIX(0));
|
207
209
|
return self;
|
208
210
|
}
|
209
211
|
|
210
212
|
static VALUE
|
211
213
|
frt_rii_length(VALUE self)
|
212
214
|
{
|
213
|
-
|
215
|
+
VALUE file = rb_ivar_get(self, id_file);
|
214
216
|
RAMFile *rf;
|
215
|
-
|
217
|
+
Data_Get_Struct(file, RAMFile, rf);
|
216
218
|
return INT2FIX(rf->length);
|
217
219
|
}
|
218
220
|
|
219
221
|
static VALUE
|
220
222
|
frt_rii_read_internal(VALUE self, VALUE rb, VALUE roffset, VALUE rlen)
|
221
223
|
{
|
222
|
-
VALUE file = rb_iv_get(self, "file");
|
223
|
-
RAMFile *rf;
|
224
|
-
Data_Get_Struct(file, RAMFile, rf);
|
225
|
-
|
226
224
|
int buffer_number, buffer_offset, bytes_in_buffer, bytes_to_copy;
|
227
225
|
int offset = FIX2INT(roffset);
|
228
226
|
int len = FIX2INT(rlen);
|
229
227
|
int remainder = len;
|
230
|
-
int pointer = FIX2INT(
|
228
|
+
int pointer = FIX2INT(rb_ivar_get(self, id_pointer));
|
231
229
|
int start = pointer;
|
232
230
|
byte_t *buffer;
|
233
231
|
byte_t *b = (byte_t *)StringValuePtr(rb);
|
234
232
|
|
233
|
+
VALUE file = rb_ivar_get(self, id_file);
|
234
|
+
RAMFile *rf;
|
235
|
+
Data_Get_Struct(file, RAMFile, rf);
|
236
|
+
|
235
237
|
while (remainder > 0) {
|
236
238
|
buffer_number = (int)(start / BUFFER_SIZE);
|
237
239
|
buffer_offset = start % BUFFER_SIZE;
|
@@ -249,14 +251,14 @@ frt_rii_read_internal(VALUE self, VALUE rb, VALUE roffset, VALUE rlen)
|
|
249
251
|
remainder -= bytes_to_copy;
|
250
252
|
}
|
251
253
|
|
252
|
-
|
254
|
+
rb_ivar_set(self, id_pointer, INT2FIX(pointer + len));
|
253
255
|
return Qnil;
|
254
256
|
}
|
255
257
|
|
256
258
|
static VALUE
|
257
259
|
frt_rii_seek_internal(VALUE self, VALUE rpos)
|
258
260
|
{
|
259
|
-
|
261
|
+
rb_ivar_set(self, id_pointer, rpos);
|
260
262
|
return Qnil;
|
261
263
|
}
|
262
264
|
|
@@ -275,16 +277,19 @@ frt_rii_close(VALUE self)
|
|
275
277
|
void
|
276
278
|
Init_ram_directory(void)
|
277
279
|
{
|
280
|
+
VALUE cDirectory, cRAMFile;
|
278
281
|
/* IDs */
|
279
282
|
flush = rb_intern("flush");
|
280
283
|
seek = rb_intern("seek");
|
284
|
+
id_file = rb_intern("@file");
|
285
|
+
id_pointer = rb_intern("@pointer");
|
281
286
|
|
282
287
|
/* RAMDirectory */
|
283
|
-
|
288
|
+
cDirectory = rb_define_class_under(mStore, "Directory", rb_cObject);
|
284
289
|
cRAMDirectory = rb_define_class_under(mStore, "RAMDirectory", cDirectory);
|
285
290
|
|
286
291
|
/* RAMFile */
|
287
|
-
|
292
|
+
cRAMFile = rb_define_class_under(cRAMDirectory, "RAMFile", rb_cObject);
|
288
293
|
rb_define_alloc_func(cRAMFile, frt_rf_alloc);
|
289
294
|
|
290
295
|
/* Methods */
|