cctools
hash_cache.h
1/*
2Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3Copyright (C) 2022 The University of Notre Dame
4This software is distributed under the GNU General Public License.
5See the file COPYING for details.
6*/
7
8#ifndef HASH_CACHE_H
9#define HASH_CACHE_H
10
11#include "hash_table.h"
12
13/*
14A hash_cache is like a hash_table, with one key difference:
15Each item is inserted with a lifetime given in seconds.
16Once the lifetime has expired, the item is automatically
17deleted (using the given cleanup function) and the user
18will not see it again.
19*/
20
21
22typedef void (*hash_cache_cleanup_t) (void *value);
23
24struct hash_cache *hash_cache_create(int size, hash_func_t func, hash_cache_cleanup_t cleanup);
25void hash_cache_delete(struct hash_cache *cache);
26
27int hash_cache_insert(struct hash_cache *cache, const char *key, void *value, int lifetime);
28void *hash_cache_remove(struct hash_cache *cache, const char *key);
29void *hash_cache_lookup(struct hash_cache *cache, const char *key);
30
31void hash_cache_firstkey(struct hash_cache *cache);
32int hash_cache_nextkey(struct hash_cache *cache, char **key, void **item);
33
34#endif
A general purpose hash table.
unsigned(* hash_func_t)(const char *key)
The type signature for a hash function given to hash_table_create.
Definition hash_table.h:41