static void taslacmite_max (gdsl_element_t* t, ulong k, gdsl_compare_func_t comp_f) { /* * Traverse up the tree comparing and swapping maximum values. */ gdsl_element_t v; v = t[k]; while (k > INDEX_MAX () && comp_f (t[PARENT_MAX (k)], v) < 0) { t[ k ] = t[ PARENT_MAX (k) ]; k = PARENT_MAX (k); } t[k] = v; }
static ulong taslactite_max (gdsl_element_t* t, ulong n, ulong k, gdsl_compare_func_t comp_f) { ulong j; gdsl_element_t v; k = MAX_NODE (k); v = t [ k ]; while (k <= PARENT_MAX (MAX_NODE (n))) { if (comp_f (t[ MIN_NODE(k) ], v) > 0) { gdsl_element_t *temp = v; v = t[MIN_NODE (k)]; t[MIN_NODE (k)] = temp; } j = CHILD1_MAX (k); if (j < MAX_NODE (n) && comp_f (t [ j ], t [ CHILD2_MAX (k) ]) < 0) { j = CHILD2_MAX (k); } if (comp_f (t [ j ], v) <= 0) { break; } t [ k ] = t [ j ]; k = j; } t [ k ] = v; fix (t, k-1, comp_f); return k; }
static void check_integrity (const gdsl_interval_heap_t heap) { int i, j; for (i = 1; i <= heap->card; i++) { if (i % 2 == 0) { int comp = heap->comp_f (heap->nodes[ LAST_INDEX (i-1) ], heap->nodes[ LAST_INDEX (i) ]); //printf("comp %d\n", comp); assert (comp <= 0); } if (LAST_INDEX (i) > INDEX_MAX ()) { int comp1 = heap->comp_f (heap->nodes[ LAST_INDEX (i) ], heap->nodes[ PARENT_MIN (LAST_INDEX (i)) ]); int comp2 = heap->comp_f (heap->nodes[ LAST_INDEX (i) ], heap->nodes[ PARENT_MAX (LAST_INDEX (i)) ]); //printf("LAST_INDEX(i): %lu PARENT_MIN: %lu\n", LAST_INDEX(i), PARENT_MIN( LAST_INDEX(i) )); //printf("LAST_INDEX(i): %lu PARENT_MAX: %lu\n", LAST_INDEX(i), PARENT_MAX( LAST_INDEX(i) )); if (comp1 < 0) { int li = LAST_INDEX (i); int pi = PARENT_MIN (li); fprintf (stderr, "min child t[%d]: %d parent t[%d]: %d\n", li, vti (heap->nodes[li]), pi, vti (heap->nodes[pi])); raw_dump (heap); } if (comp2 > 0) { int li = LAST_INDEX (i); int pi = PARENT_MAX (li); fprintf (stderr, "max child t[%d]: %d parent t[%d]: %d\n", li, vti (heap->nodes[li]), pi, vti (heap->nodes[pi])); raw_dump (heap); } assert (comp1 >= 0); assert (comp2 <= 0); } for (j = i+ 1; j <= heap->card; j++) { if (heap->nodes[ LAST_INDEX(i) ] == heap->nodes[ LAST_INDEX(j) ]) { fprintf(stderr, "IDENTICAL VALUES: %d %d\n", i, j); // N.B. I don't want any exit in my code! :) // exit (1); return 1; // I prefer a simple return (N. D.) } assert (heap->nodes[ LAST_INDEX (i) ] != heap->nodes[ LAST_INDEX (j) ]); } } //printf("passed integrity check\n"); }