#NEWLINE# def _string_hash( self , v ) : #NEWLINE# #INDENT# "A variable-length version of Python's builtin hash. Neat!" #NEWLINE# if ( v == '' ) : #NEWLINE# #INDENT# return 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# x = ( ord ( v [ 0 ] ) << 7 ) #NEWLINE# m = 1000003 #NEWLINE# mask = ( ( 2 ** self . hashbits ) - 1 ) #NEWLINE# for c in v : #NEWLINE# #INDENT# x = ( ( ( x * m ) ^ ord ( c ) ) & mask ) #NEWLINE# #UNINDENT# x ^= len ( v ) #NEWLINE# if ( x == ( - 1 ) ) : #NEWLINE# #INDENT# x = ( - 2 ) #NEWLINE# #UNINDENT# return x