[Mesa-dev] [PATCH 148/133] util/hash_table: Pull the details of the FNV-a1 into helpers

Jason Ekstrand jason at jlekstrand.net
Tue Jan 6 17:11:39 PST 2015


On Tue, Jan 6, 2015 at 5:03 PM, Matt Turner <mattst88 at gmail.com> wrote:

> On Tue, Jan 6, 2015 at 4:34 PM, Jason Ekstrand <jason at jlekstrand.net>
> wrote:
> > This way the basics of the FNV-a1 hash can be reused to easily create
> other
> > hashing functions.
> >
> > Cc: Eric Anholt <eric at anholt.net>
>
> This didn't actually Cc him.
>

My e-mail says it did...


>
> > ---
> >  src/util/hash_table.c | 17 ++++-------------
> >  src/util/hash_table.h | 19 +++++++++++++++++++
> >  2 files changed, 23 insertions(+), 13 deletions(-)
> >
> > diff --git a/src/util/hash_table.c b/src/util/hash_table.c
> > index 920bdfd..ece72bc 100644
> > --- a/src/util/hash_table.c
> > +++ b/src/util/hash_table.c
> > @@ -396,27 +396,18 @@ _mesa_hash_table_random_entry(struct hash_table
> *ht,
> >  uint32_t
> >  _mesa_hash_data(const void *data, size_t size)
> >  {
> > -   uint32_t hash = 2166136261ul;
> > -   const uint8_t *bytes = data;
> > -
> > -   while (size-- != 0) {
> > -      hash ^= *bytes;
> > -      hash = hash * 0x01000193;
> > -      bytes++;
> > -   }
> > -
> > -   return hash;
> > +   return _mesa_FNV32_1a_accumulate_block(_mesa_FNV32_1a_offset_bias,
> > +                                          data, size);
> >  }
> >
> >  /** FNV-1a string hash implementation */
> >  uint32_t
> >  _mesa_hash_string(const char *key)
> >  {
> > -   uint32_t hash = 2166136261ul;
> > +   uint32_t hash = _mesa_FNV32_1a_offset_bias;
> >
> >     while (*key != 0) {
> > -      hash ^= *key;
> > -      hash = hash * 0x01000193;
> > +      hash = _mesa_FNV32_1a_accumulate(hash, *key);
> >        key++;
> >     }
> >
> > diff --git a/src/util/hash_table.h b/src/util/hash_table.h
> > index d6b6ebf..3d98cea 100644
> > --- a/src/util/hash_table.h
> > +++ b/src/util/hash_table.h
> > @@ -90,6 +90,25 @@ static inline uint32_t _mesa_hash_pointer(const void
> *pointer)
> >     return _mesa_hash_data(&pointer, sizeof(pointer));
> >  }
> >
> > +static const uint32_t _mesa_FNV32_1a_offset_bias = 2166136261u;
>
> I don't think you want this in the header.
>

Explain?  The whole point is to make the bits of FNV-1a re-usable by other
bits of mesa.  That requires them to have access to that constant.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150106/d17ce710/attachment.html>


More information about the mesa-dev mailing list