[Python-Dev] {}.popitem() (was Re: {}.first[key,value,item] ...)
Moshe Zadka
moshez@zadka.site.co.il
Tue, 12 Dec 2000 08:33:02 +0200 (IST)
On Mon, 11 Dec 2000 15:22:55 -0500, "Tim Peters" <tim.one@home.com> wrote:
> Well, anyone can play. When keys collide, what we need is a function f(i)
> such that repeating
> i = f(i)
> visits every int in (0, 2**N) exactly once before setting i back to its
> initial value, for a fixed N and where the first i is in (0, 2**N).
OK, maybe this is me being *real* stupid, but why? Why not [0, 2**n)?
Did 0 harm you in your childhood, and you're trying to get back? <0 wink>.
If we had an affine operation, instead of a linear one, we could have
[0, 2**n). I won't repeat the proof here but changing
> def f(i):
> i <<= 1
i^=1 # This is the line I added
> if i >= 2**N:
> i ^= MAGIC_CONSTANT_DEPENDING_ON_N
> return i
Makes you waltz all over [0, 2**n) if the original made you comple
(0, 2**n).
if-i'm-wrong-then-someone-should-shoot-me-to-save-me-the-embarrasment-ly y'rs,
Z.
--
Moshe Zadka <sig@zadka.site.co.il>
This is a signature anti-virus.
Please stop the spread of signature viruses!