RE: [Python-Dev] {}.popitem() (was Re: {}.first[key,value,item] ...)

On Mon, 11 Dec 2000 15:22:55 -0500, "Tim Peters" <tim.one@home.com> wrote:
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
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!

[Tim]
[Moshe Zadka]
We don't need f at all unless we've already determined there's a collision at some index h. The i sequence is used to offset h (mod 2**N). An increment of 0 would waste time (h+0 == h, but we've already done a full compare on the h'th table entry and already determined it wasn't equal to what we're looking for). IOW, there are only 2**N-1 slots still of interest by the time f is needed.
But, Moshe! The proof would have been the most interesting part <wink>.

[Moshe Zadka]
[Tim]
But, Moshe! The proof would have been the most interesting part <wink>.
Turns out the proof would have been intensely interesting, as you can see by running the attached with and without the new line commented out. don't-ever-trust-a-theoretician<wink>-ly y'rs - tim N = 2 MAGIC_CONSTANT_DEPENDING_ON_N = 7 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 i = 1 for nothing in range(4): print i, i = f(i) print i

[Tim]
[Moshe Zadka]
We don't need f at all unless we've already determined there's a collision at some index h. The i sequence is used to offset h (mod 2**N). An increment of 0 would waste time (h+0 == h, but we've already done a full compare on the h'th table entry and already determined it wasn't equal to what we're looking for). IOW, there are only 2**N-1 slots still of interest by the time f is needed.
But, Moshe! The proof would have been the most interesting part <wink>.

[Moshe Zadka]
[Tim]
But, Moshe! The proof would have been the most interesting part <wink>.
Turns out the proof would have been intensely interesting, as you can see by running the attached with and without the new line commented out. don't-ever-trust-a-theoretician<wink>-ly y'rs - tim N = 2 MAGIC_CONSTANT_DEPENDING_ON_N = 7 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 i = 1 for nothing in range(4): print i, i = f(i) print i
participants (2)
-
Moshe Zadka
-
Tim Peters