Serhiy Storchaka added the comment:

The OrderedCounter recipe doesn't support well multiset operations, because the 
result type is hardcoded to Counter. The order is already scrambled. update() 
and substract() don't work well with overloaded __missing__().

Proposed implementations of __add__ and __or__ simplify the code. If you don't 
want that overloaded inplace operation affect non-inplace operations (I 
consider this rather as a benefit), Counter.__iadd__(result, other) can be used 
instead of result += other.

Optimized __neg__ just contains inlined substraction (note that current 
implementation of __neg__ and __pos__ violate the open-closed-principle), with 
removed no-op code.

My second step would be to add C implementation of _keep_positive(), because 
this function is used in a number of multiset methods. It could be more 
efficient and preserve the order.

In any case thank you for spending your time Raymond.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23509>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to