2 * UCW Library -- Universal Heap Macros
4 * (c) 2001 Martin Mares <mj@ucw.cz>
5 * (c) 2005 Tomas Valla <tom@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
11 #define HEAP_BUBBLE_DOWN_J(heap,num,less,swap) \
17 if (less(heap[_j],heap[_l]) && (_l == num || less(heap[_j],heap[_l+1]))) \
19 if (_l != num && less(heap[_l+1],heap[_l])) \
25 #define HEAP_BUBBLE_UP_J(heap,num,less,swap) \
29 if (less(heap[_u], heap[_j])) \
35 #define HEAP_INIT(type,heap,num,less,swap) \
43 HEAP_BUBBLE_DOWN_J(heap,num,less,swap) \
48 #define HEAP_DELMIN(type,heap,num,less,swap) \
55 HEAP_BUBBLE_DOWN_J(heap,num,less,swap); \
58 #define HEAP_INSERT(type,heap,num,less,swap) \
63 HEAP_BUBBLE_UP_J(heap,num,less,swap); \
66 #define HEAP_INCREASE(type,heap,num,less,swap,pos) \
71 HEAP_BUBBLE_DOWN_J(heap,num,less,swap); \
74 #define HEAP_DELETE(type,heap,num,less,swap,pos) \
79 swap(heap,_j,num,x); \
81 if (less(heap[_j], heap[num+1])) \
82 HEAP_BUBBLE_UP_J(heap,num,less,swap) \
84 HEAP_BUBBLE_DOWN_J(heap,num,less,swap); \
87 /* Default swapping macro */
88 #define HEAP_SWAP(heap,a,b,t) (t=heap[a], heap[a]=heap[b], heap[b]=t)