First resets the iterator to the first key/value pair.
()
| 1449 | |
| 1450 | // First resets the iterator to the first key/value pair. |
| 1451 | func (itr *MapIterator[K, V]) First() { |
| 1452 | // Exit immediately if the map is empty. |
| 1453 | if itr.m.root == nil { |
| 1454 | itr.depth = -1 |
| 1455 | return |
| 1456 | } |
| 1457 | |
| 1458 | // Initialize the stack to the left most element. |
| 1459 | itr.stack[0] = mapIteratorElem[K, V]{node: itr.m.root} |
| 1460 | itr.depth = 0 |
| 1461 | itr.first() |
| 1462 | } |
| 1463 | |
| 1464 | // Next returns the next key/value pair. Returns a nil key when no elements remain. |
| 1465 | func (itr *MapIterator[K, V]) Next() (key K, value V, ok bool) { |