]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow removal from the heap
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Apr 2016 21:04:14 +0000 (22:04 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Apr 2016 21:04:14 +0000 (22:04 +0100)
src/libutil/heap.c
src/libutil/heap.h

index ba1b44793b2fb9fcf28fa1477fd91b8bbd31d836..9bcfd4f1d4bb8110cdf704fdd202c8d33197070a 100644 (file)
@@ -138,7 +138,6 @@ rspamd_min_heap_update_elt (struct rspamd_min_heap *heap,
        g_assert (heap != NULL);
        g_assert (elt->idx > 0 && elt->idx <= heap->ar->len);
 
-
        oldpri = elt->pri;
        elt->pri = npri;
 
@@ -152,6 +151,26 @@ rspamd_min_heap_update_elt (struct rspamd_min_heap *heap,
        }
 }
 
+void
+rspamd_min_heap_remove_elt (struct rspamd_min_heap *heap,
+               struct rspamd_min_heap_elt *elt)
+{
+       struct rspamd_min_heap_elt *first;
+
+       g_assert (heap != NULL);
+       g_assert (elt->idx > 0 && elt->idx <= heap->ar->len);
+
+       first = g_ptr_array_index (heap->ar, 0);
+
+       if (elt != first) {
+               elt->pri = first->pri - 1;
+               rspamd_min_heap_swim (heap, elt);
+       }
+
+       /* Now the desired element is on the top of queue */
+       (void)rspamd_min_heap_pop (heap);
+}
+
 void
 rspamd_min_heap_destroy (struct rspamd_min_heap *heap)
 {
index 58a9a0c88353384130f6d1c1055fa24f916bd678..20e9209ce3cf146ca4653b787e4a51f1138be5a7 100644 (file)
@@ -62,6 +62,15 @@ struct rspamd_min_heap_elt* rspamd_min_heap_pop (struct rspamd_min_heap *heap);
 void rspamd_min_heap_update_elt (struct rspamd_min_heap *heap,
                struct rspamd_min_heap_elt *elt, guint npri);
 
+
+/**
+ * Removes element from the heap
+ * @param heap
+ * @param elt
+ */
+void rspamd_min_heap_remove_elt (struct rspamd_min_heap *heap,
+               struct rspamd_min_heap_elt *elt);
+
 /**
  * Destroys heap (elements are not destroyed themselves)
  * @param heap