Skip to content

Commit

Permalink
htab: support lookups for buckets with multiple entries
Browse files Browse the repository at this point in the history
Probes are represented by a quadruple naming scheme.  For easy lookup,
hashtables are kept based on each naming component.  When performing
lookups based on one of those hashtables, the head element was always
returned which is obviously wrong.

This patch introduced dt_htab_find() which provides for lookups using
a template entry and a secondary comparison function that is used to
evaluate the different entries in the bucket that match the template.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Nick Alcock <nick.alcock@oracle.com>
  • Loading branch information
kvanhees committed Feb 27, 2023
1 parent 5a76f6e commit 6821c4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libdtrace/dt_htab.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,21 @@ void *dt_htab_lookup(const dt_htab_t *htab, const void *entry)
return NULL;
}

/*
* Find an entry in the hashtable, using the provided callback function as a
* secondary comparison function to differentiate between entries in a bucket.
*/
void *dt_htab_find(const dt_htab_t *htab, const void *entry,
dt_htab_ecmp_fn *cmpf, void *arg)
{
void *ent = dt_htab_lookup(htab, entry);

while (ent != NULL && !cmpf(ent, arg))
ent = htab->ops->next(ent);

return ent;
}

/*
* Remove an entry from the hashtable. If we are deleting the last entry in a
* bucket, get rid of the bucket.
Expand Down
3 changes: 3 additions & 0 deletions libdtrace/dt_htab.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ extern dt_htab_t *dt_htab_create(struct dtrace_hdl *dtp, dt_htab_ops_t *ops);
extern void dt_htab_destroy(struct dtrace_hdl *dtp, dt_htab_t *htab);
extern int dt_htab_insert(dt_htab_t *htab, void *entry);
extern void *dt_htab_lookup(const dt_htab_t *htab, const void *entry);
typedef int dt_htab_ecmp_fn(const void *entry, void *arg);
extern void *dt_htab_find(const dt_htab_t *htab, const void *entry,
dt_htab_ecmp_fn *cmpf, void *arg);
extern size_t dt_htab_entries(const dt_htab_t *htab);
extern int dt_htab_delete(dt_htab_t *htab, void *entry);
extern void *dt_htab_next(const dt_htab_t *htab, dt_htab_next_t **it);
Expand Down

0 comments on commit 6821c4b

Please sign in to comment.