Add check for circular replacement patterns

Convert replacement patterns into a graph and do a topological sort to
find circular replacement patterns.
Fix removing items from graph

The new method is more Pythonic and works.
Merge pull request #3 from Hexadite/pattern_loop_check

Pattern loop check