TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dtNodeQueue Class Reference

#include <DetourNode.h>

Public Member Functions

 dtNodeQueue (int n)
 
 ~dtNodeQueue ()
 
void operator= (dtNodeQueue &)
 
void clear ()
 
dtNodetop ()
 
dtNodepop ()
 
void push (dtNode *node)
 
void modify (dtNode *node)
 
bool empty () const
 
int getMemUsed () const
 
int getCapacity () const
 

Private Member Functions

void bubbleUp (int i, dtNode *node)
 
void trickleDown (int i, dtNode *node)
 

Private Attributes

dtNode ** m_heap
 
const int m_capacity
 
int m_size
 

Constructor & Destructor Documentation

dtNodeQueue::dtNodeQueue ( int  n)
141  :
142  m_heap(0),
143  m_capacity(n),
144  m_size(0)
145 {
146  dtAssert(m_capacity > 0);
147 
148  m_heap = (dtNode**)dtAlloc(sizeof(dtNode*)*(m_capacity+1), DT_ALLOC_PERM);
149  dtAssert(m_heap);
150 }
void * dtAlloc(int size, dtAllocHint hint)
Definition: DetourAlloc.cpp:41
const int m_capacity
Definition: DetourNode.h:165
Definition: DetourNode.h:34
Memory persist after a function call.
Definition: DetourAlloc.h:26
#define dtAssert
Definition: DetourAssert.h:30
int m_size
Definition: DetourNode.h:166
dtNode ** m_heap
Definition: DetourNode.h:164

+ Here is the call graph for this function:

dtNodeQueue::~dtNodeQueue ( )
153 {
154  dtFree(m_heap);
155 }
dtNode ** m_heap
Definition: DetourNode.h:164
void dtFree(void *ptr)
Definition: DetourAlloc.cpp:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Function Documentation

void dtNodeQueue::bubbleUp ( int  i,
dtNode node 
)
private
158 {
159  int parent = (i-1)/2;
160  // note: (index > 0) means there is a parent
161  while ((i > 0) && (m_heap[parent]->total > node->total))
162  {
163  m_heap[i] = m_heap[parent];
164  i = parent;
165  parent = (i-1)/2;
166  }
167  m_heap[i] = node;
168 }
dtNode ** m_heap
Definition: DetourNode.h:164
float total
Cost up to the node.
Definition: DetourNode.h:38

+ Here is the caller graph for this function:

void dtNodeQueue::clear ( )
inline
115  {
116  m_size = 0;
117  }
int m_size
Definition: DetourNode.h:166

+ Here is the caller graph for this function:

bool dtNodeQueue::empty ( ) const
inline
150 { return m_size == 0; }
int m_size
Definition: DetourNode.h:166

+ Here is the caller graph for this function:

int dtNodeQueue::getCapacity ( ) const
inline
158 { return m_capacity; }
const int m_capacity
Definition: DetourNode.h:165

+ Here is the caller graph for this function:

int dtNodeQueue::getMemUsed ( ) const
inline
153  {
154  return sizeof(*this) +
155  sizeof(dtNode*)*(m_capacity+1);
156  }
const int m_capacity
Definition: DetourNode.h:165
Definition: DetourNode.h:34
void dtNodeQueue::modify ( dtNode node)
inline
139  {
140  for (int i = 0; i < m_size; ++i)
141  {
142  if (m_heap[i] == node)
143  {
144  bubbleUp(i, node);
145  return;
146  }
147  }
148  }
int m_size
Definition: DetourNode.h:166
void bubbleUp(int i, dtNode *node)
Definition: DetourNode.cpp:157
dtNode ** m_heap
Definition: DetourNode.h:164

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void dtNodeQueue::operator= ( dtNodeQueue )
inline
112 {}
dtNode* dtNodeQueue::pop ( )
inline
125  {
126  dtNode* result = m_heap[0];
127  m_size--;
129  return result;
130  }
Definition: DetourNode.h:34
void trickleDown(int i, dtNode *node)
Definition: DetourNode.cpp:170
int m_size
Definition: DetourNode.h:166
dtNode ** m_heap
Definition: DetourNode.h:164

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void dtNodeQueue::push ( dtNode node)
inline
133  {
134  m_size++;
135  bubbleUp(m_size-1, node);
136  }
int m_size
Definition: DetourNode.h:166
void bubbleUp(int i, dtNode *node)
Definition: DetourNode.cpp:157

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

dtNode* dtNodeQueue::top ( )
inline
120  {
121  return m_heap[0];
122  }
dtNode ** m_heap
Definition: DetourNode.h:164
void dtNodeQueue::trickleDown ( int  i,
dtNode node 
)
private
171 {
172  int child = (i*2)+1;
173  while (child < m_size)
174  {
175  if (((child+1) < m_size) &&
176  (m_heap[child]->total > m_heap[child+1]->total))
177  {
178  child++;
179  }
180  m_heap[i] = m_heap[child];
181  i = child;
182  child = (i*2)+1;
183  }
184  bubbleUp(i, node);
185 }
int m_size
Definition: DetourNode.h:166
void bubbleUp(int i, dtNode *node)
Definition: DetourNode.cpp:157
dtNode ** m_heap
Definition: DetourNode.h:164
float total
Cost up to the node.
Definition: DetourNode.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

const int dtNodeQueue::m_capacity
private
dtNode** dtNodeQueue::m_heap
private
int dtNodeQueue::m_size
private

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