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.
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 |
# File 'lib/fairy/node/p-group-by.rb', line 1480 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
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 |
# File 'lib/fairy/node/p-group-by.rb', line 1505 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
1497 1498 1499 |
# File 'lib/fairy/node/p-group-by.rb', line 1497 def eof? @eof end |
#key ⇒ Object
1501 1502 1503 |
# File 'lib/fairy/node/p-group-by.rb', line 1501 def key @key end |
#read_buffer ⇒ Object
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 |
# File 'lib/fairy/node/p-group-by.rb', line 1524 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 |