<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -54,18 +54,26 @@ class StateMachine:
   def __init__(self, initial, states=[]):
     self.initial = initial
     self.states = states
+    # if the initial state isn't in the states that are passed in, add it
     if self.initial not in self.states:
       self.states.append(self.initial)
 
   def __call__(self, s):
-    states = set([self.initial])
+    '''evaluate a string against this state machine, return True or False'''
+    # start with the initial state
+    states = frozenset([self.initial])
+    # for each character in the string
     for c in s:
       if len(states) == 0:
+        # if we run out of states then there's no match
         return False
+      # find the next states
       new_states = set()
       for state in states:
-        new_states = new_states.union(state(c))
-      states = new_states
+        new_states.update(state(c))
+      states = frozenset(new_states)
+    # all of the characters are consumed
+    # if we're in a terminal (matching) state, then we've succeeded
     return len([s for s in states if s.match]) &gt; 0
 
   def __iter__(self):</diff>
      <filename>fsm.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>adbe4c8d73188b0496ab8084d1429a1f37562b76</id>
    </parent>
  </parents>
  <author>
    <name>Ian McKellar</name>
    <email>ian@mckellar.org</email>
  </author>
  <url>http://github.com/ianloic/llvm-fnmatch/commit/0377c3edc4d808d03698637a5e6481a4f18d4ba5</url>
  <id>0377c3edc4d808d03698637a5e6481a4f18d4ba5</id>
  <committed-date>2009-07-07T19:35:10-07:00</committed-date>
  <authored-date>2009-07-07T19:35:10-07:00</authored-date>
  <message>add docs, minor improvements to fsm.py</message>
  <tree>bbb960ad980c0f2aea327a39b5fd17d531aa8d79</tree>
  <committer>
    <name>Ian McKellar</name>
    <email>ian@mckellar.org</email>
  </committer>
</commit>
