Class: ExternalSortModule::ChunkRandomAccess
- Defined in:
- lib/geotree/externalsort.rb
Overview
A subclass of Chunk that does not use a sliding window, and instead can contain the entire target length; includes methods for accessing target elements in arbitrary (non-streaming) order
Instance Attribute Summary collapse
-
#num_elements ⇒ Object
readonly
Returns the value of attribute num_elements.
Instance Method Summary collapse
-
#element(index) ⇒ Object
Get element from chunk.
-
#initialize(target_file, target_offset, target_length, element_size) ⇒ ChunkRandomAccess
constructor
Construct chunk, and read the complete targeted bytes to the buffer.
-
#replace_buffer_with(b) ⇒ Object
Replace existing buffer.
-
#write ⇒ Object
Write buffer to target.
Methods inherited from Chunk
Constructor Details
#initialize(target_file, target_offset, target_length, element_size) ⇒ ChunkRandomAccess
Construct chunk, and read the complete targeted bytes to the buffer
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/geotree/externalsort.rb', line 58 def initialize(target_file, target_offset, target_length, element_size) super(target_file,target_offset,target_length,element_size,target_length) @num_elements = target_length / element_size chunk_size = target_length f = @target_file f.pos = @target_offset @buffer = f.read(chunk_size) raise IOError if !@buffer || @buffer.size != chunk_size end |
Instance Attribute Details
#num_elements ⇒ Object (readonly)
Returns the value of attribute num_elements.
55 56 57 |
# File 'lib/geotree/externalsort.rb', line 55 def num_elements @num_elements end |
Instance Method Details
#element(index) ⇒ Object
Get element from chunk
73 74 75 76 77 |
# File 'lib/geotree/externalsort.rb', line 73 def element(index) raise ArgumentError if index < 0 || index >= num_elements off = index * @element_size [@buffer,off] end |
#replace_buffer_with(b) ⇒ Object
Replace existing buffer
80 81 82 83 |
# File 'lib/geotree/externalsort.rb', line 80 def replace_buffer_with(b) raise IllegalArgumentException if b.size != @buffer.size @buffer = b end |
#write ⇒ Object
Write buffer to target
86 87 88 89 90 91 |
# File 'lib/geotree/externalsort.rb', line 86 def write f = @target_file f.pos = @target_end_offset - @target_length bytes_written = f.write(@buffer) raise IOError if @buffer.size != bytes_written end |