VPR-7.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
heapsort.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void heapsort (int *sort_index, float *sort_values, int nelem, int start_index)
 

Function Documentation

void heapsort ( int *  sort_index,
float *  sort_values,
int  nelem,
int  start_index 
)

Definition at line 13 of file heapsort.c.

13  {
14 
15  /* This routine loads sort_index [1..nelem] with nelem values: the indices *
16  * of the sort_values [1..nelem] array that lead to sort_values[index] being *
17  * decreasing as one goes through sort_index. Sort_values is not changed. */
18 
19  int i;
20 
21  sort_index -= start_index;
22  sort_values -= start_index;
23 
24  /* Build a heap with the *smallest* element at the top. */
25 
26  for (i = 1; i <= nelem; i++)
27  add_to_sort_heap(sort_index, sort_values, i, i);
28 
29  /* Now pull items off the heap, smallest first. As the heap (in sort_index) *
30  * shrinks, I store the item pulled off (the smallest) in sort_index, *
31  * starting from the end. The heap and the stored smallest values never *
32  * overlap, so I get a nice sort-in-place. */
33 
34  for (i = nelem; i >= 1; i--)
35  sort_index[i] = get_top_of_heap_index(sort_index, sort_values, i,
36  start_index);
37 
38  sort_index += start_index;
39  sort_values += start_index;
40 }
static void add_to_sort_heap(int *heap, float *sort_values, int index, int heap_tail)
Definition: heapsort.c:42
static int get_top_of_heap_index(int *heap, float *sort_values, int heap_tail, int start_index)
Definition: heapsort.c:64

+ Here is the call graph for this function:

+ Here is the caller graph for this function: