Class: Innodb::Page::Index::RecordCursor

Inherits:
Object
  • Object
show all
Defined in:
lib/innodb/page/index.rb

Overview

A class for cursoring through records starting from an arbitrary point.

Instance Method Summary collapse

Constructor Details

#initialize(page, offset) ⇒ RecordCursor

Returns a new instance of RecordCursor.



568
569
570
571
# File 'lib/innodb/page/index.rb', line 568

def initialize(page, offset)
  @page   = page
  @offset = offset
end

Instance Method Details

#recordObject

Return the next record, and advance the cursor. Return nil when the end of records is reached.



575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
# File 'lib/innodb/page/index.rb', line 575

def record
  return nil unless @offset

  record = @page.record(@offset)

  if record == @page.supremum
    # We've reached the end of the linked list at supremum.
    @offset = nil
  elsif record.next == @offset
    # The record links to itself; go ahead and return it (once), but set
    # the next offset to nil to end the loop.
    @offset = nil
    record
  else
    @offset = record.next
    record
  end
end