CPPDescent 80d9539 (with uncommitted changes)
A C++ KNN-Graph creation library
Loading...
Searching...
No Matches
ADTPQueue.hpp
Go to the documentation of this file.
1
11#pragma once
12
13#include "ADTVector.hpp"
14
19class PQueue {
20 public:
36 PQueue(CompareFunc compare, DestroyFunc destroyValue, Vector* values);
41 ~PQueue();
47 int getSize();
53 Pointer getMax();
59 Pointer getMin();
65 void insert(Pointer value);
70 void removeMax();
77 DestroyFunc setDestroyValue(DestroyFunc destroyValue);
86 void remove(Pointer value, CompareFunc compare);
94 int find(Pointer value, CompareFunc compare);
95
101 Vector* toVector() { return this->vector; };
102
103 // Helper functions
104 // These are used because the node IDs are 1-based, where as the
105 // vector is 0-based.
106 Pointer nodeValue(int nodeId);
107 void nodeSwap(int nodeId1, int nodeId2);
108 void bubbleUp(int nodeId);
109 void bubbleDown(int nodeId);
110 void naiveHeapify(Vector* values);
111
112 private:
113 Vector* vector;
114 CompareFunc compare;
115 DestroyFunc destroyValue;
116};
ADTVector implementation using a dynamic array.
ADT Priority Queue.
Definition ADTPQueue.hpp:19
void insert(Pointer value)
Insert a new element to the queue.
Definition ADTPQueue.cpp:112
Pointer getMin()
Get the min element of the queue.
Definition ADTPQueue.cpp:99
Vector * toVector()
Returns all the elements as a vector.
Definition ADTPQueue.hpp:101
void remove(Pointer value, CompareFunc compare)
Finds (using the given compare function) and removes the node with the given value.
Definition ADTPQueue.cpp:145
DestroyFunc setDestroyValue(DestroyFunc destroyValue)
Set the Destroy Value object.
Definition ADTPQueue.cpp:139
~PQueue()
Destroy the PQueue object.
Definition ADTPQueue.cpp:86
int find(Pointer value, CompareFunc compare)
Finds the given value in the priority queue and returns its nodeId.
Definition ADTPQueue.cpp:169
Pointer getMax()
Get the max element of the queue.
Definition ADTPQueue.cpp:95
int getSize()
Get the size of the priority queue.
Definition ADTPQueue.cpp:91
void removeMax()
Remove the max of the queue.
Definition ADTPQueue.cpp:120
ADT Vector.
Definition ADTVector.hpp:58