Message132712
| 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: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 |
|