aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-08 22:04:14 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-08 22:04:14 +0100
commit6538f7ff7c62de807adca85e5db49d7cccab67d4 (patch)
treee1ed2cd06cc3dad40f886f9ff62b1c538d7a1c82
parent3789f106c11e9314ef29708d8156397b43387958 (diff)
downloadrspamd-6538f7ff7c62de807adca85e5db49d7cccab67d4.tar.gz
rspamd-6538f7ff7c62de807adca85e5db49d7cccab67d4.zip
[Feature] Allow removal from the heap
-rw-r--r--src/libutil/heap.c21
-rw-r--r--src/libutil/heap.h9
2 files changed, 29 insertions, 1 deletions
diff --git a/src/libutil/heap.c b/src/libutil/heap.c
index ba1b44793..9bcfd4f1d 100644
--- a/src/libutil/heap.c
+++ b/src/libutil/heap.c
@@ -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;
@@ -153,6 +152,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)
{
if (heap) {
diff --git a/src/libutil/heap.h b/src/libutil/heap.h
index 58a9a0c88..20e9209ce 100644
--- a/src/libutil/heap.h
+++ b/src/libutil/heap.h
@@ -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