CPPDescent 80d9539 (with uncommitted changes)
A C++ KNN-Graph creation library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Vector Class Reference

ADT Vector. More...

#include <ADTVector.hpp>

Public Member Functions

 Vector (int size, DestroyFunc destroyValue)
 Construct a new Vector object.
 
 ~Vector ()
 Destroy the Vector object.
 
int getSize ()
 Get the current size of the Vector.
 
void insertLast (Pointer value)
 Inserts a new element at the end of the vector.
 
int removeLast ()
 Removes the last element of the vector.
 
Pointer getAt (int pos)
 Get the value at the specified position of the vector.
 
int setAt (int pos, Pointer value)
 Set the value at the specified position of the vector.
 
Pointer find (Pointer value, CompareFunc compare)
 Find the first element with value equal to value.
 
Pointer binaryFind (Pointer value, CompareFunc compare)
 Find the element with value equal to value using binary search.
 
int findPos (Pointer value, CompareFunc compare)
 Find the first element with value equal to value and return its pos.
 
DestroyFunc setDestroyValue (DestroyFunc destroyValue)
 Set the Destroy Value.
 
vectorNodefirst ()
 Get the first node of the vector.
 
vectorNodelast ()
 Get the last node of the vector.
 
vectorNodenext (vectorNode *node)
 Get the next node of the vector, after the one given.
 
vectorNodeprevious (vectorNode *node)
 Get the previous node of the vector, before the one given.
 
Pointer nodeValue (vectorNode *node)
 Get the value of the node.
 
vectorNodefindNode (Pointer value, CompareFunc compare)
 Find the first node with value equal to value.
 
void swap (int pos1, int pos2)
 Swaps the value that is saved in pos1 with the one in pos2.
 

Detailed Description

ADT Vector.

An ADT Vector using a dynamic array for smart resizing.

Constructor & Destructor Documentation

◆ Vector()

Vector::Vector ( int  size,
DestroyFunc  destroyValue 
)

Construct a new Vector object.

The newly created Vector will be of size size and its elements will be initialized as nullptr.

If destroyValue is not nullptr, it will be called on each element when it is removed from the Vector.

Parameters
sizeThe initial size of the Vector.
destroyValueThe function to be called on each element when it is removed from the Vector.

◆ ~Vector()

Vector::~Vector ( )

Destroy the Vector object.

Deletes all allocated memory of the Vector.

Member Function Documentation

◆ binaryFind()

Pointer Vector::binaryFind ( Pointer  value,
CompareFunc  compare 
)

Find the element with value equal to value using binary search.

Parameters
valueThe value to look for.
compareThe function to be used for comparison.
Returns
Pointer A pointer to the found value.

◆ find()

Pointer Vector::find ( Pointer  value,
CompareFunc  compare 
)

Find the first element with value equal to value.

Parameters
valueThe value to look for.
compareThe function to be used for comparison.
Returns
Pointer A pointer to the found value.

◆ findNode()

vectorNode * Vector::findNode ( Pointer  value,
CompareFunc  compare 
)

Find the first node with value equal to value.

Parameters
valueThe value to look for.
compareThe function to be used for comparison.
Returns
vectorNode The resulting node.

◆ findPos()

int Vector::findPos ( Pointer  value,
CompareFunc  compare 
)

Find the first element with value equal to value and return its pos.

Parameters
valueThe value to look for.
compareThe function to be used for comparison.
Returns
int The position of the element.

◆ first()

vectorNode * Vector::first ( )

Get the first node of the vector.

Returns
vectorNode

◆ getAt()

Pointer Vector::getAt ( int  pos)

Get the value at the specified position of the vector.

Parameters
posThe position to look for.
Returns
Pointer A pointer to the value at the specified position.

◆ getSize()

int Vector::getSize ( )

Get the current size of the Vector.

Returns
int The size of the Vector.

◆ insertLast()

void Vector::insertLast ( Pointer  value)

Inserts a new element at the end of the vector.

Parameters
valueThe value of the new element.

If we are at the last element, we create a new array double the size.

◆ last()

vectorNode * Vector::last ( )

Get the last node of the vector.

Returns
vectorNode

◆ next()

vectorNode * Vector::next ( vectorNode node)

Get the next node of the vector, after the one given.

Parameters
nodeThe node to get the next of.
Returns
vectorNode

◆ nodeValue()

Pointer Vector::nodeValue ( vectorNode node)

Get the value of the node.

Parameters
node
Returns
Pointer

◆ previous()

vectorNode * Vector::previous ( vectorNode node)

Get the previous node of the vector, before the one given.

Parameters
nodeThe node to get the previous of.
Returns
vectorNode

◆ removeLast()

int Vector::removeLast ( )

Removes the last element of the vector.

Returns
int -1 if the function fails, else 0.

◆ setAt()

int Vector::setAt ( int  pos,
Pointer  value 
)

Set the value at the specified position of the vector.

Parameters
posThe position to edit.
valueThe new value.
Returns
int -1 if the function fails, else 0.

◆ setDestroyValue()

DestroyFunc Vector::setDestroyValue ( DestroyFunc  destroyValue)

Set the Destroy Value.

Parameters
destroyValueThe new destroy value function.
Returns
DestroyFunc The old destroy value function.

◆ swap()

void Vector::swap ( int  pos1,
int  pos2 
)

Swaps the value that is saved in pos1 with the one in pos2.

Parameters
pos1Index of the first element to be swaped.
pos2Index of the second element to be swaped.
Returns
vectorNode The resulting node.

The documentation for this class was generated from the following files: