Message132712
> 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. |
|
Date |
User |
Action |
Args |
2011-03-31 21:58:25 | rhettinger | set | recipients:
+ rhettinger, vstinner, cool-RR |
2011-03-31 21:58:25 | rhettinger | set | messageid: <1301608705.05.0.512286241512.issue11733@psf.upfronthosting.co.za> |
2011-03-31 21:58:24 | rhettinger | link | issue11733 messages |
2011-03-31 21:58:24 | rhettinger | create | |
|