-
Notifications
You must be signed in to change notification settings - Fork 1
Getting started with Vector.
Anirudh Lakhanpal edited this page May 31, 2024
·
7 revisions
The vector offered by LibC-STL is somewhat similar in terms of methods and usage to C++ STL.
The file contains the definitions of Vector functions, and _Generic macros. And corresponding function definitions are defined in Vector.h
typedef enum
{
INT,
FLOAT,
CHAR,
DOUBLE,
} DataType;
typedef enum
{
INSERT_VECTOR_SUCCESS,
INSERT_VECTOR_FAILED,
VECTOR_RESIZE_SUCCESS,
VECTOR_RESIZE_FAILED,
PUSH_BACK_VECTOR_SUCCESS,
PUSH_BACK_VECTOR_FAILED,
} StatusCodes;
typedef struct vector
{
void **data;
size_t capacity;
size_t size;
DataType type;
} Vector;
typedef int** VectorDataInt ;
typedef float** VectorDataFloat ;
typedef char** VectorDataChar ;
typedef double** VectorDataDouble ;
Vector *create_Vector(size_t, DataType);
void delete_vector(Vector *);
int resize_vector(Vector *, size_t);
StatusCodes LIBC_INTERNAL_pb_int(Vector *, int);
StatusCodes LIBC_INTERNAL_pb_float(Vector *, float);
StatusCodes LIBC_INTERNAL_pb_char(Vector *, char);
StatusCodes LIBC_INTERNAL_pb_double(Vector *, double);
//Not recommended to call LIBC_INTERNAL functions directly
StatusCodes LIBC_INTERNAL_insert_int(Vector *, int, size_t);
StatusCodes LIBC_INTERNAL_insert_float(Vector *, float, size_t);
StatusCodes LIBC_INTERNAL_insert_char(Vector *, char, size_t);
StatusCodes LIBC_INTERNAL_insert_double(Vector *, double, size_t);
int AtInt(Vector *, int);
float AtFloat(Vector *, int);
char AtChar(Vector *, int);
double AtDouble(Vector *, int);
int** get_vector_int(Vector *);
int empty_vector(Vector *);
void *at(Vector *, size_t);
size_t vector_size(Vector *);
size_t vector_capacity(Vector *);
#define insert(Container, index, value) _Generic((value), \
int: LIBC_INTERNAL_insert_int, \
float: LIBC_INTERNAL_insert_float, \
char: LIBC_INTERNAL_insert_char, \
double: LIBC_INTERNAL_insert_double, \
)
#define AtVector(container, index, type) _Generic((type), \
int: AtInt, \
float: AtFloat, \
char: AtChar, \
double: AtDouble \
)(container, index)
#define push_Back(Container, T) _Generic((T), \
int: LIBC_INTERNAL_pb_int, \
float: LIBC_INTERNAL_pb_float, \
char: LIBC_INTERNAL_pb_char, \
double: LIBC_INTERNAL_pb_double)(Container, T)