Allows successively iterating over ancestor paths in O(n) complexity and with no dynamic memory allocations.