This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients cool-RR, rhettinger, vstinner
Date 2011-03-31.21:58:24
SpamBayes Score 0.00017334557
Marked as misclassified No
Message-id <1301608705.05.0.512286241512.issue11733@psf.upfronthosting.co.za>
In-reply-to
Content
> It would be interesting to have Counter.elements_count() 
> if it has a complexity of O(1): if the collections 
> maintains a total (in a private attribute).

I agree that it would be interesting; however, it would be an implementation disaster.  We would have to override (and slow-down) every mutating method in order to maintain the invariant.  And as a dict subclass, any C module using PyDict_Setitem() would bypass those methods and still break the invariant no matter what we do.

The Counter tool was designed in an open fashion (a simple, fully exposed dictionary with a few handy methods for counting).  In that regard, it is much different and more flexible than a traditional Bag class that maintains its data privately.
History
Date User Action Args
2011-03-31 21:58:25rhettingersetrecipients: + rhettinger, vstinner, cool-RR
2011-03-31 21:58:25rhettingersetmessageid: <1301608705.05.0.512286241512.issue11733@psf.upfronthosting.co.za>
2011-03-31 21:58:24rhettingerlinkissue11733 messages
2011-03-31 21:58:24rhettingercreate