Survival Royale 1.0.0
A very simple yet funny card game.
Loading...
Searching...
No Matches
vector.h
Go to the documentation of this file.
1// Copyright (C) 2025 Giulio Salvi, Jacopo Paradisi
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
20
21#include "consts.h"
22#include "includes.h"
23
24#ifndef _VECTOR_H_
26 #define _VECTOR_H_
27
29 #define MIN_CAPACITY 2
31 #define MAX_CAPACITY 2048
33 #define RESIZE_COEFFICIENT 2
34
36 typedef char data_type;
37
39 typedef struct vector {
41 size_t size;
43 size_t capacity;
47
53 void freeVector(vector* const vector);
57 void resize(vector* const vector, const size_t newCapacity);
61 void pushBack(vector* const vector, const data_type element);
69 void pushFront(vector* const vector, const data_type element);
78 data_type at(vector* vector, size_t index);
79#endif
Declaration of constants used by the modules.
Preprocessor file used for including library for modules.
The vector structure.
Definition vector.h:39
data_type * data
Contiguous memory segment with in data is stored.
Definition vector.h:45
size_t size
Field for determining the amount of elements actually stored in memory.
Definition vector.h:41
size_t capacity
Field for determining the amount of possible elements that can be stored in memory without resizing t...
Definition vector.h:43
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 allocati...
Definition vector.c:48
void freeVector(vector *const vector)
Frees the memory used from the vector structure.
Definition vector.c:43
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.
Definition vector.c:83
char data_type
The type of data wrapped in the vector structure. For convenience char has been choosen so it can wra...
Definition vector.h:36
data_type popBack(vector *const vector)
Pops the element at the back of the vector. If necessary, the vector is resized automatically....
Definition vector.c:70
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 vecto...
Definition vector.c:111
vector * buildVector()
Builds a vector structure initializing its fields. If vector's allocation or data's block allocation ...
Definition vector.c:23
void pushBack(vector *const vector, const data_type element)
Pushes an element at the back of the vector.
Definition vector.c:63
data_type popFront(vector *const vector)
Pops the element at the back of the vector. If necessary, the vector is resized automatically....
Definition vector.c:94