benoitbryon/wardrobe — pull request #7 by benoitbryon (2012-07-22 10:53:51+00:00)
Title: Implementation: use a dict and a diff history instead of several dict layers

At commit 9f5c76caf6f67fe956c0343a3b99ad9a9af5a562, implementation uses a stack of dict objects.
It seems to have some pitfalls:

* The __getitem__() method has to browse layers until it finds the requested key. If there are many layers, it could take long.
* The __iter__(), iterkeys(), itervalues() and iteritems() methods have to build a list of keys to figure out which keys are still valid or which ones have already been yielded. That may consume memory on instances with many layers or many items.
* Implementation of viewitems(), viewvalues() or viewkeys() is not simple.

This pull request proposes another implementation:

* have a _dict member, which is a standard dict and contains the current state.
* many methods are proxies to the _dict property. See __iter__(), iterkeys(), viewitems(), viewvalues()... So they are simply implemented and efficient (relies on standard dict's implementation).
* a diff history is maintained methods involving changes, such as push(), pop(), __setitem__ or __delitem__...

Also refs #3 (but not #6).