Class: Fairy::PGroupBy::DirectKB2MergeSortBuffer::CachedBuffer
- Inherits:
-
Object
- Object
- Fairy::PGroupBy::DirectKB2MergeSortBuffer::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.
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 |
# File 'lib/fairy/node/p-group-by.rb', line 1469 def initialize(njob, io) @njob = njob @io = io io.open @cache = [] @eof = false read_buffer @key = @njob.hash_key(@cache.first.first) end |
Instance Method Details
#each_by_same_key(&block) ⇒ Object
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 |
# File 'lib/fairy/node/p-group-by.rb', line 1494 def each_by_same_key(&block) loop do while vv = @cache.shift unless @njob.hash_key(vv.first) == @key @cache.unshift vv @key = @njob.hash_key(vv.first) return end vv.each &block end read_buffer return if @cache.empty? unless @njob.hash_key(@cache.first.first) == @key @key = @njob.hash_key(@cache.first.first) return end end end |
#eof? ⇒ Boolean
1486 1487 1488 |
# File 'lib/fairy/node/p-group-by.rb', line 1486 def eof? @eof end |
#key ⇒ Object
1490 1491 1492 |
# File 'lib/fairy/node/p-group-by.rb', line 1490 def key @key end |
#read_buffer ⇒ Object
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 |
# File 'lib/fairy/node/p-group-by.rb', line 1513 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 |