ferret 0.3.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/CHANGELOG +9 -0
  2. data/Rakefile +51 -25
  3. data/ext/analysis.c +553 -0
  4. data/ext/analysis.h +76 -0
  5. data/ext/array.c +83 -0
  6. data/ext/array.h +19 -0
  7. data/ext/bitvector.c +164 -0
  8. data/ext/bitvector.h +29 -0
  9. data/ext/compound_io.c +335 -0
  10. data/ext/document.c +336 -0
  11. data/ext/document.h +87 -0
  12. data/ext/ferret.c +88 -47
  13. data/ext/ferret.h +43 -109
  14. data/ext/field.c +395 -0
  15. data/ext/filter.c +103 -0
  16. data/ext/fs_store.c +352 -0
  17. data/ext/global.c +219 -0
  18. data/ext/global.h +73 -0
  19. data/ext/hash.c +446 -0
  20. data/ext/hash.h +80 -0
  21. data/ext/hashset.c +141 -0
  22. data/ext/hashset.h +37 -0
  23. data/ext/helper.c +11 -0
  24. data/ext/helper.h +5 -0
  25. data/ext/inc/lang.h +41 -0
  26. data/ext/ind.c +389 -0
  27. data/ext/index.h +884 -0
  28. data/ext/index_io.c +269 -415
  29. data/ext/index_rw.c +2543 -0
  30. data/ext/lang.c +31 -0
  31. data/ext/lang.h +41 -0
  32. data/ext/priorityqueue.c +228 -0
  33. data/ext/priorityqueue.h +44 -0
  34. data/ext/q_boolean.c +1331 -0
  35. data/ext/q_const_score.c +154 -0
  36. data/ext/q_fuzzy.c +287 -0
  37. data/ext/q_match_all.c +142 -0
  38. data/ext/q_multi_phrase.c +343 -0
  39. data/ext/q_parser.c +2180 -0
  40. data/ext/q_phrase.c +657 -0
  41. data/ext/q_prefix.c +75 -0
  42. data/ext/q_range.c +247 -0
  43. data/ext/q_span.c +1566 -0
  44. data/ext/q_term.c +308 -0
  45. data/ext/q_wildcard.c +146 -0
  46. data/ext/r_analysis.c +255 -0
  47. data/ext/r_doc.c +578 -0
  48. data/ext/r_index_io.c +996 -0
  49. data/ext/r_qparser.c +158 -0
  50. data/ext/r_search.c +2321 -0
  51. data/ext/r_store.c +263 -0
  52. data/ext/r_term.c +219 -0
  53. data/ext/ram_store.c +447 -0
  54. data/ext/search.c +524 -0
  55. data/ext/search.h +1065 -0
  56. data/ext/similarity.c +143 -39
  57. data/ext/sort.c +661 -0
  58. data/ext/store.c +35 -0
  59. data/ext/store.h +152 -0
  60. data/ext/term.c +704 -143
  61. data/ext/termdocs.c +599 -0
  62. data/ext/vector.c +594 -0
  63. data/lib/ferret.rb +9 -10
  64. data/lib/ferret/analysis/analyzers.rb +2 -2
  65. data/lib/ferret/analysis/standard_tokenizer.rb +1 -1
  66. data/lib/ferret/analysis/token.rb +14 -14
  67. data/lib/ferret/analysis/token_filters.rb +3 -3
  68. data/lib/ferret/document/field.rb +16 -17
  69. data/lib/ferret/index/document_writer.rb +4 -4
  70. data/lib/ferret/index/index.rb +39 -23
  71. data/lib/ferret/index/index_writer.rb +2 -2
  72. data/lib/ferret/index/multiple_term_doc_pos_enum.rb +1 -8
  73. data/lib/ferret/index/segment_term_vector.rb +4 -4
  74. data/lib/ferret/index/term.rb +5 -1
  75. data/lib/ferret/index/term_vector_offset_info.rb +6 -6
  76. data/lib/ferret/index/term_vectors_io.rb +5 -5
  77. data/lib/ferret/query_parser/query_parser.tab.rb +81 -77
  78. data/lib/ferret/search.rb +1 -1
  79. data/lib/ferret/search/boolean_query.rb +2 -1
  80. data/lib/ferret/search/field_sorted_hit_queue.rb +3 -3
  81. data/lib/ferret/search/fuzzy_query.rb +2 -1
  82. data/lib/ferret/search/index_searcher.rb +3 -0
  83. data/lib/ferret/search/{match_all_docs_query.rb → match_all_query.rb} +7 -7
  84. data/lib/ferret/search/multi_phrase_query.rb +6 -5
  85. data/lib/ferret/search/phrase_query.rb +3 -6
  86. data/lib/ferret/search/prefix_query.rb +4 -4
  87. data/lib/ferret/search/sort.rb +3 -1
  88. data/lib/ferret/search/sort_field.rb +9 -9
  89. data/lib/ferret/search/spans/near_spans_enum.rb +1 -1
  90. data/lib/ferret/search/spans/span_near_query.rb +1 -1
  91. data/lib/ferret/search/spans/span_weight.rb +1 -1
  92. data/lib/ferret/search/spans/spans_enum.rb +7 -7
  93. data/lib/ferret/store/fs_store.rb +10 -6
  94. data/lib/ferret/store/ram_store.rb +3 -3
  95. data/lib/rferret.rb +36 -0
  96. data/test/functional/thread_safety_index_test.rb +2 -2
  97. data/test/test_helper.rb +16 -2
  98. data/test/unit/analysis/c_token.rb +25 -0
  99. data/test/unit/analysis/tc_per_field_analyzer_wrapper.rb +1 -1
  100. data/test/unit/analysis/tc_standard_analyzer.rb +1 -1
  101. data/test/unit/document/{tc_document.rb → c_document.rb} +0 -0
  102. data/test/unit/document/c_field.rb +98 -0
  103. data/test/unit/document/tc_field.rb +0 -66
  104. data/test/unit/index/{tc_index.rb → c_index.rb} +62 -6
  105. data/test/unit/index/{tc_index_reader.rb → c_index_reader.rb} +51 -10
  106. data/test/unit/index/{tc_index_writer.rb → c_index_writer.rb} +0 -4
  107. data/test/unit/index/{tc_term.rb → c_term.rb} +1 -3
  108. data/test/unit/index/{tc_term_vector_offset_info.rb → c_term_voi.rb} +5 -5
  109. data/test/unit/index/tc_segment_term_vector.rb +2 -2
  110. data/test/unit/index/tc_term_vectors_io.rb +4 -4
  111. data/test/unit/query_parser/c_query_parser.rb +138 -0
  112. data/test/unit/search/{tc_filter.rb → c_filter.rb} +24 -24
  113. data/test/unit/search/{tc_fuzzy_query.rb → c_fuzzy_query.rb} +0 -0
  114. data/test/unit/search/{tc_index_searcher.rb → c_index_searcher.rb} +9 -26
  115. data/test/unit/search/{tc_search_and_sort.rb → c_search_and_sort.rb} +15 -15
  116. data/test/unit/search/{tc_sort.rb → c_sort.rb} +2 -1
  117. data/test/unit/search/c_sort_field.rb +27 -0
  118. data/test/unit/search/{tc_spans.rb → c_spans.rb} +0 -0
  119. data/test/unit/search/tc_sort_field.rb +7 -20
  120. data/test/unit/store/c_fs_store.rb +76 -0
  121. data/test/unit/store/c_ram_store.rb +35 -0
  122. data/test/unit/store/m_store.rb +34 -0
  123. data/test/unit/store/m_store_lock.rb +68 -0
  124. data/test/unit/store/tc_fs_store.rb +0 -53
  125. data/test/unit/store/tc_ram_store.rb +0 -20
  126. data/test/unit/store/tm_store.rb +0 -30
  127. data/test/unit/store/tm_store_lock.rb +0 -66
  128. metadata +84 -31
  129. data/ext/Makefile +0 -140
  130. data/ext/ferret_ext.so +0 -0
  131. data/ext/priority_queue.c +0 -232
  132. data/ext/ram_directory.c +0 -321
  133. data/ext/segment_merge_queue.c +0 -37
  134. data/ext/segment_term_enum.c +0 -326
  135. data/ext/string_helper.c +0 -42
  136. data/ext/tags +0 -344
  137. data/ext/term_buffer.c +0 -230
  138. data/ext/term_infos_reader.c +0 -54
  139. data/ext/terminfo.c +0 -160
  140. data/ext/token.c +0 -93
  141. data/ext/util.c +0 -12
