/* Hash table for fast access */
GHashTable *items_by_symbol;
GPtrArray *items_by_order;
+ GPtrArray *items_by_id;
rspamd_mempool_t *static_pool;
gdouble max_weight;
guint used_items;
}
if (item->type == SYMBOL_TYPE_VIRTUAL && item->parent != -1) {
- g_assert (item->parent < (gint)cache->items_by_order->len);
- parent = g_ptr_array_index (cache->items_by_order, item->parent);
+ g_assert (item->parent < (gint)cache->items_by_id->len);
+ parent = g_ptr_array_index (cache->items_by_id, item->parent);
if (parent->weight < item->weight) {
parent->weight = item->weight;
cache->used_items ++;
msg_debug ("used items: %d, added symbol: %s", cache->used_items, name);
rspamd_set_counter (item, 0);
+ g_ptr_array_add (cache->items_by_id, item);
g_ptr_array_add (cache->items_by_order, item);
if (name != NULL) {
g_hash_table_destroy (cache->items_by_symbol);
rspamd_mempool_delete (cache->static_pool);
-
+ g_ptr_array_free (cache->items_by_id, TRUE);
+ g_ptr_array_free (cache->items_by_order, TRUE);
g_slice_free1 (sizeof (*cache), cache);
}
}
cache->items_by_symbol = g_hash_table_new (rspamd_str_hash,
rspamd_str_equal);
cache->items_by_order = g_ptr_array_new ();
+ cache->items_by_id = g_ptr_array_new ();
cache->mtx = rspamd_mempool_get_mutex (cache->static_pool);
cache->reload_time = CACHE_RELOAD_TIME;
cache->total_freq = 1;
}
if (item->type == SYMBOL_TYPE_VIRTUAL && item->parent != -1) {
- g_assert (item->parent < (gint)cache->items_by_order->len);
- parent = g_ptr_array_index (cache->items_by_order, item->parent);
+ g_assert (item->parent < (gint)cache->items_by_id->len);
+ parent = g_ptr_array_index (cache->items_by_id, item->parent);
if (abs (parent->weight) < abs (item->weight)) {
parent->weight = item->weight;
"symbol", 0, false);
if (item->type == SYMBOL_TYPE_VIRTUAL && item->parent != -1) {
- g_assert (item->parent < (gint)cbd->cache->items_by_order->len);
- parent = g_ptr_array_index (cbd->cache->items_by_order,
+ g_assert (item->parent < (gint)cbd->cache->items_by_id->len);
+ parent = g_ptr_array_index (cbd->cache->items_by_id,
item->parent);
ucl_object_insert_key (obj, ucl_object_fromdouble (item->weight),
"weight", 0, false);
}
}
/* Sync virtual symbols */
- for (i = 0; i < cache->items_by_order->len; i ++) {
+ for (i = 0; i < cache->items_by_id->len; i ++) {
if (item->parent != -1) {
- parent = g_ptr_array_index (cache->items_by_order, item->parent);
+ parent = g_ptr_array_index (cache->items_by_id, item->parent);
item->avg_time = parent->avg_time;
item->avg_counter = parent->avg_counter;
}
/* For virtual symbols we also increase counter for parent */
if (item->parent != -1) {
- parent = g_ptr_array_index (cache->items_by_order, item->parent);
+ parent = g_ptr_array_index (cache->items_by_id, item->parent);
parent->frequency ++;
}
}