+static void heap_dump_item( HEAP h, int i, int level) {
+ double cur,tot;
+ if (i>h->heapnum)
+ return;
+ (void)rset_pos(h->heap[i]->rset,h->heap[i]->fd, &cur, &tot);
+ logf(LOG_LOG," %d %*s i=%p buf=%p %0.1f/%0.1f",i, level, "",
+ &(h->heap[i]), h->heap[i]->buf, cur,tot );
+ heap_dump_item(h, 2*i, level+1);
+ heap_dump_item(h, 2*i+1, level+1);
+}
+static void heap_dump( HEAP h,char *msg) {
+ logf(LOG_LOG, "heap dump: %s num=%d max=%d",msg, h->heapnum, h->heapmax);
+ heap_dump_item(h,1,1);
+}
+#endif
+
+static void heap_swap (HEAP h, int x, int y)