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.



572
573
574
575
# File 'lib/innodb/page/index.rb', line 572

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.



579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# File 'lib/innodb/page/index.rb', line 579

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