Go to the source code of this file.
Functions | |
struct translate_cache * | translate_cache_create (void) |
void | translate_cache_destroy (struct translate_cache *cache) |
struct translate * | translate_cache_find (struct translate_cache *cache, struct translate_key *key) |
Will try to find a translate structure matched by the given key. |
struct translate_cache* translate_cache_create | ( | void | ) | [read] |
Definition at line 40 of file translate_cache.c.
References cso_hash_create(), translate_cache::hash, and MALLOC_STRUCT.
00041 { 00042 struct translate_cache *cache = MALLOC_STRUCT(translate_cache); 00043 cache->hash = cso_hash_create(); 00044 return cache; 00045 }
void translate_cache_destroy | ( | struct translate_cache * | cache | ) |
Definition at line 61 of file translate_cache.c.
References cso_hash_delete(), delete_translates(), FREE, and translate_cache::hash.
00062 { 00063 delete_translates(cache); 00064 cso_hash_delete(cache->hash); 00065 FREE(cache); 00066 }
struct translate* translate_cache_find | ( | struct translate_cache * | cache, | |
struct translate_key * | key | |||
) | [read] |
Will try to find a translate structure matched by the given key.
If such a structure doesn't exist in the cache the function will automatically create it, insert it in the cache and return the created version.
Definition at line 86 of file translate_cache.c.
References create_key(), cso_hash_find_data_from_template(), cso_hash_insert(), translate_cache::hash, hash_key(), and translate_create().
00088 { 00089 unsigned hash_key = create_key(key); 00090 struct translate *translate = (struct translate*) 00091 cso_hash_find_data_from_template(cache->hash, 00092 hash_key, 00093 key, sizeof(*key)); 00094 00095 if (!translate) { 00096 /* create/insert */ 00097 translate = translate_create(key); 00098 cso_hash_insert(cache->hash, hash_key, translate); 00099 } 00100 00101 return translate; 00102 }