Ryanitus wrote:
> I may have found a bug in the __setitem__ method of the maxdict class.
> 

Fixed--thanks for pointing it out.

Eric

> Since a dictionary is a mapping class, if an item is set that already
> exists, it overwrites the previous.  However, you are still appending that
> item to _killkeys regardless.
> 
> In the case where 2 items with the same key were added and later removed due
> to size constraints, the line in bold would throw an exception on the second
> call.
> 
> By checking for the key existance, you handle that situation gracefully. 
> The item can still be removed from _killkeys, since it's the next to go
> anyway.
> 
> Ryan
> 
> Original code (circa line 776):
> 
>         if len(self)>=self.maxsize:
>             del self[self._killkeys[0]]
>             del self._killkeys[0]
>         dict.__setitem__(self, k, v)
>         self._killkeys.append(k)
> 
> Possible solution:
> 
>         if len(self)>=self.maxsize:
>             if self.has_key(self._killkeys[0]):
>                 del self[self._killkeys[0]]
>             del self._killkeys[0]
>         dict.__setitem__(self, k, v)
>         self._killkeys.append(k)
> 
> 
> 


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to