data/ext/ferret_ext.so DELETED
Binary file
data/ext/priority_queue.c DELETED
@@ -1,232 +0,0 @@
1
- #include "ferret.h"
2
-
3
- ID less_than, put_heap;
4
- /****************************************************************************
5
- *
6
- * PriorityQueue Methods
7
- *
8
- ****************************************************************************/
9
-
10
- void
11
- frt_priq_free(void *p)
12
- {
13
- free(p);
14
- }
15
-
16
- static VALUE
17
- frt_priq_alloc(VALUE klass)
18
- {
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;
26
- }
27
-
28
- static VALUE
29
- frt_priq_init(VALUE self, VALUE rsize)
30
- {
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;
42
- }
43
-
44
- void
45
- priq_up(PriorityQueue *priq, VALUE self, VALUE rary)
46
- {
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);
60
- }
61
-
62
- void
63
- priq_down(PriorityQueue *priq, VALUE self, VALUE rary)
64
- {
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);
87
- }
88
-
89
- static VALUE
90
- frt_priq_push(VALUE self, VALUE e)
91
- {
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;
105
- }
106
-
107
- static VALUE
108
- frt_priq_insert(VALUE self, VALUE e)
109
- {
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;
129
- }
130
- }
131
-
132
- static VALUE
133
- frt_priq_top(VALUE self)
134
- {
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;
147
- }
148
-
149
- static VALUE
150
- frt_priq_pop(VALUE self)
151
- {
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;
171
- }
172
-
173
- static VALUE
174
- frt_priq_clear(VALUE self)
175
- {
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
-
185
- }
186
-
187
- static VALUE
188
- frt_priq_size(VALUE self)
189
- {
190
- PriorityQueue *priq;
191
- Data_Get_Struct(self, PriorityQueue, priq);
192
- return INT2FIX(priq->len);
193
- }
194
-
195
- static VALUE
196
- frt_priq_adjust_top(VALUE self)
197
- {
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;
206
- }
207
-
208
-
209
- /****************************************************************************
210
- *
211
- * Init Function
212
- *
213
- ****************************************************************************/
214
-
215
- void
216
- Init_priority_queue(void)
217
- {
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);
232
- }
data/ext/ram_directory.c DELETED
@@ -1,321 +0,0 @@
1
- #include "ferret.h"
2
-
3
- ID flush, seek, id_file, id_pointer;
4
-
5
- /****************************************************************************
6
- *
7
- * RAMFile Methods
8
- *
9
- ****************************************************************************/
10
-
11
- void
12
- frt_rf_free(void *p)
13
- {
14
- int i;
15
- RAMFile *rf = (RAMFile *)p;
16
-
17
- for (i = 0; i < rf->bufcnt; i++) {
18
- free(rf->buffers[i]);
19
- }
20
- free(rf->buffers);
21
- free(rf);
22
- }
23
-
24
- void
25
- frt_rf_mark(void *p)
26
- {
27
- RAMFile *rf = (RAMFile *)p;
28
- rb_gc_mark(rf->mtime);
29
- }
30
-
31
- static VALUE
32
- frt_rf_alloc(VALUE klass)
33
- {
34
- RAMFile *rf;
35
- byte_t *buf;
36
- VALUE rrf;
37
-
38
- rf = ALLOC(RAMFile);
39
- buf = ALLOC_N(byte_t, BUFFER_SIZE);
40
- rf->buffers = ALLOC_N(void *, 1);
41
- rf->buffers[0] = buf;
42
- rf->bufcnt = 1;
43
- rf->length = 0;
44
- rf->mtime = rb_funcall(rb_cTime, id_new, 0);
45
-
46
- rrf = Data_Wrap_Struct(klass, frt_rf_mark, frt_rf_free, rf);
47
- return rrf;
48
- }
49
-
50
- void
51
- frt_rf_extend(RAMFile *rf)
52
- {
53
- byte_t *buf = ALLOC_N(byte_t, BUFFER_SIZE);
54
- rf->bufcnt++;
55
- REALLOC_N(rf->buffers, void *, rf->bufcnt);
56
- rf->buffers[rf->bufcnt - 1] = buf;
57
- }
58
-
59
- static VALUE
60
- frt_rf_length(VALUE self)
61
- {
62
- RAMFile *rf;
63
- Data_Get_Struct(self, RAMFile, rf);
64
-
65
- return INT2FIX(rf->length);
66
- }
67
-
68
- /****************************************************************************
69
- *
70
- * RAMIndexOutput Methods
71
- *
72
- ****************************************************************************/
73
-
74
- static VALUE
75
- frt_rio_init(VALUE self, VALUE ramfile)
76
- {
77
- rb_ivar_set(self, id_file, ramfile);
78
- rb_ivar_set(self, id_pointer, INT2FIX(0));
79
- return self;
80
- }
81
-
82
- static VALUE
83
- frt_rio_length(VALUE self)
84
- {
85
- VALUE file = rb_ivar_get(self, id_file);
86
- RAMFile *rf;
87
- Data_Get_Struct(file, RAMFile, rf);
88
- return INT2FIX(rf->length);
89
- }
90
-
91
- void
92
- frt_extend_buffer_if_necessary(RAMFile *rf, int bufnum)
93
- {
94
- while (bufnum >= rf->bufcnt) {
95
- frt_rf_extend(rf);
96
- }
97
- }
98
-
99
- static VALUE
100
- frt_rio_flush_buffer(VALUE self, VALUE rsrc, VALUE rlen)
101
- {
102
- int buffer_number, buffer_offset, bytes_in_buffer, bytes_to_copy;
103
- int src_offset;
104
- int len = FIX2INT(rlen);
105
- /* char *src = StringValuePtr(rsrc); */
106
- int pointer = FIX2INT(rb_ivar_get(self, id_pointer));
107
- byte_t *buffer;
108
-
109
- VALUE file = rb_ivar_get(self, id_file);
110
- RAMFile *rf;
111
- Data_Get_Struct(file, RAMFile, rf);
112
-
113
- buffer_number = (int)(pointer / BUFFER_SIZE);
114
- buffer_offset = pointer % BUFFER_SIZE;
115
- bytes_in_buffer = BUFFER_SIZE - buffer_offset;
116
- bytes_to_copy = bytes_in_buffer < len ? bytes_in_buffer : len;
117
-
118
- frt_extend_buffer_if_necessary(rf, buffer_number);
119
-
120
- buffer = rf->buffers[buffer_number];
121
- MEMCPY(buffer + buffer_offset, RSTRING(rsrc)->ptr, byte_t, bytes_to_copy);
122
-
123
- if (bytes_to_copy < len) {
124
- src_offset = bytes_to_copy;
125
- bytes_to_copy = len - bytes_to_copy;
126
- buffer_number += 1;
127
- frt_extend_buffer_if_necessary(rf, buffer_number);
128
- buffer = rf->buffers[buffer_number];
129
-
130
- MEMCPY(buffer, RSTRING(rsrc)->ptr + src_offset, byte_t, bytes_to_copy);
131
- }
132
- pointer += len;
133
- rb_ivar_set(self, id_pointer, INT2FIX(pointer));
134
-
135
- if (pointer > rf->length)
136
- rf->length = pointer;
137
-
138
- rf->mtime = rb_class_new_instance(0, NULL, rb_cTime);
139
- return Qnil;
140
- }
141
-
142
- static VALUE
143
- frt_rio_seek(VALUE self, VALUE rpos)
144
- {
145
- rb_call_super(1, &rpos);
146
-
147
- rb_ivar_set(self, id_pointer, rpos);
148
-
149
- return rpos;
150
- }
151
-
152
- static VALUE
153
- frt_rio_reset(VALUE self)
154
- {
155
- VALUE file = rb_ivar_get(self, id_file);
156
- RAMFile *rf;
157
- Data_Get_Struct(file, RAMFile, rf);
158
-
159
- rb_funcall(self, seek, 1, INT2FIX(0));
160
-
161
- rf->length = 0;
162
- return Qnil;
163
- }
164
-
165
- static VALUE
166
- frt_rio_close(VALUE self)
167
- {
168
- VALUE file = rb_ivar_get(self, id_file);
169
- RAMFile *rf;
170
- Data_Get_Struct(file, RAMFile, rf);
171
- rf->mtime = rb_funcall(rb_cTime, id_new, 0);
172
- rb_call_super(0, NULL);
173
- return Qnil;
174
- }
175
-
176
- static VALUE
177
- frt_rio_write_to(VALUE self, VALUE routput)
178
- {
179
- int i, len;
180
- int last_buffer_number, last_buffer_offset;
181
- VALUE file = rb_ivar_get(self, id_file);
182
- RAMFile *rf;
183
- Data_Get_Struct(file, RAMFile, rf);
184
-
185
- rb_funcall(self, flush, 0);
186
-
187
- last_buffer_number = (int)(rf->length / BUFFER_SIZE);
188
- last_buffer_offset = rf->length % BUFFER_SIZE;
189
-
190
- for (i = 0; i < rf->bufcnt; i++) {
191
- len = ((i == last_buffer_number) ? last_buffer_offset : BUFFER_SIZE);
192
- frt_write_bytes(routput, rf->buffers[i], len);
193
- }
194
-
195
- return Qnil;
196
- }
197
-
198
- /****************************************************************************
199
- *
200
- * RAMIndexInput Methods
201
- *
202
- ****************************************************************************/
203
-
204
- static VALUE
205
- frt_rii_init(VALUE self, VALUE ramfile)
206
- {
207
- rb_ivar_set(self, id_file, ramfile);
208
- rb_ivar_set(self, id_pointer, INT2FIX(0));
209
- return self;
210
- }
211
-
212
- static VALUE
213
- frt_rii_length(VALUE self)
214
- {
215
- VALUE file = rb_ivar_get(self, id_file);
216
- RAMFile *rf;
217
- Data_Get_Struct(file, RAMFile, rf);
218
- return INT2FIX(rf->length);
219
- }
220
-
221
- static VALUE
222
- frt_rii_read_internal(VALUE self, VALUE rb, VALUE roffset, VALUE rlen)
223
- {
224
- int buffer_number, buffer_offset, bytes_in_buffer, bytes_to_copy;
225
- int offset = FIX2INT(roffset);
226
- int len = FIX2INT(rlen);
227
- int remainder = len;
228
- int pointer = FIX2INT(rb_ivar_get(self, id_pointer));
229
- int start = pointer;
230
- byte_t *buffer;
231
- byte_t *b = (byte_t *)StringValuePtr(rb);
232
-
233
- VALUE file = rb_ivar_get(self, id_file);
234
- RAMFile *rf;
235
- Data_Get_Struct(file, RAMFile, rf);
236
-
237
- while (remainder > 0) {
238
- buffer_number = (int)(start / BUFFER_SIZE);
239
- buffer_offset = start % BUFFER_SIZE;
240
- bytes_in_buffer = BUFFER_SIZE - buffer_offset;
241
-
242
- if (bytes_in_buffer >= remainder) {
243
- bytes_to_copy = remainder;
244
- } else {
245
- bytes_to_copy = bytes_in_buffer;
246
- }
247
- buffer = rf->buffers[buffer_number];
248
- MEMCPY(b + offset, buffer + buffer_offset, byte_t, bytes_to_copy);
249
- offset += bytes_to_copy;
250
- start += bytes_to_copy;
251
- remainder -= bytes_to_copy;
252
- }
253
-
254
- rb_ivar_set(self, id_pointer, INT2FIX(pointer + len));
255
- return Qnil;
256
- }
257
-
258
- static VALUE
259
- frt_rii_seek_internal(VALUE self, VALUE rpos)
260
- {
261
- rb_ivar_set(self, id_pointer, rpos);
262
- return Qnil;
263
- }
264
-
265
- static VALUE
266
- frt_rii_close(VALUE self)
267
- {
268
- return Qnil;
269
- }
270
-
271
- /****************************************************************************
272
- *
273
- * Init Function
274
- *
275
- ****************************************************************************/
276
-
277
- void
278
- Init_ram_directory(void)
279
- {
280
- VALUE cDirectory, cRAMFile;
281
- /* IDs */
282
- flush = rb_intern("flush");
283
- seek = rb_intern("seek");
284
- id_file = rb_intern("@file");
285
- id_pointer = rb_intern("@pointer");
286
-
287
- /* RAMDirectory */
288
- cDirectory = rb_define_class_under(mStore, "Directory", rb_cObject);
289
- cRAMDirectory = rb_define_class_under(mStore, "RAMDirectory", cDirectory);
290
-
291
- /* RAMFile */
292
- cRAMFile = rb_define_class_under(cRAMDirectory, "RAMFile", rb_cObject);
293
- rb_define_alloc_func(cRAMFile, frt_rf_alloc);
294
-
295
- /* Methods */
296
- rb_define_method(cRAMFile, "length", frt_rf_length, 0);
297
-
298
- /* RAMIndexOutput */
299
- cRAMIndexOut = rb_define_class_under(cRAMDirectory, "RAMIndexOutput", cBufferedIndexOut);
300
- /*rb_define_alloc_func(cRAMIndexOut, frt_ramio_alloc); */
301
-
302
- /* Methods */
303
- rb_define_method(cRAMIndexOut, "initialize", frt_rio_init, 1);
304
- rb_define_method(cRAMIndexOut, "length", frt_rio_length, 0);
305
- rb_define_method(cRAMIndexOut, "flush_buffer", frt_rio_flush_buffer, 2);
306
- rb_define_method(cRAMIndexOut, "reset", frt_rio_reset, 0);
307
- rb_define_method(cRAMIndexOut, "seek", frt_rio_seek, 1);
308
- rb_define_method(cRAMIndexOut, "close", frt_rio_close, 0);
309
- rb_define_method(cRAMIndexOut, "write_to", frt_rio_write_to, 1);
310
-
311
- /* RAMIndexInput */
312
- cRAMIndexIn = rb_define_class_under(cRAMDirectory, "RAMIndexInput", cBufferedIndexIn);
313
- /*rb_define_alloc_func(cRAMIndexIn, frt_ramio_alloc); */
314
-
315
- /* Methods */
316
- rb_define_method(cRAMIndexIn, "initialize", frt_rii_init, 1);
317
- rb_define_method(cRAMIndexIn, "length", frt_rii_length, 0);
318
- rb_define_method(cRAMIndexIn, "read_internal", frt_rii_read_internal, 3);
319
- rb_define_method(cRAMIndexIn, "seek_internal", frt_rii_seek_internal, 1);
320
- rb_define_method(cRAMIndexIn, "close", frt_rii_close, 0);
321
- }