class Innodb::Page::Index::RecordCursor
A class for cursoring through records starting from an arbitrary point.
Public Class Methods
new(page, offset, direction)
click to toggle source
# File lib/innodb/page/index.rb, line 715 def initialize(page, offset, direction) Innodb::Stats.increment :page_record_cursor_create @initial = true @page = page @direction = direction @record = initial_record(offset) end
Public Instance Methods
each_record() { |rec| ... }
click to toggle source
Iterate through all records in the cursor.
# File lib/innodb/page/index.rb, line 789 def each_record return enum_for(:each_record) unless block_given? while (rec = record) yield rec end end
initial_record(offset)
click to toggle source
# File lib/innodb/page/index.rb, line 724 def initial_record(offset) case offset when :min @page.min_record when :max @page.max_record else # Offset is a byte offset of a record (hopefully). @page.record(offset) end end
next_record()
click to toggle source
Return the next record, and advance the cursor. Return nil when the end of records (supremum) is reached.
# File lib/innodb/page/index.rb, line 738 def next_record Innodb::Stats.increment :page_record_cursor_next_record rec = @page.record(@record.next) # The garbage record list's end is self-linked, so we must check for # both supremum and the current record's offset. if rec == @page.supremum || rec.offset == @record.offset # We've reached the end of the linked list at supremum. nil else @record = rec end end
prev_record()
click to toggle source
Return the previous record, and advance the cursor. Return nil when the end of records (infimum) is reached.
# File lib/innodb/page/index.rb, line 755 def prev_record Innodb::Stats.increment :page_record_cursor_prev_record slot = @page.directory_slot_for_record(@record) raise "Could not find slot for record" unless slot search_cursor = @page.record_cursor(@page.directory[slot - 1]) raise "Could not position search cursor" unless search_cursor while (rec = search_cursor.record) && rec.offset != @record.offset next unless rec.next == @record.offset return if rec == @page.infimum return @record = rec end end
record()
click to toggle source
Return the next record in the order defined when the cursor was created.
# File lib/innodb/page/index.rb, line 774 def record if @initial @initial = false return @record end case @direction when :forward next_record when :backward prev_record end end