REFACTOR: Completely redid push_back and create
This commit is contained in:
+15
-15
@@ -8,29 +8,32 @@
|
||||
#ifndef CHAR_H
|
||||
#define CHAR_H
|
||||
|
||||
#define CAPACITY 1024
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <utils.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* arr;
|
||||
size_t size;
|
||||
size_t capacity;
|
||||
size_t max_size;
|
||||
} Vec8_t;
|
||||
|
||||
__attribute__((overloadable)) Vec8_t
|
||||
create(const Vec8_t* input);
|
||||
|
||||
__attribute__((overloadable)) Vec8_t
|
||||
create(const _Bool init);
|
||||
Vec8_t
|
||||
create(const char* buf, const int len);
|
||||
|
||||
Vec8_t
|
||||
reserve(Vec8_t* ptr, size_t max_size);
|
||||
push_back(Vec8_t* vec, const char val);
|
||||
|
||||
Vec8_t
|
||||
pop_back(Vec8_t* vec);
|
||||
|
||||
Vec8_t
|
||||
reserve(Vec8_t* ptr, const size_t max_size);
|
||||
|
||||
Vec8_t
|
||||
shrink_to_fit(Vec8_t* ptr);
|
||||
@@ -41,10 +44,13 @@ swap(Vec8_t* ptr, Vec8_t* ptr_other);
|
||||
char*
|
||||
data(const Vec8_t* ptr);
|
||||
|
||||
size_t
|
||||
capacity(const Vec8_t* ptr);
|
||||
|
||||
size_t
|
||||
max_size(const Vec8_t* ptr);
|
||||
|
||||
void delete (Vec8_t* vec);
|
||||
void delete (const Vec8_t* vec);
|
||||
|
||||
Vec8_t
|
||||
clear(Vec8_t* vec);
|
||||
@@ -76,12 +82,6 @@ back(const Vec8_t* vec);
|
||||
int
|
||||
empty(const Vec8_t* vec);
|
||||
|
||||
Vec8_t
|
||||
add_back(Vec8_t* vec, char val);
|
||||
|
||||
Vec8_t
|
||||
pop_back(Vec8_t* vec);
|
||||
|
||||
__attribute__((overloadable)) Vec8_t
|
||||
resize(Vec8_t* vec, size_t size);
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#define CAPACITY 1024
|
||||
#define SUCCESS 0
|
||||
|
||||
#define FAILURE 1
|
||||
#define ERR_ALLOC_FAIL 20
|
||||
#define ERR_BUF_NULL 21
|
||||
#define ERR_BAD_TYPE 22
|
||||
#define ERR_INVALID_SIZE 23
|
||||
#define ERR_VECTOR_NULL 24
|
||||
#define ERR_MAX_PASSED 25
|
||||
|
||||
extern const char* error_messages[];
|
||||
|
||||
#define LOG(msg) printf("LOG: %s\n", msg) /**< Print log message*/
|
||||
#define LOGERROR(error_code) \
|
||||
printf("ERROR: %s\n", \
|
||||
error_messages[error_code]) /**< Print log error message*/
|
||||
|
||||
#define find_len(arr) sizeof(arr) / sizeof(arr[0])
|
||||
static const size_t VEC_MAX = SIZE_MAX / sizeof(int);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user