Definition of vector structure and related functions.
More...
#include "consts.h"
#include "includes.h"
Go to the source code of this file.
|
#define | _VECTOR_H_ |
| Include guard.
|
#define | MIN_CAPACITY 2 |
| Defines the minimum allocated memory for the vector. If data_type is char, this is 2B of data.
|
#define | MAX_CAPACITY 2048 |
| Defines the maximum allocable memory for the vector. If data_type is char, this is 2KiB of data.
|
#define | RESIZE_COEFFICIENT 2 |
| Defines the multiplicative coefficient for which the vector has to be resized.
|
|
typedef char | data_type |
| The type of data wrapped in the vector structure. For convenience char has been choosen so it can wrap, by casting, any other primitive data type.
|
typedef struct vector | vector |
| The vector structure.
|
|
vector * | buildVector () |
| Builds a vector structure initializing its fields. If vector's allocation or data's block allocation fails, it exits with EXIT_ALLOC_FAILED exit code.
|
void | freeVector (vector *const vector) |
| Frees the memory used from the vector structure.
|
void | resize (vector *const vector, const size_t newCapacity) |
| Resizes the capacity of the vector with the new capacity specified. If vector's data's block allocation fails, it exits with EXIT_ALLOC_FAILED exit code.
|
void | pushBack (vector *const vector, const data_type element) |
| Pushes an element at the back of the vector.
|
data_type | popBack (vector *const vector) |
| Pops the element at the back of the vector. If necessary, the vector is resized automatically. If the vector is empty, it exits with EXIT_POP_FAILURE exit code.
|
void | pushFront (vector *const vector, const data_type element) |
| Pushes an element at the front of the vector. If necessary, the vector is resized automatically.
|
data_type | popFront (vector *const vector) |
| Pops the element at the back of the vector. If necessary, the vector is resized automatically. If the vector is empty, it exits with EXIT_POP_FAILURE exit code.
|
data_type | at (vector *vector, size_t index) |
| Access at the element in the given index of the vector. If the index is greater or equal to the vector's size, it exits with EXIT_ILLEGAL_INDEX_FAILURE exit code.
|
Definition of vector structure and related functions.
Definition in file vector.h.
◆ _VECTOR_H_
Include guard.
Definition at line 26 of file vector.h.
◆ MAX_CAPACITY
#define MAX_CAPACITY 2048 |
Defines the maximum allocable memory for the vector. If data_type is char, this is 2KiB of data.
Definition at line 31 of file vector.h.
◆ MIN_CAPACITY
Defines the minimum allocated memory for the vector. If data_type is char, this is 2B of data.
Definition at line 29 of file vector.h.
◆ RESIZE_COEFFICIENT
#define RESIZE_COEFFICIENT 2 |
Defines the multiplicative coefficient for which the vector has to be resized.
Definition at line 33 of file vector.h.
◆ data_type
The type of data wrapped in the vector structure. For convenience char has been choosen so it can wrap, by casting, any other primitive data type.
Definition at line 36 of file vector.h.
◆ vector
typedef struct vector vector |
◆ at()
Access at the element in the given index of the vector. If the index is greater or equal to the vector's size, it exits with EXIT_ILLEGAL_INDEX_FAILURE exit code.
- Parameters
-
vector | The vector. |
index | The index to access to. |
- Returns
- The element at the index position in the vector.
Definition at line 111 of file vector.c.
◆ buildVector()
Builds a vector structure initializing its fields. If vector's allocation or data's block allocation fails, it exits with EXIT_ALLOC_FAILED exit code.
- Returns
- A vector structure.
Definition at line 23 of file vector.c.
◆ freeVector()
void freeVector |
( |
vector *const | vector | ) |
|
Frees the memory used from the vector structure.
- Parameters
-
vector | The vector to be free. |
Definition at line 43 of file vector.c.
◆ popBack()
Pops the element at the back of the vector. If necessary, the vector is resized automatically. If the vector is empty, it exits with EXIT_POP_FAILURE exit code.
- Parameters
-
vector | The vector from which the element is poped. |
- Returns
- Returns the element at the back of the vector.
Definition at line 70 of file vector.c.
◆ popFront()
Pops the element at the back of the vector. If necessary, the vector is resized automatically. If the vector is empty, it exits with EXIT_POP_FAILURE exit code.
- Parameters
-
vector | The vector from which the element is poped. |
- Returns
- Returns the element at the front of the vector.
Definition at line 94 of file vector.c.
◆ pushBack()
Pushes an element at the back of the vector.
- Parameters
-
vector | The vector into the element has to be pushed. If necessary, the vector is resized automatically. |
element | The element to be pushed. |
Definition at line 63 of file vector.c.
◆ pushFront()
Pushes an element at the front of the vector. If necessary, the vector is resized automatically.
- Parameters
-
vector | The vector into the element has to be pushed. |
element | The element to be pushed. |
Definition at line 83 of file vector.c.
◆ resize()
void resize |
( |
vector *const | vector, |
|
|
const size_t | newCapacity ) |
Resizes the capacity of the vector with the new capacity specified. If vector's data's block allocation fails, it exits with EXIT_ALLOC_FAILED exit code.
- Parameters
-
vector | The vector that has to be resized. |
newCapacity | The new capacity of the vector. |
Definition at line 48 of file vector.c.