From: Pavel Charvat Date: Wed, 10 Dec 2008 12:09:51 +0000 (+0100) Subject: Libucw: Implemented HEAP_DECREASE. Fixed description of HEAP_INSERT. X-Git-Tag: holmes-import~118^2~11 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=1158507becaff6103931442d141fc9adcdf9b8e7;p=libucw.git Libucw: Implemented HEAP_DECREASE. Fixed description of HEAP_INSERT. --- diff --git a/ucw/heap.h b/ucw/heap.h index d8ef8d5c..e0a33b02 100644 --- a/ucw/heap.h +++ b/ucw/heap.h @@ -98,7 +98,7 @@ } while(0) /** - * Insert `heap[num + 1]` in `O(log(n))` time. + * Insert `heap[num]` in `O(log(n))` time. The value of @num must be increased before. **/ #define HEAP_INSERT(type,heap,num,less,swap) \ do { \ @@ -121,6 +121,19 @@ HEAP_BUBBLE_DOWN_J(heap,num,less,swap); \ } while(0) +/** + * If you need to decrease the value of `heap[pos]`, just do it and then call this macro to rebuild the heap. + * Only `heap[pos]` can be changed, the rest of the array must form a valid heap. + * The time complexity is `O(log(n))`. + **/ +#define HEAP_DECREASE(type,heap,num,less,swap,pos) \ + do { \ + uns _j, _u; \ + type x; \ + _j = pos; \ + HEAP_BUBBLE_UP_J(heap,num,less,swap); \ + } while(0) + /** * Delete `heap[pos]` in `O(log(n))` time. **/