Message414231
About runtime, you're right. I did a ballpark "OK, if there are N incoming values, the inner loop has to go around, for each one, looking for a NULL, across a vector of at most log2(N) entries. So N * log2(N)". But, in fact, it's highly skewed toward getting out early, and 2*N is an upper bound on the total number of inner loop iterations. Strongly related to that the total number of trailing 1 bits in the integers from 1 through N inclusive is N - N.bit_count().
For the rest, I'll only repeat that if this goes in, it should be as a new function. Special-casing, e.g., math.prod() is a Bad Idea. We can have no idea in advance whether the iterable is type-homogenous, or even whether the __mul__ methods the types involved implement are even intended to be associative.
functools.reduce() clearly documents strict "left to right" evaluation.
But a new treereduce() can do anything it feels like promising. |
|
Date |
User |
Action |
Args |
2022-03-01 01:32:22 | tim.peters | set | recipients:
+ tim.peters, rhettinger, mark.dickinson, benrg |
2022-03-01 01:32:22 | tim.peters | set | messageid: <1646098342.09.0.0194288553258.issue46868@roundup.psfhosted.org> |
2022-03-01 01:32:22 | tim.peters | link | issue46868 messages |
2022-03-01 01:32:21 | tim.peters | create | |
|