| 199 | { } |
| 200 | |
| 201 | pair<slice,Value> next() { |
| 202 | while (unsigned(++current.index) >= current.parent.childCount()) { |
| 203 | if (depth > 0) { |
| 204 | // Pop the stack: |
| 205 | current = stack[--depth]; |
| 206 | } else { |
| 207 | node.reset(); // at end |
| 208 | return {}; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // Get the current node: |
| 213 | while (true) { |
| 214 | node = current.parent.childAtIndex(current.index); |
| 215 | if (node.isLeaf()) |
| 216 | break; |
| 217 | |
| 218 | // If it's an interior node, recurse into its children: |
| 219 | assert(depth < kMaxDepth); |
| 220 | stack[depth++] = current; |
| 221 | current = {node, 0}; |
| 222 | } |
| 223 | |
| 224 | // Return the current leaf's key/value: |
| 225 | if (node.isMutable()) { |
| 226 | auto leaf = ((MutableLeaf*)node.asMutable()); |
| 227 | return {leaf->_key, leaf->_value}; |
| 228 | } else { |
| 229 | auto &leaf = node.asImmutable()->leaf; |
| 230 | return {leaf.keyString(), leaf.value()}; |
| 231 | } |
| 232 | } |
| 233 | }; |
| 234 | |
| 235 | } |
no test coverage detected