43 void swap(
unsigned int i,
unsigned int j)
override;
47 void insert(
T *we,
float v);
49 void update(
T *we,
float nv);
52 int remove(
T *we)
override;
59 inline int parent(
int i)
const {
return (i-1)/2;}
61 inline int left(
int i)
const {
return 2*i+1;}
63 inline int right(
int i)
const {
return 2*i+2;}
109 if (we==
nullptr) {
return; }
110 if (we->heapPosition != -1) {
return; }
124 if (we==
nullptr) {
return; }
126 if (we->heapPosition == -1)
144 if (we ==
nullptr) {
return -1; }
146 const int i = we->heapPosition;
147 if (i == -1) {
return -1; }
150 if (i >= n) {
return -1; }
179 const int i = we->heapPosition;
180 if (i == -1) {
return; }
183 if (i >= n) {
return; }
185 const float ov =
static_cast<float>(we->value);
204 if (i==0) {
return 0; }
205 const int pi = parent(i);
217int CSOObjectHeap<T>::downHeap(
int i)
219 int largest=i,l=left(i),r=right(i);
222 if (i >= n) {
return -1; }
229 return downHeap(largest);
244 for (i = 0; i < n; ++i)
249 n = newheap->CSOObjectVector<T>::num();
250 for ( i = 0; i < n; ++i)
252 insert(newheap->CSOObjectVector<T>::at(i));
Heap structure with property i>2*i+1 and i>2*i+2.
T * root() const
Returns the root (first) element of heap that is typecast from CSOLiveWireNode to T.
void insert(T *we)
Inserts heap element and resorts the heap.
int remove(T *we) override
Removes the heap element, and resorts the heap.
void swap(unsigned int i, unsigned int j) override
Swaps two heap elements and resorts the heap.
void sort()
Sorts the heap.
~CSOObjectHeap() override
Standard destructor.
void update(T *we, float nv)
Updates the specified heap element with the new value, and resorts the heap.
Dynamic templated vector.
unsigned int num() const
Returns the number of elements in the vector.
virtual void swap(unsigned int p1, unsigned int p2)
Swaps two elements in the vector.
T * firstBoundsCheck() const
Returns the first element, and return nullptr if out of range.
virtual unsigned int append(T *elem)
Appends the element to the back of the vector and returns its position.
T * at(unsigned int pos) const
Returns the element at the specified position.
virtual void deleteLast()
Deletes the last element of the vector.
virtual unsigned int appendUnsafe(T *elem)
Appends the element to back of vector.
virtual void clear()
Clears all internal pointers.
T * last() const
Returns the last element.