<s> """<STR_LIT>""" <EOL> from rplibs . six . moves import range <EOL> class PointerSlotStorage ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , max_size ) : <EOL> self . _data = [ None ] * max_size <EOL> self . _max_index = <NUM_LIT:0> <EOL> self . _num_entries = <NUM_LIT:0> <EOL> def get_max_index ( self ) : <EOL> return self . _max_index <EOL> def get_num_entries ( self ) : <EOL> return self . _num_entries <EOL> def find_slot ( self ) : <EOL> for i , value in enumerate ( self . _data ) : <EOL> if not value : <EOL> return i <EOL> return - <NUM_LIT:1> <EOL> def find_consecutive_slots ( self , num_consecutive ) : <EOL> if num_consecutive == <NUM_LIT:1> : <EOL> return self . find_slot ( ) <EOL> for i in range ( len ( self . _data ) ) : <EOL> any_taken = False <EOL> for k in range ( num_consecutive ) : <EOL> if self . _data [ i + k ] : <EOL> any_taken = True <EOL> break <EOL> if not any_taken : <EOL> return i <EOL> return - <NUM_LIT:1> <EOL> def free_slot ( self , slot ) : <EOL> self . _data [ slot ] = None <EOL> self . _num_entries -= <NUM_LIT:1> <EOL> if slot == self . _max_index : <EOL> while self . _max_index >= <NUM_LIT:0> and not self . _data [ self . _max_index ] : <EOL> self . _max_index -= <NUM_LIT:1> <EOL> def free_consecutive_slots ( self , slot , num_consecutive ) : <EOL> for i in range ( num_consecutive ) : <EOL> self . free_slot ( slot + i ) <EOL> def reserve_slot ( self , slot , ptr ) : <EOL> self . _max_index = max ( self . _max_index , slot ) <EOL> self . _data [ slot ] = ptr <EOL> self . _num_entries += <NUM_LIT:1> <EOL> def begin ( self ) : <EOL> for i in range ( self . _max_index + <NUM_LIT:1> ) : <EOL> if self . _data [ i ] : <EOL> yield self . _data [ i ] <EOL> def end ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) </s>
