55from pixie .vm .numbers import Integer
66import pixie .vm .stdlib as proto
77from pixie .vm .code import extend , as_var
8- from rpython .rlib .rarithmetic import r_uint , intmask
8+ from rpython .rlib .rarithmetic import r_int , r_uint , intmask
99import rpython .rlib .jit as jit
1010import pixie .vm .rt as rt
1111
@@ -108,7 +108,7 @@ def assoc_inode(self, shift, hash_val, key, val, added_leaf):
108108
109109 if key_or_null is None :
110110 assert isinstance (val_or_node , INode )
111- n = val_or_node .assoc_inode (shift + 5 , hash_val , key , val , added_leaf )
111+ n = val_or_node .assoc_inode (shift + 5 , hash_val & MASK_32 , key , val , added_leaf )
112112 if n is val_or_node :
113113 return self
114114 return BitmapIndexedNode (None , self ._bitmap , clone_and_set (self ._array , 2 * idx + 1 , n ))
@@ -226,17 +226,17 @@ def assoc_inode(self, shift, hash_val, key, val, added_leaf):
226226 return self
227227 return ArrayNode (None , self ._cnt , clone_and_set (self ._array , idx , n ))
228228
229- def without_inode (self , shift , hash , key ):
230- idx = mask (hash , shift )
229+ def without_inode (self , shift , hash_val , key ):
230+ idx = r_uint ( mask (hash_val , shift ) )
231231 node = self ._array [idx ]
232232 if node is None :
233233 return self
234- n = node .without_inode (shift + 5 , hash , key )
234+ n = node .without_inode (shift + 5 , hash_val , key )
235235 if n is node :
236236 return self
237237 if n is None :
238238 if self ._cnt <= 8 : # shrink
239- return self .pack (None , idx )
239+ return self .pack (idx )
240240 return ArrayNode (None , self ._cnt - 1 , clone_and_set (self ._array , idx , n ))
241241 else :
242242 return ArrayNode (None , self ._cnt , clone_and_set (self ._array , idx , n ))
@@ -250,7 +250,7 @@ def pack(self, idx):
250250 while i < idx :
251251 if self ._array [i ] is not None :
252252 new_array [j ] = self ._array [i ]
253- bitmap |= 1 << i
253+ bitmap |= r_uint ( 1 ) << i
254254 j += 2
255255
256256 i += 1
@@ -259,7 +259,7 @@ def pack(self, idx):
259259 while i < len (self ._array ):
260260 if self ._array [i ] is not None :
261261 new_array [j ] = self ._array [i ]
262- bitmap |= 1 << i
262+ bitmap |= r_uint ( 1 ) << i
263263 j += 2
264264
265265 i += 1
@@ -291,7 +291,22 @@ def __init__(self, edit, hash, array):
291291 self ._array = array
292292
293293 def assoc_inode (self , shift , hash_val , key , val , added_leaf ):
294- assert False
294+ if hash_val == self ._hash :
295+ count = len (self ._array )
296+ idx = self .find_index (key )
297+ if idx != - 1 :
298+ if self ._array [idx + 1 ] == val :
299+ return self ;
300+ return HashCollisionNode (None , hash_val , clone_and_set (self ._array , r_uint (idx + 1 ), val ))
301+
302+ new_array = [None ] * (count + 2 )
303+ list_copy (self ._array , 0 , new_array , 0 , count )
304+ new_array [count ] = key
305+ added_leaf ._val = added_leaf
306+ new_array [count + 1 ] = val
307+ return HashCollisionNode (self ._edit , self ._hash , new_array )
308+ return BitmapIndexedNode (None , bitpos (self ._hash , shift ), [None , self ]) \
309+ .assoc_inode (shift , hash_val , key , val , added_leaf )
295310
296311 def find (self , shift , hash_val , key , not_found ):
297312 for x in range (0 , len (self ._array ), 2 ):
@@ -314,29 +329,29 @@ def reduce_inode(self, f, init):
314329 return init
315330
316331 def find_index (self , key ):
317- i = 0
332+ i = r_int ( 0 )
318333 while i < len (self ._array ):
319334 if rt .eq (key , self ._array [i ]):
320335 return i
321336
322337 i += 2
323338
324- return - 1
339+ return r_int ( - 1 )
325340
326- def without (self , shift , hash , key ):
341+ def without_inode (self , shift , hash , key ):
327342 idx = self .find_index (key )
328343 if idx == - 1 :
329344 return self
330345
331346 if len (self ._array ) == 1 :
332347 return None
333348
334- return HashCollisionNode (None , self ._hash , remove_pair (self ._array , idx / 2 ))
349+ return HashCollisionNode (None , self ._hash , remove_pair (self ._array , r_uint ( idx ) / 2 ))
335350
336351
337352
338353def create_node (shift , key1 , val1 , key2hash , key2 , val2 ):
339- key1hash = rt .hash (key1 )
354+ key1hash = rt .hash (key1 ) & MASK_32
340355 if key1hash == key2hash :
341356 return HashCollisionNode (None , key1hash , [key1 , val1 , key2 , val2 ])
342357 added_leaf = Box ()
0 commit comments