Simple C Variable Size Vector
 All Data Structures Files Functions Variables Typedefs Pages
vector.h
Go to the documentation of this file.
1 
3 /*
4 Simple C variable size vector, a simple variable size vector written in C
5  Copyright (C) 2016-2017 Francisco Anderson Bezerra Rodrigues
6 
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef VECTOR_H
23 #define VECTOR_H
24 
30 struct vector
31 {
32  void *elements;
33  unsigned long int elementSize;
35  int capacity;
36 };
37 typedef struct vector Vector;
38 
50 Vector* NewVector(unsigned long int elementSize);
51 
66 int VectorAppendCopy(Vector *vec, void *element);
67 
83 int VectorAllocateOne(Vector *vec);
84 
101 void* VectorGetElement(Vector *vec, int position);
102 
115 Vector* DeleteVector(Vector* vec);
116 #endif
The vector data structre.
Definition: vector.h:30
unsigned long int elementSize
Definition: vector.h:33
int numberOfElements
Definition: vector.h:34
int VectorAppendCopy(Vector *vec, void *element)
Inserts a new element at the end of the vector.
Definition: vector.c:59
int capacity
Definition: vector.h:35
Vector * DeleteVector(Vector *vec)
Delete the vector and its elements.
Definition: vector.c:82
void * elements
Definition: vector.h:32
int VectorAllocateOne(Vector *vec)
Allocates space for at least one more element.
Definition: vector.c:49
Vector * NewVector(unsigned long int elementSize)
Create a new vector.
Definition: vector.c:23
void * VectorGetElement(Vector *vec, int position)
Gets the element at informed position.
Definition: vector.c:67