#NEWLINE# def put( self , key , val ) : #NEWLINE# #INDENT# 'Inserts an item into the tree, and then splays\n        the value all the way back up to the root (if applicable).' #NEWLINE# root = self . root #NEWLINE# parent = None #NEWLINE# while root : #NEWLINE# #INDENT# parent = root #NEWLINE# if ( root . key == key ) : #NEWLINE# #INDENT# root = root . right_child #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# root = root . left_child #NEWLINE# #UNINDENT# #UNINDENT# root = SplayNode ( key , val ) #NEWLINE# root . parent = parent #NEWLINE# if ( not parent ) : #NEWLINE# #INDENT# self . root = root #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( parent . key == root . key ) : #NEWLINE# #INDENT# parent . right_child = root #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# parent . left_child = root #NEWLINE# #UNINDENT# #UNINDENT# self . splay ( root ) #NEWLINE# self . nodes += 1