Class: Ferret::Store::RAMDirectory::RAMIndexInput

Inherits:
BufferedIndexInput show all
Defined in:
lib/ferret/store/ram_store.rb,
ext/ram_directory.c

Instance Method Summary collapse

Methods inherited from BufferedIndexInput

#initialize_copy, #pos, #read_byte, #read_bytes, #read_chars, #read_int, #read_long, #read_string, #read_uint, #read_ulong, #read_vint, #read_vlong, #refill, #seek

Methods inherited from IndexInput

#pos, #read_byte, #read_bytes, #read_chars, #read_int, #read_long, #read_string, #read_uint, #read_ulong, #read_vint, #seek

Constructor Details

#initialize(ramfile) ⇒ Object

**************************************************************************

RAMIndexInput Methods

**************************************************************************



202
203
204
205
206
# File 'ext/ram_directory.c', line 202

def initialize(f)
  @pointer = 0
  @file = f
  super()
end

Instance Method Details

#closeObject



263
264
# File 'ext/ram_directory.c', line 263

def close
end

#lengthObject



210
211
212
# File 'ext/ram_directory.c', line 210

def length
  return @file.length
end

#read_internal(rb, roffset, rlen) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'ext/ram_directory.c', line 219

def read_internal(b, offset, length)
  remainder = length
  start = @pointer
  
  while remainder != 0
    buffer_number = (start / BUFFER_SIZE).to_i
    buffer_offset = start % BUFFER_SIZE
    bytes_in_buffer = BUFFER_SIZE - buffer_offset
    
    if bytes_in_buffer >= remainder
      bytes_to_copy = remainder
    else
      bytes_to_copy = bytes_in_buffer
    end
    buffer = @file.buffers[buffer_number]
    bo2 = buffer_offset
    do2 = offset
    b[do2, bytes_to_copy] = buffer[bo2, bytes_to_copy]
    offset += bytes_to_copy
    start += bytes_to_copy
    remainder -= bytes_to_copy
  end
  
  @pointer += length
end

#seek_internal(rpos) ⇒ Object



256
257
258
# File 'ext/ram_directory.c', line 256

def seek_internal(pos)
  @pointer = pos
end