A* Pathfinding Project  4.0.3
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
BinaryHeap Class Reference

Binary heap implementation. More...

Detailed Description

Binary heap implementation.

Binary heaps are really fast for ordering nodes in a way that makes it possible to get the node with the lowest F score. Also known as a priority queue.

This has actually been rewritten as a 4-ary heap for performance, but it's the same principle.

See Also
http://en.wikipedia.org/wiki/Binary_heap
https://en.wikipedia.org/wiki/D-ary_heap

Classes

struct  Tuple
 Item in the heap. More...
 

Public Member Functions

 BinaryHeap (int capacity)
 Create a new heap with the specified initial capacity.
 
void Add (PathNode node)
 Adds a node to the heap.
 
void Clear ()
 Removes all elements from the heap.
 
void Rebuild ()
 Rebuilds the heap by trickeling down all items.
 
PathNode Remove ()
 Returns the node with the lowest F score from the heap.
 

Public Attributes

float growthFactor = 2
 The tree will grow by at least this factor every time it is expanded.
 
int numberOfItems
 Number of items in the tree.
 

Package Functions

PathNode GetNode (int i)
 
void SetF (int i, uint f)
 

Properties

bool isEmpty [get]
 True if the heap does not contain any elements.
 

Private Member Functions

void Expand ()
 Expands to a larger backing array when the current one is too small.
 
void Validate ()
 

Static Private Member Functions

static int RoundUpToNextMultipleMod1 (int v)
 Rounds up v so that it has remainder 1 when divided by D.
 

Private Attributes

const int D = 4
 Number of children of each node in the tree.
 
Tuple[] heap
 Internal backing array for the heap.
 
const bool SortGScores = true
 Sort nodes by G score if there is a tie when comparing the F score.
 

Constructor & Destructor Documentation

BinaryHeap ( int  capacity)

Create a new heap with the specified initial capacity.

Member Function Documentation

void Add ( PathNode  node)

Adds a node to the heap.

void Clear ( )

Removes all elements from the heap.

void Expand ( )
private

Expands to a larger backing array when the current one is too small.

PathNode GetNode ( int  i)
package
void Rebuild ( )

Rebuilds the heap by trickeling down all items.

Usually called after the hTarget on a path has been changed

PathNode Remove ( )

Returns the node with the lowest F score from the heap.

static int RoundUpToNextMultipleMod1 ( int  v)
staticprivate

Rounds up v so that it has remainder 1 when divided by D.

I.e it is of the form n*D + 1 where n is any non-negative integer.

void SetF ( int  i,
uint  f 
)
package
void Validate ( )
private

Member Data Documentation

const int D = 4
private

Number of children of each node in the tree.

Different values have been tested and 4 has been empirically found to perform the best.

See Also
https://en.wikipedia.org/wiki/D-ary_heap
float growthFactor = 2

The tree will grow by at least this factor every time it is expanded.

Tuple [] heap
private

Internal backing array for the heap.

int numberOfItems

Number of items in the tree.

const bool SortGScores = true
private

Sort nodes by G score if there is a tie when comparing the F score.

Disabling this will improve pathfinding performance with around 2.5% but may break ties between paths that have the same length in a less desirable manner (only relevant for grid graphs).

Property Documentation

bool isEmpty
get

True if the heap does not contain any elements.


The documentation for this class was generated from the following file: