[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: hash locate_matching_entry()
From: |
Jason Stover |
Subject: |
Re: hash locate_matching_entry() |
Date: |
Wed, 8 Oct 2008 10:36:47 -0400 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
On Wed, Oct 08, 2008 at 10:25:19AM -0400, Jason Stover wrote:
> I'm having some trouble getting a matching entry in my
> hash table. It looks like the problem is here:
>
> /* Locates an entry matching TARGET. Returns the index for the
> entry, if found, or the index of an empty entry that indicates
> where TARGET should go, otherwise. */
> static inline unsigned
> locate_matching_entry (struct hsh_table *h, const void *target)
> {
> unsigned i = h->hash (target, h->aux);
>
> assert (h->hash_ordered);
> for (;;)
> {
> void *entry;
> i &= h->size - 1;
> entry = h->entries[i];
> if (entry == NULL || !h->compare (entry, target, h->aux))
> return i;
> i--;
> }
> }
>
> In my code, h->compare (entry, target, h->aux) returns 1 when
> entry and target match. So I would think locate_matching_entry()
> should return i, but it doesn't because of the !h->compare (...).
> Should this line be:
>
> if (entry == NULL || h->compare (entry, target, h->aux))
John just clarified over IRC that the return value here is supposed to be
strcmp-ish: 0 for a match.
So disregard.
-Jason