#include <UT_Algorithm.h>
Public Member Functions | |
| UT_CycleDetect () | |
| void | reset () |
| bool | detect (const T &tail) |
NOTE: In general, this won't detect cycles immediately and so your loop must be able to support extra iterations.
You might have as many as 3 times the number of iterations as your total path length.
For a more efficient cycle detector, we could use Floyd's cycle detection algorithm but then it would need to be given 2 iterators.
Example:
T walk; UT_CycleDetect<T> cycle; for (walk = first; walk && !cycle.detect(walk); walk = walk->next) { .... do stuff with walk .... }
Definition at line 82 of file UT_Algorithm.h.
| UT_CycleDetect< T >::UT_CycleDetect | ( | ) | [inline] |
Definition at line 85 of file UT_Algorithm.h.
| bool UT_CycleDetect< T >::detect | ( | const T & | tail | ) | [inline] |
Definition at line 96 of file UT_Algorithm.h.
| void UT_CycleDetect< T >::reset | ( | void | ) | [inline] |
Definition at line 90 of file UT_Algorithm.h.
1.5.9