* @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 */
| 207 | * @return the inserted object |
| 208 | */ |
| 209 | static 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 |
nothing calls this directly
no test coverage detected