CPPDescent 80d9539 (with uncommitted changes)
A C++ KNN-Graph creation library
Loading...
Searching...
No Matches
ADTGraph.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include "ADTPQueue.hpp"
15#include "ADTVector.hpp"
16
17class Graph {
18 private:
19 Vector* vec;
20 int size;
21 CompareFunc compare_vertices;
22 CompareFunc compare_data;
23 DestroyFunc destroy_data;
24
25 public:
26 Graph(CompareFunc compare, DestroyFunc vecDestroy);
27 ~Graph();
28 int getSize();
29 void insertVertex(Pointer vertex);
30 Vector* getVerticesV();
31 void removeVertex(Pointer vertex);
32 void insertEdge(Pointer vertex1, Pointer vertex2);
33 void removeEdge(Pointer vertex1, Pointer vertex2);
34 Vector* getAdjacentV(Pointer vertex);
35 Vector* getReverseAdjacentV(Pointer vertex);
36 Vector* getGeneralNeighborsV(Pointer vertex);
37 bool isNeighborVertex(Pointer v1, Pointer v2);
38 CompareFunc getCompareData() { return this->compare_data; };
39 CompareFunc getCompareVertices() { return this->compare_vertices; };
40 DestroyFunc getDestroyData() { return this->destroy_data; };
41 Vector* getVec() { return this->vec; };
42};
43
45 private:
46 Pointer data;
47 PQueue* neighbors;
48 PQueue* reverse;
49 Graph* owner;
50 bool hasBeenChecked;
51 double norm;
52 int posInGraphVector;
53
54 public:
55 GraphVertex(Pointer data, Graph* owner);
57 void setPos(int pos) { this->posInGraphVector = pos; };
58 int getPos() { return this->posInGraphVector; };
59 void addNeighbor(Pointer neighbor) { this->neighbors->insert(neighbor); };
60 void addReverse(Pointer reverse) { this->reverse->insert(reverse); };
61 void removeNeighbor(Pointer neighbor, CompareFunc compare) {
62 this->neighbors->remove(neighbor, compare);
63 };
64 void removeReverse(Pointer reverse, CompareFunc compare) {
65 this->reverse->remove(reverse, compare);
66 };
67 PQueue* getNeighbors() { return this->neighbors; };
68 PQueue* getReverse() { return this->reverse; };
69 Pointer getData() { return this->data; };
70 Graph* getOwner() { return this->owner; };
71 void check() { this->hasBeenChecked = true; };
72 bool checked() { return this->hasBeenChecked; };
73 void setNorm(double norm) { this->norm = norm; };
74 double getNorm() { return this->norm; };
75};
76
78 public:
79 GraphVertexPair(Graph* owner, Pointer vertex1, Pointer vertex2)
80 : flag(true), vertex1(vertex1), vertex2(vertex2), owner(owner){};
81 Pointer getVertex1() { return this->vertex1; };
82 Pointer getVertex2() { return this->vertex2; };
83 Graph* getOwner() { return this->owner; };
84 void setFalse() { this->flag = false; };
85 bool getFlag() { return this->flag; };
86
87 private:
88 bool flag;
89 Pointer vertex1;
90 Pointer vertex2;
91 Graph* owner;
92};
ADTVector implementation using a dynamic array.
Definition ADTGraph.hpp:77
Definition ADTGraph.hpp:44
Definition ADTGraph.hpp:17
Vector * getGeneralNeighborsV(Pointer vertex)
Returns a vector where the K first elements are the direct neighbors of the vertex and the rest are t...
Definition ADTGraph.cpp:167
void insertVertex(Pointer vertex)
Insert a vertex to the graph (if it doesn't already exist).
Definition ADTGraph.cpp:70
ADT Priority Queue.
Definition ADTPQueue.hpp:19
void insert(Pointer value)
Insert a new element to the queue.
Definition ADTPQueue.cpp:112
void remove(Pointer value, CompareFunc compare)
Finds (using the given compare function) and removes the node with the given value.
Definition ADTPQueue.cpp:145
ADT Vector.
Definition ADTVector.hpp:58