Stephan Witt wrote:
> There is a cool algorithm to detect infinite loops without global state:
> 
> Use two pointers, start both somewhere at the same point.
> Increment the first by one, the second by two (if not hitting the end), until 
> one of the conditions is true:
> 1. Stop if one of the pointers reach the end -> no infinite loop.
> 2. Stop if the second pointer meets the first -> loop detected!
> 
> It's easy and fast.

there is a slight complication that we can branch in each document...  so
either we have towards beginning or send pointer messenger in all possible
branches...

pavel

Reply via email to