Question to Cache::Memcached

Dave Evans memcached-list-20040309@djce.org.uk
Tue, 08 Jun 2004 19:21:57 +0100


This is a multi-part message in MIME format.
--------------090009000100050904050700
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Brad Fitzpatrick wrote:
> Whoa, good bug!
> 
> I guess I assumed Perl ints would wrap around, not get magically upcast to
> some float/bigint type, or whatever's going on.
> 
> Can you change it to this:
> 
>  $hash = ($hash*33 + ord($_)) % (2 ** 31);
> 
> That should work, right?  *scratches head*

You may prefer "use integer;" instead - I think it's what you want, and
it will be much more efficient.  Under this pragma,

"In addition, the range of
operands and results is restricted to that of familiar two's complement
integers, i.e., -(2**31) .. (2**31-1) on 32-bit architectures, and
-(2**63) .. (2**63-1) on 64-bit architectures."

Patch attached (but I haven't properly tested this; it's just what looks
to me like it might work).

-- 
Dave

PGP key: http://rudolf.org.uk/pgpkey

--------------090009000100050904050700
Content-Type: text/plain;
 name="use-integer.patch"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="use-integer.patch"

ZGlmZiAtdXIgb3JpZy9NZW1jYWNoZWQucG0gQ2FjaGUtTWVtY2FjaGVkLTEu
MTMvTWVtY2FjaGVkLnBtCi0tLSBvcmlnL01lbWNhY2hlZC5wbQkyMDA0LTA1
LTMwIDIyOjA4OjA1LjAwMDAwMDAwMCArMDEwMAorKysgQ2FjaGUtTWVtY2Fj
aGVkLTEuMTMvTWVtY2FjaGVkLnBtCTIwMDQtMDYtMDggMTk6MTk6MDEuMDAw
MDAwMDAwICswMTAwCkBAIC0yMTMsNiArMjEzLDcgQEAKIH0KIAogc3ViIGdl
dF9zb2NrIHsgIyAoa2V5KQorICAgIHVzZSBpbnRlZ2VyOwogICAgIG15IENh
Y2hlOjpNZW1jYWNoZWQgJHNlbGYgPSBzaGlmdDsKICAgICBteSAoJGtleSkg
PSBAXzsKICAgICByZXR1cm4gc29ja190b19ob3N0KCRzZWxmLT57J19zaW5n
bGVfc29jayd9KSBpZiAkc2VsZi0+eydfc2luZ2xlX3NvY2snfTsKQEAgLTcx
MSw2ICs3MTIsNyBAQAogfQogCiBzdWIgX2hhc2hmdW5jIHsKKyAgICB1c2Ug
aW50ZWdlcjsKICAgICBteSAkaGFzaCA9IDA7CiAgICAgZm9yZWFjaCAoc3Bs
aXQgLy8sIHNoaWZ0KSB7CiAgICAgICAgICRoYXNoID0gJGhhc2gqMzMgKyBv
cmQoJF8pOwo=

--------------090009000100050904050700--