Exemplo n.º 1
0
static void 
taslacmite_min (gdsl_element_t* t, ulong k, gdsl_compare_func_t comp_f)
{
    /*
     * Traverse up the tree comparing and swapping minimum values.
     */
    gdsl_element_t v;
    v = t[k];
    
    while (k > INDEX_MAX () && comp_f (t[PARENT_MIN (k)], v) > 0) 
	{
	    t[ k ] = t[ PARENT_MIN (k) ];
	    k = PARENT_MIN (k);
	}
    
    t[k] = v;
}
Exemplo n.º 2
0
static ulong
taslactite_min (gdsl_element_t* t, ulong n, ulong k, gdsl_compare_func_t comp_f)
{
    ulong          j;
    gdsl_element_t v;
    k = MIN_NODE (k);

    v = t [ k ];

    while (k <= PARENT_MIN (MIN_NODE (n)))
	{
        int comp;

        comp = comp_f (v, t[ MAX_NODE (k) ]);

        if (comp > 0) 
	    {
		gdsl_element_t *temp = v;
		v = t[ MAX_NODE (k) ];
		t[ MAX_NODE (k) ] = temp;
	    }

        j = CHILD1_MIN (k);

        if (j < MIN_NODE (n) && comp_f ( t [ j ] , t [ CHILD2_MIN (k)  ]) > 0)
        {
            j = CHILD2_MIN (k);
        }

        if (comp_f (t [ j ], v) >= 0) 
        {
            break;
        }
	
	t [ k ] = t [ j ];
	
	k = j;
	}
    
    t [ k ] = v;
    
    if (k != n)
	{
	    fix (t, k, comp_f);
	}

    return k;
}
Exemplo n.º 3
0
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");
}