brandtbucher / automap

High-performance autoincremented integer-valued mappings. 🗺️

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AutoMap, in some scenarios, permits the same key to be added more than once.

flexatone opened this issue · comments

Not sure exactly when this scenario happens, but here is an example:

In [57]: a = automap.AutoMap(('a', 'b'))                                                  

In [60]: a |= ('a',)                                                                      
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-60-557ca4a6c5c0> in <module>
----> 1 a |= ('a',)

KeyError: 'a'

In [62]: a |= ('c',)                                                                      

In [63]: a |= ('c',)                                                                      

In [64]: a                                                                                
Out[64]: automap.AutoMap(['a', 'b', 'c', 'c'])

Nice catch! This was a very tricky one that exposed a much bigger bug in the table resizing logic.

Basically, when an update required a table resize, the old entries were incorrectly inserted back into their old slots, rather than expanding to the new table size.

This is fixed in 647002c.

0.0.3 is out with this fix.