inc/quickHeap.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  quickHeap

Functions

quickHeapnewQuickHeap (int initSize, int(*compare)(const void *elem1, const void *elem2))
void freeQuickHeap (struct quickHeap **pH)
void addToQuickHeap (struct quickHeap *h, void *elem)
void quickHeapTopChanged (struct quickHeap *h)
boolean quickHeapEmpty (struct quickHeap *h)
boolean removeFromQuickHeapByElem (struct quickHeap *h, void *elem)
void * peekQuickHeapTop (struct quickHeap *h)
void * removeQuickHeapTop (struct quickHeap *h)


Function Documentation

void addToQuickHeap ( struct quickHeap h,
void *  elem 
)

Definition at line 66 of file quickHeap.c.

References quickHeap::compareFunc, expandQuickHeap(), quickHeap::heap, quickHeap::heapCount, and quickHeap::heapMax.

00068 {
00069 int n, p;   /* node, parent */
00070 if (h->heapCount >= h->heapMax)
00071     expandQuickHeap(h);
00072 /* preserve heap property as it grows */
00073 n = h->heapCount;
00074 h->heap[h->heapCount++] = elem;
00075 p = (n-1)/2;
00076 while (n > 0 && h->compareFunc(h->heap[p], h->heap[n]) < 0)
00077     {
00078     void *temp = h->heap[p];
00079     h->heap[p] = h->heap[n];
00080     h->heap[n] = temp;
00081     n = p;
00082     p = (n-1)/2;
00083     }
00084 }

Here is the call graph for this function:

void freeQuickHeap ( struct quickHeap **  pH  ) 

Definition at line 50 of file quickHeap.c.

References freez(), and quickHeap::heap.

00052 {
00053 struct quickHeap *h = *pH;
00054 freez(&h->heap);
00055 freez(pH);
00056 }

Here is the call graph for this function:

struct quickHeap* newQuickHeap ( int  initSize,
int(*)(const void *elem1, const void *elem2)  compare 
) [read]

Definition at line 33 of file quickHeap.c.

References AllocN, AllocVar, quickHeap::compareFunc, errAbort(), quickHeap::heap, quickHeap::heapCount, and quickHeap::heapMax.

00037 {
00038 struct quickHeap *h;
00039 if (initSize < 1)
00040     errAbort("invalid initial size for newQuickHeap: %d",initSize);
00041 AllocVar(h);
00042 h->heapCount=0;
00043 h->heapMax = initSize;
00044 h->heap = AllocN(void *,h->heapMax);
00045 h->compareFunc = compare;
00046 return h;
00047 }

Here is the call graph for this function:

void* peekQuickHeapTop ( struct quickHeap h  ) 

Definition at line 176 of file quickHeap.c.

References quickHeap::heap, and quickHeap::heapCount.

00178 {
00179 if (h->heapCount < 1) 
00180     return NULL;
00181 return h->heap[0];    
00182 }

boolean quickHeapEmpty ( struct quickHeap h  ) 

Definition at line 127 of file quickHeap.c.

References quickHeap::heapCount.

00129 {
00130 return h->heapCount < 1;
00131 }

void quickHeapTopChanged ( struct quickHeap h  ) 

Definition at line 119 of file quickHeap.c.

References quickHeapBalanceWithChildren().

00121 {
00122 /* balance heap - swap node with biggest child until both children are 
00123  * either less or equal or hit end of heap (no more children) */
00124 quickHeapBalanceWithChildren(h,0);
00125 }

Here is the call graph for this function:

boolean removeFromQuickHeapByElem ( struct quickHeap h,
void *  elem 
)

Definition at line 164 of file quickHeap.c.

References FALSE, findElemInQuickHeap(), removeFromQuickHeapN(), and TRUE.

00168 {
00169 int n = findElemInQuickHeap(h, elem);
00170 if (n < 0) 
00171     return FALSE;
00172 removeFromQuickHeapN(h,n);
00173 return TRUE;
00174 }

Here is the call graph for this function:

void* removeQuickHeapTop ( struct quickHeap h  ) 

Definition at line 184 of file quickHeap.c.

References quickHeap::heap, quickHeap::heapCount, and removeFromQuickHeapN().

00188 {
00189 void *result = h->heap[0]; 
00190 /* this is ok, but depends on removeFromQuickHeapN NULLing as it empties */   
00191 if (h->heapCount > 0) 
00192     {
00193     removeFromQuickHeapN(h,0);
00194     }
00195 return result;
00196 }

Here is the call graph for this function:


Generated on Tue Dec 25 19:13:30 2007 for blat by  doxygen 1.5.2