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



559
560
561
562
# File 'lib/innodb/page/index.rb', line 559

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.



566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
# File 'lib/innodb/page/index.rb', line 566

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