41 const
T*
root() const;
43 void swap(
unsigned int i,
unsigned int j) override;
55 void clear() override;
60 inline
int parent(
int i)
const {
return (i-1)/2;}
62 inline int left(
int i)
const {
return 2*i+1;}
64 inline int right(
int i)
const {
return 2*i+2;}
95 return reinterpret_cast<T*
>(wp);
117 at(i)->setHeapPosition(i);
118 at(j)->setHeapPosition(j);
126 if (wp ==
nullptr) {
return; }
130 const unsigned int n =
num()-1;
131 last()->setHeapPosition(n);
140 if (wp ==
nullptr) {
return; }
146 const unsigned int n =
num()-1;
147 last()->setHeapPosition(n);
161 if (wp ==
nullptr) {
return -1; }
164 if (i == -1) {
return -1; }
167 if (i >= n) {
return -1; }
197 if (i == -1) {
return; }
200 if (i >= n) {
return; }
219int WEMHeap<T>::upHeap(
int i)
221 if (i == 0) {
return 0; }
222 const int pi = parent(i);
234int WEMHeap<T>::downHeap(
int i)
236 int largest=i,l=left(i),r=right(i);
239 if (i >= n) {
return -1; }
252 return downHeap(largest);
266 const unsigned int n =
num();
267 for (i = 0; i < n; i ++) { newheap->
append(
at(i)); }
269 const unsigned int nn = newheap->
num();
270 for (i = 0; i < nn; i ++) {
insert(newheap->
at(i)); }
280 const unsigned int n =
num();
281 for (
unsigned int i = 0; i < n; i++) {
282 at(i)->setHeapPosition(-1);
WEMHeap()
Standard constructor.
void update(WEMPrimitive *wp, double nv)
Updates given heap element with the given value and resorts this heap.
void clear() override
Remove all elements from heap.
void sort()
Sorts this heap.
void swap(unsigned int i, unsigned int j) override
Swaps two heap elements given by their indices and resorts this heap.
T * root()
Returns the root (first) element of this heap, typecast from WEMPrimitive to T.
~WEMHeap() override
Standard destructor.
int remove(WEMPrimitive *wp) override
Removes the given heap element and resorts this heap.
WEMHeap(WEMHeap &&) noexcept=default
void insert(WEMPrimitive *wp)
Inserts the given heap element and resorts this heap.
This is the base class for the WEM elements nodes, edges, and faces.
int getHeapPosition() const
Returns the heap position.
void setHeapPosition(int heapPosition)
Sets the heap position.
void setHeapValue(double heapValue)
Sets the heap value.
double getHeapValue() const
Returns the heap value.
WEMVector(unsigned int init=0)
virtual unsigned int append(T *elem)
Appends the given element to back of this vector.
WEMPrimitive * at(unsigned int pos) const
virtual void swap(unsigned int p1, unsigned int p2)
Swaps the two elements given by their indices in this vector.
virtual unsigned int appendUnsafe(T *elem)
virtual void deleteLast()
T * first()
Returns the first element.
IteratorTraits::value_type & at(const ml_iterator_map< IteratorTraits, IDMap > &i, typename property_traits< IDMap >::key_type key)
static bool less(const WEMPrimitive &x, const WEMPrimitive &y)