CPPDescent 80d9539 (with uncommitted changes)
A C++ KNN-Graph creation library
Loading...
Searching...
No Matches
ADTVector.hpp
Go to the documentation of this file.
1
11#pragma once
12
13#include "common.hpp"
14
15#define VECTOR_MIN_CAPACITY 10
16
17#define VECTOR_BOF (vectorNode*)0
18#define VECTOR_EOF (vectorNode*)0
19
27 public:
34 vectorNode(Pointer value) : value(value){};
40 Pointer getValue() const { return value; };
46 void setValue(Pointer value) { this->value = value; };
47
48 private:
49 Pointer value;
50};
51
58class Vector {
59 public:
73 Vector(int size, DestroyFunc destroyValue);
80 ~Vector();
86 int getSize();
92 void insertLast(Pointer value);
98 int removeLast();
105 Pointer getAt(int pos);
113 int setAt(int pos, Pointer value);
121 Pointer find(Pointer value, CompareFunc compare);
129 Pointer binaryFind(Pointer value, CompareFunc compare);
137 int findPos(Pointer value, CompareFunc compare);
144 DestroyFunc setDestroyValue(DestroyFunc destroyValue);
150 vectorNode* first();
156 vectorNode* last();
163 vectorNode* next(vectorNode* node);
177 Pointer nodeValue(vectorNode* node);
185 vectorNode* findNode(Pointer value, CompareFunc compare);
193 void swap(int pos1, int pos2);
194
195 private:
196 vectorNode* array;
197 int size;
198 int capacity;
199 DestroyFunc destroyValue;
200};
ADT Vector.
Definition ADTVector.hpp:58
int findPos(Pointer value, CompareFunc compare)
Find the first element with value equal to value and return its pos.
Definition ADTVector.cpp:125
vectorNode * last()
Get the last node of the vector.
Definition ADTVector.cpp:146
~Vector()
Destroy the Vector object.
Definition ADTVector.cpp:21
vectorNode * first()
Get the first node of the vector.
Definition ADTVector.cpp:139
int removeLast()
Removes the last element of the vector.
Definition ADTVector.cpp:50
Pointer nodeValue(vectorNode *node)
Get the value of the node.
Definition ADTVector.cpp:167
Pointer find(Pointer value, CompareFunc compare)
Find the first element with value equal to value.
Definition ADTVector.cpp:87
Pointer getAt(int pos)
Get the value at the specified position of the vector.
Definition ADTVector.cpp:69
vectorNode * findNode(Pointer value, CompareFunc compare)
Find the first node with value equal to value.
Definition ADTVector.cpp:171
vectorNode * next(vectorNode *node)
Get the next node of the vector, after the one given.
Definition ADTVector.cpp:153
void swap(int pos1, int pos2)
Swaps the value that is saved in pos1 with the one in pos2.
Definition ADTVector.cpp:179
int setAt(int pos, Pointer value)
Set the value at the specified position of the vector.
Definition ADTVector.cpp:76
void insertLast(Pointer value)
Inserts a new element at the end of the vector.
Definition ADTVector.cpp:38
vectorNode * previous(vectorNode *node)
Get the previous node of the vector, before the one given.
Definition ADTVector.cpp:160
DestroyFunc setDestroyValue(DestroyFunc destroyValue)
Set the Destroy Value.
Definition ADTVector.cpp:133
Pointer binaryFind(Pointer value, CompareFunc compare)
Find the element with value equal to value using binary search.
Definition ADTVector.cpp:95
int getSize()
Get the current size of the Vector.
Definition ADTVector.cpp:34
Class for the vector Node object.
Definition ADTVector.hpp:26
vectorNode()
Construct a new vector Node object.
Definition ADTVector.hpp:33
void setValue(Pointer value)
Set the Value object.
Definition ADTVector.hpp:46
Pointer getValue() const
Get the Value object.
Definition ADTVector.hpp:40