struct rspamd_symcache_item {
/* This block is likely shared */
- struct item_stat *st;
+ struct rspamd_symcache_item_stat *st;
guint64 last_count;
struct rspamd_counter_data *cd;
gchar *symbol;
- enum rspamd_symbol_type type;
+ gint type;
/* Callback data */
union {
} normal;
struct {
gint parent;
+ struct rspamd_symcache_item *parent_item;
} virtual;
} specific;
GPtrArray *container;
};
-struct item_stat {
- struct rspamd_counter_data time_counter;
- gdouble avg_time;
- gdouble weight;
- guint hits;
- guint64 total_hits;
- struct rspamd_counter_data frequency_counter;
- gdouble avg_frequency;
- gdouble stddev_frequency;
-};
-
struct rspamd_symcache {
/* Hash table for fast access */
GHashTable *items_by_symbol;
if (item != NULL) {
if (resolve_parent && item->is_virtual && !(item->type & SYMBOL_TYPE_GHOST)) {
- item = g_ptr_array_index (cache->items_by_id,
- item->specific.virtual.parent);
+ item =item->specific.virtual.parent_item;
}
return item;
rspamd_symcache_get_parent (struct rspamd_symcache *cache,
const gchar *symbol)
{
- struct rspamd_symcache_item *item;
+ struct rspamd_symcache_item *item, *parent;
g_assert (cache != NULL);
if (item != NULL) {
if (item->is_virtual && !(item->type & SYMBOL_TYPE_GHOST)) {
- item = g_ptr_array_index (cache->items_by_id,
- item->specific.virtual.parent);
+ parent = item->specific.virtual.parent_item;
+
+ if (!parent) {
+ item->specific.virtual.parent_item = g_ptr_array_index (cache->items_by_id,
+ item->specific.virtual.parent);
+ parent = item->specific.virtual.parent_item;
+ }
+
+ item = parent;
}
return item->symbol;
g_assert (item->specific.virtual.parent < (gint)cache->items_by_id->len);
parent = g_ptr_array_index (cache->items_by_id,
item->specific.virtual.parent);
+ item->specific.virtual.parent_item = parent;
if (parent->st->weight < item->st->weight) {
parent->st->weight = item->st->weight;
g_assert (item->specific.virtual.parent < (gint) cache->items_by_id->len);
parent = g_ptr_array_index (cache->items_by_id,
item->specific.virtual.parent);
+ item->specific.virtual.parent_item = parent;
if (fabs (parent->st->weight) < fabs (item->st->weight)) {
parent->st->weight = item->st->weight;
void
rspamd_symcache_foreach (struct rspamd_symcache *cache,
- void (*func) (gint, const gchar *, gint, gpointer),
+ void (*func) (struct rspamd_symcache_item *, gpointer),
gpointer ud)
{
struct rspamd_symcache_item *item;
while (g_hash_table_iter_next (&it, &k, &v)) {
item = (struct rspamd_symcache_item *)v;
- func (item->id, item->symbol, item->type, ud);
+ func (item, ud);
}
}
}
}
-enum rspamd_symbol_type
+gint
rspamd_symcache_item_flags (struct rspamd_symcache_item *item)
{
if (item) {
}
return 0;
+}
+
+const gchar*
+rspamd_symcache_item_name (struct rspamd_symcache_item *item)
+{
+ return item ? item->symbol : NULL;
+}
+
+const struct rspamd_symcache_item_stat *
+rspamd_symcache_item_stat (struct rspamd_symcache_item *item)
+{
+ return item ? item->st : NULL;
+}
+
+gboolean
+rspamd_symcache_item_is_enabled (struct rspamd_symcache_item *item)
+{
+ if (item) {
+ if (!item->enabled) {
+ return FALSE;
+ }
+
+ if (item->is_virtual && item->specific.virtual.parent_item != NULL) {
+ return rspamd_symcache_item_is_enabled (item->specific.virtual.parent_item);
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+struct rspamd_symcache_item * rspamd_symcache_item_get_parent (
+ struct rspamd_symcache_item *item)
+{
+ if (item && item->is_virtual && item->specific.virtual.parent_item != NULL) {
+ return item->specific.virtual.parent_item;
+ }
+
+ return NULL;
+}
+
+const GPtrArray*
+rspamd_symcache_item_get_deps (struct rspamd_symcache_item *item)
+{
+ struct rspamd_symcache_item *parent;
+
+ if (item) {
+ parent = rspamd_symcache_item_get_parent (item);
+
+ if (parent) {
+ item = parent;
+ }
+
+ return item->deps;
+ }
+
+ return NULL;
+}
+
+const GPtrArray*
+rspamd_symcache_item_get_rdeps (struct rspamd_symcache_item *item)
+{
+ struct rspamd_symcache_item *parent;
+
+ if (item) {
+ parent = rspamd_symcache_item_get_parent (item);
+
+ if (parent) {
+ item = parent;
+ }
+
+ return item->rdeps;
+ }
+
+ return NULL;
}
\ No newline at end of file
char data[];
};
+struct rspamd_symcache_item_stat {
+ struct rspamd_counter_data time_counter;
+ gdouble avg_time;
+ gdouble weight;
+ guint hits;
+ guint64 total_hits;
+ struct rspamd_counter_data frequency_counter;
+ gdouble avg_frequency;
+ gdouble stddev_frequency;
+};
+
/**
* Creates new cache structure
* @return
* @param ud
*/
void rspamd_symcache_foreach (struct rspamd_symcache *cache,
- void (*func) (gint /* id */, const gchar * /* name */,
- gint /* flags */, gpointer /* userdata */),
+ void (*func) (struct rspamd_symcache_item *item, gpointer /* userdata */),
gpointer ud);
/**
* @param item
* @return
*/
-enum rspamd_symbol_type rspamd_symcache_item_flags (struct rspamd_symcache_item *item);
+gint rspamd_symcache_item_flags (struct rspamd_symcache_item *item);
+/**
+ * Returns cache item name
+ * @param item
+ * @return
+ */
+const gchar* rspamd_symcache_item_name (struct rspamd_symcache_item *item);
+/**
+ * Returns the current item stat
+ * @param item
+ * @return
+ */
+const struct rspamd_symcache_item_stat *
+ rspamd_symcache_item_stat (struct rspamd_symcache_item *item);
+/**
+ * Returns if an item is enabled (for virutal it also means that parent should be enabled)
+ * @param item
+ * @return
+ */
+gboolean rspamd_symcache_item_is_enabled (struct rspamd_symcache_item *item);
+/**
+ * Returns parent for virtual symbols (or NULL)
+ * @param item
+ * @return
+ */
+struct rspamd_symcache_item * rspamd_symcache_item_get_parent (
+ struct rspamd_symcache_item *item);
+/**
+ * Returns direct deps for an element
+ * @param item
+ * @return array of struct rspamd_symcache_item *
+ */
+const GPtrArray* rspamd_symcache_item_get_deps (
+ struct rspamd_symcache_item *item);
+/**
+ * Returns direct reverse deps for an element
+ * @param item
+ * @return array of struct rspamd_symcache_item *
+ */
+const GPtrArray* rspamd_symcache_item_get_rdeps (
+ struct rspamd_symcache_item *item);
+
#ifdef __cplusplus
}