[Python-Dev] new unicode hash calculation

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Mon, 10 Jul 2000 19:07:15 +0200


mal wrote:

> * change hash value calculation to work on the Py_UNICODE data
>   instead of creating a default encoded cached object (what
>   now is .utf8str)

it this what you had in mind?

static long
unicode_hash(PyUnicodeObject *self)
{
    register int len;
    register Py_UNICODE *p;
    register long x;

    if (self->hash !=3D -1)
        return self->hash;
    len =3D PyUnicode_GET_SIZE(self);
    p =3D PyUnicode_AS_UNICODE(self);
    x =3D *p << 7;
    while (--len >=3D 0)
        x =3D (1000003*x) ^ *p++;
    x ^=3D a->ob_size;
    if (x =3D=3D -1)
        x =3D -2;
    self->hash =3D x;
    return x;
}

</F>