<s> import bisect <EOL> class NearestName : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ea_names ) : <EOL> self . update ( ea_names ) <EOL> def update ( self , ea_names ) : <EOL> """<STR_LIT>""" <EOL> self . _names = ea_names <EOL> self . _addrs = ea_names . keys ( ) <EOL> self . _addrs . sort ( ) <EOL> def find ( self , ea ) : <EOL> """<STR_LIT>""" <EOL> pos = bisect . bisect_left ( self . _addrs , ea ) <EOL> if pos >= len ( self . _addrs ) : <EOL> return None <EOL> if self . _addrs [ pos ] != ea : <EOL> pos -= <NUM_LIT:1> <EOL> if pos < <NUM_LIT:0> : <EOL> return None <EOL> return self [ pos ] <EOL> def _get_item ( self , index ) : <EOL> ea = self . _addrs [ index ] <EOL> return ( ea , self . _names [ ea ] , index ) <EOL> def __iter__ ( self ) : <EOL> return ( self . _get_item ( index ) for index in xrange ( <NUM_LIT:0> , len ( self . _addrs ) ) ) <EOL> def __getitem__ ( self , index ) : <EOL> """<STR_LIT>""" <EOL> if index > len ( self . _addrs ) : <EOL> raise StopIteration <EOL> return self . _get_item ( index ) </s>
