Re: hashlittle(), hashbig(), hashword() and endianness

From: Alex Vinokur <alexvn(at)users(dot)sourceforge(dot)net>
To: pgsql-patches(at)postgresql(dot)org
Subject: Re: hashlittle(), hashbig(), hashword() and endianness
Date: 2007-11-16 09:19:13
Message-ID: daab8b06-7108-4043-84fd-7e6c1d6f9a51@l1g2000hsa.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

On Nov 15, 1:23 pm, hei(dot)(dot)(dot)(at)enterprisedb(dot)com (Heikki Linnakangas)
wrote:
> Alex Vinokurwrote:
> > On Nov 15, 10:40 am,Alex Vinokur<ale(dot)(dot)(dot)(at)users(dot)sourceforge(dot)net>
> > wrote:
> > [snip]
> >> I have some question concerning Bob Jenkins' functions
> >> hashword(uint32_t*, size_t), hashlittle(uint8_t*, size_t) and
> >> hashbig(uint8_t*, size_t) in lookup3.c.
>
> >> Let k1 by a key: uint8_t* k1; strlen(k1)%sizeof(uint32_t) == 0.
>
> >> 1. hashlittle(k1) produces the same value on Little-Endian and Big-
> >> Endian machines.
> >> Let hashlittle(k1) be == L1.
>
> >> 2. hashbig(k1) produces the same value on Little-Endian and Big-Endian
> >> machines.
> >> Let hashbig(k1) be == B1.
>
> >> L1 != B1
>
> >> 3. hashword((uint32_t*)k1) produces
> >> * L1 on LittleEndian machine and
> >> * B1 on BigEndian machine.
>
> > ===================================
> >> ---------------------
> >> The question is: is it possible to change hashword() to get
> >> * L1 on Little-Endian machine and
> >> * B1 on Big-Endian machine
> >> ?
>
> > Sorry, it should be as follows:
>
> > Is it possible to create two new hash functions on basis of
> > hashword():
> > i) hashword_little () that produces L1 on Little-Endian and Big-
> > Endian machines;
> > ii) hashword_big () that produces B1 on Little-Endian and Big-
> > Endian machines
> > ?
>
> Why?
>
[snip]

Suppose:
uint8_t chBuf[SIZE32 * 4]; // ((size_t)&chBuf[0] & 3) == 0

Function
hashlittle(chBuf, SIZE32 * 4, 0)
produces the same hashValue (let this value be L1) on little-endian
and big-endian machines. So, hashlittle() is endianness-indepent.

On other hand, function
hashword ((uint32_t)chBuf, SIZE32, 0)
produces hashValue == L1 on little-endian machine and hashValue != L1
on big-endian machine. So, hashword() is endianness-dependent.

I would like to use both hashlittle() and hashword() (or
hashword_little) on little-endian and big-endian machine and to get
identical hashValues.

Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Zoltan Boszormenyi 2007-11-16 10:26:55 Problem with pg_dump -n schemaname
Previous Message Tom Lane 2007-11-15 20:38:41 Re: [HACKERS] Why copy_relation_data only use wal whenWALarchivingis enabled