add sigar_cache_find function

This commit is contained in:
Doug MacEachern 2006-06-20 00:13:12 +00:00
parent 0aa428e669
commit 8f29dedf2d
2 changed files with 21 additions and 0 deletions

View File

@ -107,6 +107,9 @@ sigar_cache_t *sigar_cache_new(int size);
sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
sigar_uint64_t key);
sigar_cache_entry_t *sigar_cache_find(sigar_cache_t *table,
sigar_uint64_t key);
void sigar_cache_destroy(sigar_cache_t *table);
#endif /* SIGAR_UTIL_H */

View File

@ -85,6 +85,24 @@ static void sigar_cache_rehash(sigar_cache_t *table)
#define SIGAR_CACHE_IX(t, k) \
t->entries + (k % t->size)
sigar_cache_entry_t *sigar_cache_find(sigar_cache_t *table,
sigar_uint64_t key)
{
sigar_cache_entry_t *entry, **ptr;
for (ptr = SIGAR_CACHE_IX(table, key), entry = *ptr;
entry;
ptr = &entry->next, entry = *ptr)
{
if (entry->id == key) {
return entry;
}
}
return NULL;
}
/* create entry if it does not exist */
sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
sigar_uint64_t key)
{