<s> from . lookuptree import LookupTree <EOL> from itertools import islice <EOL> class ImmutableVector ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , initvalues = None ) : <EOL> if initvalues is None : initvalues = [ ] <EOL> self . tree = LookupTree ( initvalues ) <EOL> self . _length = len ( initvalues ) <EOL> def assoc ( self , index , value ) : <EOL> '''<STR_LIT>''' <EOL> newvec = ImmutableVector ( ) <EOL> newvec . tree = self . tree . assoc ( index , value ) <EOL> if index >= self . _length : <EOL> newvec . _length = index + <NUM_LIT:1> <EOL> else : <EOL> newvec . _length = self . _length <EOL> return newvec <EOL> def concat ( self , tailvec ) : <EOL> '''<STR_LIT>''' <EOL> newvec = ImmutableVector ( ) <EOL> vallist = [ ( i + self . _length , tailvec [ i ] ) for i in range ( <NUM_LIT:0> , tailvec . _length ) ] <EOL> newvec . tree = self . tree . multi_assoc ( vallist ) <EOL> newvec . _length = self . _length + tailvec . _length <EOL> return newvec <EOL> def pop ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . _length == <NUM_LIT:0> : <EOL> raise IndexError ( ) <EOL> newvec = ImmutableVector ( ) <EOL> newvec . tree = self . tree . remove ( self . _length - <NUM_LIT:1> ) <EOL> newvec . _length = self . _length - <NUM_LIT:1> <EOL> return newvec <EOL> def conj ( self , value ) : <EOL> '''<STR_LIT>''' <EOL> return self . assoc ( self . _length , value ) <EOL> def _get ( self , index ) : <EOL> if index >= self . _length : <EOL> raise IndexError <EOL> return self . tree [ index ] <EOL> def _slice ( self , slc ) : <EOL> lst = [ val for val in islice ( self , slc . start , slc . stop , slc . step ) ] <EOL> return ImmutableVector ( lst ) <EOL> def __add__ ( self , other ) : <EOL> return self . concat ( other ) <EOL> def __iter__ ( self ) : <EOL> for i in range ( <NUM_LIT:0> , self . _length ) : <EOL> yield self [ i ] <EOL> def __len__ ( self ) : <EOL> return self . _length <EOL> def __getitem__ ( self , index ) : <EOL> if isinstance ( index , slice ) : <EOL> return self . _slice ( index ) <EOL> return self . _get ( index ) <EOL> def __str__ ( self ) : <EOL> return str ( list ( self ) ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' + str ( self ) + '<STR_LIT:)>' <EOL> def __contains__ ( self , item ) : <EOL> for thing in self : <EOL> if thing == item : <EOL> return True <EOL> return False <EOL> def __eq__ ( self , other ) : <EOL> if other is None : <EOL> return False <EOL> if not hasattr ( other , '<STR_LIT>' ) : <EOL> return False <EOL> if len ( self ) != len ( other ) : <EOL> return False <EOL> for i in range ( len ( self ) ) : <EOL> if self [ i ] != other [ i ] : <EOL> return False <EOL> return True <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) </s>
