nanotrav/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...

Defines

#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.
void Ntr_FreeHeap (NtrHeap *heap)
 Frees a priority queue.
int Ntr_HeapInsert (NtrHeap *heap, void *item, int key)
 Inserts an item in a priority queue.
int Ntr_HeapExtractMin (NtrHeap *heap, void *item, int *key)
 Extracts the element with the minimum key from a priority queue.
int Ntr_HeapCount (NtrHeap *heap)
 Returns the number of items in a priority queue.
NtrHeapNtr_HeapClone (NtrHeap *source)
 Clones a priority queue.
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.
static void ntrHeapify (NtrHeap *heap, int i)
 Maintains the heap property of a priority queue.
static int ntrHeapResize (NtrHeap *heap)
 Resizes a priority queue.

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

Copyright (c) 1995-2015, Regents of the University of Colorado

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the University of Colorado nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Function Documentation

void Ntr_FreeHeap ( NtrHeap heap  ) 

Frees a priority queue.

Side effects
None
See also:
Ntr_InitHeap
NtrHeap* Ntr_HeapClone ( NtrHeap source  ) 

Clones a priority queue.

Side effects
None
See also:
Ntr_InitHeap
int Ntr_HeapCount ( NtrHeap heap  ) 

Returns the number of items in a priority queue.

Side effects
None
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
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
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
int Ntr_TestHeap ( NtrHeap heap,
int  i 
)

Tests the heap property of a priority queue.

Returns:
1 if Successful; 0 otherwise.
Side effects
None
static void ntrHeapify ( NtrHeap heap,
int  i 
) [static]

Maintains the heap property of a priority queue.

Side effects
None
See also:
Ntr_HeapExtractMin
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
 All Data Structures Files Functions Variables Typedefs Enumerations Defines

Generated on 31 Dec 2015 for cudd by  doxygen 1.6.1