Class: Fairy::PGroupBy::DirectKBMergeSortBuffer::CachedBuffer
- Inherits:
-
Object
- Object
- Fairy::PGroupBy::DirectKBMergeSortBuffer::CachedBuffer
- Extended by:
- Forwardable
- Defined in:
- lib/fairy/node/p-group-by.rb
Instance Method Summary collapse
- #each_by_same_key(&block) ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(njob, io) ⇒ CachedBuffer
constructor
A new instance of CachedBuffer.
- #key ⇒ Object
- #read_buffer ⇒ Object
Constructor Details
#initialize(njob, io) ⇒ CachedBuffer
Returns a new instance of CachedBuffer.
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 |
# File 'lib/fairy/node/p-group-by.rb', line 1382 def initialize(njob, io) @njob = njob @io = io io.open @cache = [] @eof = false read_buffer @key = @njob.hash_key(@cache.first) end |
Instance Method Details
#each_by_same_key(&block) ⇒ Object
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 |
# File 'lib/fairy/node/p-group-by.rb', line 1407 def each_by_same_key(&block) loop do @cache.each &block read_buffer return if @cache.empty? unless @njob.hash_key(@cache.first) == @key @key = @njob.hash_key(@cache.first) return end end end |
#eof? ⇒ Boolean
1399 1400 1401 |
# File 'lib/fairy/node/p-group-by.rb', line 1399 def eof? @eof end |
#key ⇒ Object
1403 1404 1405 |
# File 'lib/fairy/node/p-group-by.rb', line 1403 def key @key end |
#read_buffer ⇒ Object
1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 |
# File 'lib/fairy/node/p-group-by.rb', line 1419 def read_buffer io = @io.io begin @cache = Marshal.load(io) rescue EOFError @eof = true @cache = [] rescue ArgumentError Log::debug(self, "MARSHAL ERROR OCCURED!!") io.seek(-1024, IO::SEEK_CUR) buf = io.read(2048) Log::debugf(self, "File Contents: %s", buf) raise end end |