MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / LFUDA_insert

Function LFUDA_insert

libCacheSim/cache/eviction/LFUDA.c:209–232  ·  view source on GitHub ↗

* @brief insert an object into the cache, * update the hash table and cache metadata * this function assumes the cache has enough space * eviction should be * performed before calling this function * * @param cache * @param req * @return the inserted object */

Source from the content-addressed store, hash-verified

207 * @return the inserted object
208 */
209static cache_obj_t *LFUDA_insert(cache_t *cache, const request_t *req) {
210 LFUDA_params_t *params = (LFUDA_params_t *)(cache->eviction_params);
211 cache_obj_t *cache_obj = cache_insert_base(cache, req);
212 cache_obj->lfu.freq = params->min_freq + 1;
213
214 gpointer key = GSIZE_TO_POINTER(cache_obj->lfu.freq);
215 freq_node_t *new_node = g_hash_table_lookup(params->freq_map, key);
216 if (new_node == NULL) {
217 new_node = my_malloc_n(freq_node_t, 1);
218 memset(new_node, 0, sizeof(freq_node_t));
219 new_node->freq = cache_obj->lfu.freq;
220 g_hash_table_insert(params->freq_map, key, new_node);
221 params->max_freq = params->max_freq < cache_obj->lfu.freq
222 ? cache_obj->lfu.freq
223 : params->max_freq;
224 } else {
225 DEBUG_ASSERT(new_node->freq == cache_obj->lfu.freq);
226 }
227
228 append_obj_to_tail(&new_node->first_obj, &new_node->last_obj, cache_obj);
229 new_node->n_obj += 1;
230
231 return cache_obj;
232}
233
234/**
235 * @brief find the object to be evicted

Callers

nothing calls this directly

Calls 2

cache_insert_baseFunction · 0.85
append_obj_to_tailFunction · 0.85

Tested by

no test coverage detected