Exemplo n.º 1
0
static INLINE void sanitize_cb(struct cso_hash *hash, enum cso_cache_type type,
                               int max_size, void *user_data)
{
   /* if we're approach the maximum size, remove fourth of the entries
    * otherwise every subsequent call will go through the same */
   int hash_size = cso_hash_size(hash);
   int max_entries = (max_size > hash_size) ? max_size : hash_size;
   int to_remove =  (max_size < max_entries) * max_entries/4;
   if (hash_size > max_size)
      to_remove += hash_size - max_size;
   while (to_remove) {
      /*remove elements until we're good */
      /*fixme: currently we pick the nodes to remove at random*/
      struct cso_hash_iter iter = cso_hash_first_node(hash);
      void  *cso = cso_hash_take(hash, cso_hash_iter_key(iter));
      delete_cso(cso, type);
      --to_remove;
   }
}
Exemplo n.º 2
0
/**
 * Remove all entries from the map, calling the delete callback for each.
 * \param user  passed to the delete callback as the last param.
 */
void
util_keymap_remove_all(struct keymap *map, void *user)
{
   struct cso_hash_iter iter;
   struct keymap_item *item;

   assert(map);
   if (!map)
      return;

   iter = cso_hash_first_node(map->cso);
   while (!cso_hash_iter_is_null(iter)) {
      item = (struct keymap_item *)
         cso_hash_take(map->cso, cso_hash_iter_key(iter));
      map->delete_func(map, item->key, item->value, user);
      FREE(item->key);
      FREE(item);
      iter = cso_hash_first_node(map->cso);
   }
}