cudd  3.0.0
The University of Colorado Decision Diagram Package
Data Structures | Macros | Functions
ntrHeap.c File Reference

Functions for heap-based priority queues. More...

#include "ntr.h"
Include dependency graph for ntrHeap.c:

Data Structures

struct  NtrHeapSlot
 Entry of NtrHeap. More...
 
struct  NtrHeap
 Heap-based priority queue. More...
 

Macros

#define PARENT(i)   (((i)-1)>>1)
 
#define RIGHT(i)   (((i)+1)<<1)
 
#define LEFT(i)   (((i)<<1)|1)
 
#define ITEM(p, i)   ((p)[i].item)
 
#define KEY(p, i)   ((p)[i].key)
 

Functions

NtrHeapNtr_InitHeap (int size)
 Initializes a priority queue. More...
 
void Ntr_FreeHeap (NtrHeap *heap)
 Frees a priority queue. More...
 
int Ntr_HeapInsert (NtrHeap *heap, void *item, int key)
 Inserts an item in a priority queue. More...
 
int Ntr_HeapExtractMin (NtrHeap *heap, void *item, int *key)
 Extracts the element with the minimum key from a priority queue. More...
 
int Ntr_HeapCount (NtrHeap *heap)
 Returns the number of items in a priority queue. More...
 
NtrHeapNtr_HeapClone (NtrHeap *source)
 Clones a priority queue. More...
 
void Ntr_HeapForeach (NtrHeap *heap, void(*f)(void *e, void *arg), void *arg)
 Calls a function on all items in a heap.
 
int Ntr_TestHeap (NtrHeap *heap, int i)
 Tests the heap property of a priority queue. More...
 
static void ntrHeapify (NtrHeap *heap, int i)
 Maintains the heap property of a priority queue. More...
 
static int ntrHeapResize (NtrHeap *heap)
 Resizes a priority queue. More...
 

Detailed Description

Functions for heap-based priority queues.

The functions in this file manage a priority queue implemented as a heap. The first element of the heap is the one with the smallest key. The queue stores generic pointers, but the key must be an int. Refer to Chapter 7 of Cormen, Leiserson, and Rivest for the theory.

Author
Fabio Somenzi

Function Documentation

◆ Ntr_FreeHeap()

void Ntr_FreeHeap ( NtrHeap heap)

Frees a priority queue.

Side effects None
See also
Ntr_InitHeap

◆ Ntr_HeapClone()

NtrHeap* Ntr_HeapClone ( NtrHeap source)

Clones a priority queue.

Side effects None
See also
Ntr_InitHeap

◆ Ntr_HeapCount()

int Ntr_HeapCount ( NtrHeap heap)

Returns the number of items in a priority queue.

Side effects None

◆ Ntr_HeapExtractMin()

int Ntr_HeapExtractMin ( NtrHeap heap,
void *  item,
int *  key 
)

Extracts the element with the minimum key from a priority queue.

Returns
1 if successful; 0 otherwise.
Side effects The minimum key and the associated item are returned as
side effects.
See also
Ntr_HeapInsert

◆ Ntr_HeapInsert()

int Ntr_HeapInsert ( NtrHeap heap,
void *  item,
int  key 
)

Inserts an item in a priority queue.

Returns
1 if successful; 0 otherwise.
Side effects None
See also
Ntr_HeapExtractMin

◆ Ntr_InitHeap()

NtrHeap* Ntr_InitHeap ( int  size)

Initializes a priority queue.

Returns
a pointer to the heap if successful; NULL otherwise.
Side effects None
See also
Ntr_FreeHeap

◆ Ntr_TestHeap()

int Ntr_TestHeap ( NtrHeap heap,
int  i 
)

Tests the heap property of a priority queue.

Returns
1 if Successful; 0 otherwise.
Side effects None

◆ ntrHeapify()

static void ntrHeapify ( NtrHeap heap,
int  i 
)
static

Maintains the heap property of a priority queue.

Side effects None
See also
Ntr_HeapExtractMin

◆ ntrHeapResize()

static int ntrHeapResize ( NtrHeap heap)
static

Resizes a priority queue.

Resizes a priority queue by doubling the number of available slots.

Returns
1 if successful; 0 otherwise.
Side effects None
See also
Ntr_HeapInsert