@@ -24,7 +24,9 @@ def ensure_hashable(x):
2424class SequenceLearner (BaseLearner ):
2525 def __init__ (self , function , sequence ):
2626 self .function = function
27- self ._to_do_seq = {ensure_hashable (x ) for x in sequence }
27+
28+ # We use a poor man's OrderedSet, a dict that points to None.
29+ self ._to_do_seq = {ensure_hashable (x ): None for x in sequence }
2830 self ._npoints = len (sequence )
2931 self .sequence = copy (sequence )
3032 self .data = {}
@@ -61,17 +63,17 @@ def loss(self, real=True):
6163
6264 def remove_unfinished (self ):
6365 for p in self .pending_points :
64- self ._to_do_seq . add ( p )
66+ self ._to_do_seq [ p ] = None
6567 self .pending_points = set ()
6668
6769 def tell (self , point , value ):
6870 self .data [point ] = value
6971 self .pending_points .discard (point )
70- self ._to_do_seq .discard (point )
72+ self ._to_do_seq .pop (point , None )
7173
7274 def tell_pending (self , point ):
7375 self .pending_points .add (point )
74- self ._to_do_seq .discard (point )
76+ self ._to_do_seq .pop (point , None )
7577
7678 def done (self ):
7779 return not self ._to_do_seq and not self .pending_points
0 commit comments