Restructure

This commit is contained in:
2025-01-29 23:21:18 +02:00
parent 0165e7d682
commit 69811ba0f2
25 changed files with 332 additions and 25 deletions

View File

@@ -0,0 +1,21 @@
#ifndef _H_MCUTIL_COLLEC_GEN_VEC
#define _H_MCUTIL_COLLEC_GEN_VEC
#include "mcutil/mcutil.h"
#include <stddef.h>
#define MCU_GEN_VEC_INITIAL_SIZE 32
typedef struct gen_vec_s {
void** inner;
size_t count;
size_t capacity;
} gen_vec_t;
MCU_API void mcu_gen_vec_insert_front(gen_vec_t* gv, void* data);
MCU_API void mcu_gen_vec_insert_back(gen_vec_t* gv, void* data);
MCU_API void* mcu_gen_vec_remove_back(gen_vec_t *gv);
MCU_API void* mcu_gen_vec_remove_front(gen_vec_t *gv);
#endif

View File

@@ -0,0 +1,33 @@
#ifndef _H_MCU_COLLECT_HASH_MAP
#define _H_MCU_COLLECT_HASH_MAP
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include "mcutil/mcutil.h"
typedef struct mcu_hash_map_node_s {
uint8_t key[16];
void* value;
struct mcu_hash_map_node_s* next;
} mcu_hash_map_node_t;
typedef struct mcu_hash_map_s {
mcu_hash_map_node_t* nodes;
} mcu_hash_map_t;
#define mcu_hm_insert(hm, key, value) _mcu_hm_insert((hm), (key), (const size_t)sizeof(key), (value));
#define mcu_hm_get(hm, key) _mcu_hm_insert((hm), (key), (const size_t)sizeof(key));
#define mcu_hm_remove(hm, key) _mcu_hm_insert((hm), (key), (const size_t)sizeof(key));
MCU_API mcu_hash_map_t mcu_hm_new();
MCU_API void _mcu_hm_insert(mcu_hash_map_t* hm, const void* key, const size_t key_len, const void* value);
MCU_API void* _mcu_hm_get (mcu_hash_map_t* hm, const void* key, const size_t key_len);
MCU_API void* _mcu_hm_remove(mcu_hash_map_t* hm, const void* key, const size_t key_len);
/// Frees the hashmap but not the pointers inside the values
MCU_API void mcu_free(mcu_hash_map_t* hm);
/// Frees the hashmap and the pointers inside the values
MCU_API void mcu_free_all(mcu_hash_map_t* hm);
#endif // _H_MCU_COLLECT_HASH_MAP

View File

@@ -0,0 +1,42 @@
#ifndef _H_MCU_STR
#define _H_MCU_STR
#include "mcutil/mcutil.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define mcu_str_append_cstr(to, from) mc_str_append((to), mc_str_new(from))
#define mcu_str_free(str) MCU_FREE((str)->inner)
typedef struct mcu_str_s {
char* inner;
uint8_t _null;
size_t len;
size_t cap;
} mcu_str_t;
/// Creates a new owned string
/// You can just use printf as normal with this cause you can safely cast this into char*
MCU_API mcu_str_t mcu_str_new(const char* str);
/// Append the string 'from' onto string 'to'
MCU_API void mcu_str_append(mcu_str_t* to, const mcu_str_t* from);
/// Strip the whitespace from the front of the string
MCU_API void mcu_str_trim_front(mcu_str_t* str);
/// Strip the whitespace from the front of the string
MCU_API void mcu_str_trim_end(mcu_str_t* str);
/// Strip the whitespace from the front and end of the string
MCU_API void mcu_str_trim(mcu_str_t* str);
/// Replace string 'from' to string 'to'
/// Hopefully this works, i hope
MCU_API void mcu_str_replace(mcu_str_t* str, const mcu_str_t* from, const mcu_str_t* to);
#endif // _H_MCU_STR