how to allow integer overflow for calculating hash code of a string?

From: Haifeng Liu <liuhaifeng(at)live(dot)com>
To: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: how to allow integer overflow for calculating hash code of a string?
Date: 2012-09-20 08:55:46
Message-ID: BLU0-SMTP486A3A8F157C95DD76E23EB99A0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

I want to write a hash function which acts as String.hashCode() in java: hash = hash * 31 + s.charAt(i)... but I got integer out of range error. How can I avoid this? I saw java do not care overflow of int, it just make the result negative.

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Craig James 2012-09-20 14:34:29 Re: how to allow integer overflow for calculating hash code of a string?
Previous Message Craig Ringer 2012-09-20 02:28:36 Re: Postgres Cache usage