I suggest the creation of additional methods for hash objects which provide the capability to first "position" a pointer in the search tree (e.g. hash.pos_key()), even if the key is not found, and then find the next key in the sorting sequence (hash.next_key()). The second method should have an option to search "up" or "down", the default being "up".
The first method will always return a zero, while the second method will return a non-zero return code if the beginning (while searching "down") or the end (while searching "up") of the hash has been reached. Multiple entries for a given key should be treated as one.