-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.h
More file actions
38 lines (29 loc) · 1.01 KB
/
vector.h
File metadata and controls
38 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef CICADA_VECTOR_H
#define CICADA_VECTOR_H
#include <stddef.h>
#include <stdbool.h>
/*
* Vector is a generic dynamic array with no
* fixed length as is the case with static arrays.
* It can grow (and sometimes shrink) on an as
* need basis. Mostly complies with a similar API
* as List or any other "linear" data structure.
*/
struct Vector {
size_t len;
size_t cap;
void** data;
};
struct Vector *newVector(); // O(1)
struct Vector *newVectorReserved(size_t); // O(1)
void freeVector(struct Vector*); // O(n)
void cleanVector(struct Vector*); // O(n)
void *lPopVectorEl(struct Vector*); // O(n)
void *rPopVectorEl(struct Vector*); // O(1)
bool lPushVectorEl(struct Vector*, void*); // O(n)
bool rPushVectorEl(struct Vector*, void*); // O(1) avg
void *getVectorEl(struct Vector*, size_t); // O(1)
bool setVectorEl(struct Vector*, size_t, void*); // O(1)
void *deleteVectorEl(struct Vector*, size_t); // O(n)
bool insertVectorEl(struct Vector*, size_t, void*); // O(n)
#endif