]> mj.ucw.cz Git - libucw.git/blobdiff - lib/heap.h
Added REV_COMPARE(x,y) which is equivalent to COMPARE(y,x), but it's
[libucw.git] / lib / heap.h
index 268cc2572cd8d3ad855464d7c8a6e2a5b41dead7..8404858e6a516d9f318e340c7b324012d7003545 100644 (file)
@@ -2,6 +2,9 @@
  *     Sherlock Library -- Universal Heap Macros
  *
  *     (c) 2001 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
 #define HEAP_BUBBLE_DOWN_J(heap,num,less,swap)                                         \
   do {                                                                                 \
     uns j, l, u;                                                                       \
     type x;                                                                            \
-    swap(heap,pos,num,x);                                                              \
-    num--;                                                                             \
     j = pos;                                                                           \
+    swap(heap,j,num,x);                                                                        \
+    num--;                                                                             \
     if (less(heap[j], heap[num+1]))                                                    \
       HEAP_BUBBLE_UP_J(heap,num,less,swap)                                             \
     else                                                                               \
       HEAP_BUBBLE_DOWN_J(heap,num,less,swap);                                          \
   } while(0)
+
+/* Default swapping macro */
+#define HEAP_SWAP(heap,a,b,t) (t=heap[a], heap[a]=heap[b], heap[b]=t)