implement vector
This commit is contained in:
@ -1,14 +1,6 @@
|
||||
#ifndef LIBFLINT_H_UTILITY
|
||||
#define LIBFLINT_H_UTILITY
|
||||
|
||||
/**
|
||||
* \struct Point
|
||||
* \brief Representation of a point on a two dimensional grid
|
||||
* \var int x
|
||||
* x point on the 2d grid
|
||||
* \var int y
|
||||
* y point on the 2d grid
|
||||
*/
|
||||
typedef struct Point {
|
||||
int x;
|
||||
int y;
|
||||
|
31
include/vector.h
Normal file
31
include/vector.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef LIBFLINT_H_VECTOR
|
||||
#define LIBFLINT_H_VECTOR
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
typedef struct Vector {
|
||||
size_t capacity;
|
||||
size_t length;
|
||||
void **elements;
|
||||
void (*destroy)(void *data);
|
||||
} Vector;
|
||||
|
||||
int vec_init(Vector *vec, void (*destroy)(void *data));
|
||||
|
||||
int vec_init_with_capacity(Vector *vec, void (*destroy)(void *data), size_t cap);
|
||||
|
||||
void vec_destroy(Vector *vec);
|
||||
|
||||
int vec_insert(Vector *vec, void *data, size_t index);
|
||||
|
||||
int vec_push(Vector *vec, void *data);
|
||||
|
||||
void *vec_safe_at(Vector *vec, size_t index);
|
||||
|
||||
void *vec_remove(Vector *vec, size_t index);
|
||||
|
||||
#define vec_at(v, i) (v)->elements[(i)]
|
||||
|
||||
#define vec_len(v) (v)->length
|
||||
|
||||
#endif // LIBFLINT_H_VECTOR
|
Reference in New Issue
Block a user