Method: Containers::RubySplayTreeMap#each

Defined in:
lib/containers/splay_tree_map.rb

#eachObject

Iterates over the SplayTreeMap in ascending order. Uses an iterative, not recursive, approach.



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/containers/splay_tree_map.rb', line 189

def each
  return nil unless @root
  stack = Containers::Stack.new
  cursor = @root
  loop do
    if cursor
      stack.push(cursor)
      cursor = cursor.left
    else
      unless stack.empty?
        cursor = stack.pop
        yield(cursor.key, cursor.value)
        cursor = cursor.right
      else
        break
      end
    end
  end
end