diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-08 22:04:14 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-08 22:04:14 +0100 |
commit | 6538f7ff7c62de807adca85e5db49d7cccab67d4 (patch) | |
tree | e1ed2cd06cc3dad40f886f9ff62b1c538d7a1c82 /src/libutil/heap.c | |
parent | 3789f106c11e9314ef29708d8156397b43387958 (diff) | |
download | rspamd-6538f7ff7c62de807adca85e5db49d7cccab67d4.tar.gz rspamd-6538f7ff7c62de807adca85e5db49d7cccab67d4.zip |
[Feature] Allow removal from the heap
Diffstat (limited to 'src/libutil/heap.c')
-rw-r--r-- | src/libutil/heap.c | 21 |
1 files changed, 20 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) { |