1#ifndef N_PRIORITYARRAY_H
2#define N_PRIORITYARRAY_H
42 void Add(
const TYPE& elm,
float pri);
100 for (i = 0; i < this->numElements; i++)
102 this->elements[i] = src.
elements[i];
113 this->numElements = 0;
114 this->maxElements = 0;
115 this->minPriElementIndex = 0;
130 minPriElementIndex(0),
166 for (i = 0; i < this->numElements; i++)
168 this->Destroy(&(this->elements[i].element));
170 this->numElements = 0;
171 this->minPriElementIndex = 0;
182 this->minPriElementIndex = 0;
183 float minPri = this->elements[0].priority;
184 for (i = 1; i < this->numElements; i++)
186 if (this->elements[i].priority < minPri)
188 minPri = this->elements[i].priority;
189 this->minPriElementIndex = i;
201 if (this->numElements < this->maxElements)
203 this->elements[this->numElements].element = elm;
204 this->elements[this->numElements].priority = pri;
206 if (this->numElements == this->maxElements)
208 this->UpdateMinPriElementIndex();
213 if (pri > this->elements[this->minPriElementIndex].priority)
215 this->elements[this->minPriElementIndex].element = elm;
216 this->elements[this->minPriElementIndex].priority = pri;
217 this->UpdateMinPriElementIndex();
229 return this->numElements;
239 n_assert((index >= 0) && (index < this->numElements));
240 return this->elements[index].element;
250 n_assert((index >= 0) && (index < this->numElements));
251 return this->elements[index].element;
273 return (0 == this->numElements);
Definition priorityarray.h:27
~PriorityArray()
destructor
Definition priorityarray.h:140
PriorityArray(int size)
constructor
Definition priorityarray.h:77
int Size() const
get number of elements in array
Definition priorityarray.h:227
void Destroy(TYPE *elm)
destroy an element (call destructor without freeing memory)
Definition priorityarray.h:150
TYPE & At(int index)
return n'th array element
Definition priorityarray.h:237
int numElements
Definition priorityarray.h:67
PriorityArray< TYPE > & operator=(const PriorityArray< TYPE > &rhs)
assignment operator
Definition priorityarray.h:259
void Delete()
delete content
Definition priorityarray.h:111
void UpdateMinPriElementIndex()
update the min pri element index
Definition priorityarray.h:179
Element * elements
Definition priorityarray.h:70
void Add(const TYPE &elm, float pri)
add element to array
Definition priorityarray.h:199
int minPriElementIndex
Definition priorityarray.h:69
int maxElements
Definition priorityarray.h:68
void Clear()
clear the array
Definition priorityarray.h:160
TYPE & operator[](int index) const
[] operator
Definition priorityarray.h:248
bool IsEmpty() const
return true if empty
Definition priorityarray.h:271
void Copy(const PriorityArray< TYPE > &src)
copy content
Definition priorityarray.h:91
#define n_assert(exp)
Definition debug.h:50
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
#define n_delete_array(ptr)
Definition osxmemory.h:116
#define n_new_array(type, size)
Definition osxmemory.h:114
an element class
Definition priorityarray.h:62
TYPE element
Definition priorityarray.h:63
float priority
Definition priorityarray.h:64