Method: Containers::RubyRBTreeMap#each
- Defined in:
- lib/containers/rb_tree_map.rb
#each ⇒ Object
Iterates over the TreeMap from smallest to largest element. Iterative approach.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/containers/rb_tree_map.rb', line 183 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 |