class Innodb::List::ListCursor
A list iteration cursor used primarily by the Innodb::List
cursor method implicitly. Keeps its own state for iterating through lists efficiently.
Public Class Methods
new(list, node = :min, direction = :forward)
click to toggle source
# File lib/innodb/list.rb, line 143 def initialize(list, node = :min, direction = :forward) @initial = true @list = list @direction = direction @node = initial_node(node) end
Public Instance Methods
each_node() { |n| ... }
click to toggle source
# File lib/innodb/list.rb, line 195 def each_node return enum_for(:each_node) unless block_given? while (n = node) yield n end end
goto_node(node)
click to toggle source
# File lib/innodb/list.rb, line 175 def goto_node(node) @node = node if node end
initial_node(node)
click to toggle source
# File lib/innodb/list.rb, line 150 def initial_node(node) case node when :min @list.first when :max @list.last else node end end
next_node()
click to toggle source
Return the next entry from the current position, and advance the cursor position to the returned entry. If the cursor is currently nil, return the first entry in the list and adjust the cursor position to that entry.
# File lib/innodb/list.rb, line 191 def next_node goto_node(@list.next(@node)) end
node()
click to toggle source
# File lib/innodb/list.rb, line 161 def node if @initial @initial = false return @node end case @direction when :forward next_node when :backward prev_node end end
prev_node()
click to toggle source
Return the previous entry from the current position, and advance the cursor position to the returned entry. If the cursor is currently nil, return the last entry in the list and adjust the cursor position to that entry.
# File lib/innodb/list.rb, line 183 def prev_node goto_node(@list.prev(@node)) end