class ExternalSortModule::Chunk

Base class for chunking file access. Essentially a buffer that acts as a sliding window into a binary file.

Public Class Methods

new(target_file, target_offset, target_length, element_size, chunk_size = MAX_CHUNK_SIZE_) click to toggle source

Constructor @param target_file file containing target area @param target_offset offset to start of the target area for this chunk @param target_length length of target area @param element_size size of each element; target_length must be a multiple of this

# File lib/geotree/externalsort.rb, line 24
def initialize(target_file, target_offset, target_length, element_size, chunk_size = MAX_CHUNK_SIZE_)
  @target_file = target_file
  @target_offset = target_offset
  @target_length = target_length

  @target_end_offset = target_offset + target_length
  @element_size = element_size
  raise ArgumentError if target_length % element_size != 0

  set_chunk_size(chunk_size)

  @buffer = []
  @buffer_offset = 0
end

Public Instance Methods

done() click to toggle source
# File lib/geotree/externalsort.rb, line 45
def done
  @buffer_offset == @buffer.size && @target_offset == @target_end_offset
end
set_chunk_size(n) click to toggle source
# File lib/geotree/externalsort.rb, line 39
def set_chunk_size(n)
  n -= (n % @element_size)
  raise ArgumentError if n <= 0
  @max_chunk_size = [n,@target_length].min
end