ui: dialogue: +id_map
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
add_library(utils STATIC)
|
||||
|
||||
file(GLOB M_HEADERS "*.h")
|
||||
file(GLOB M_SOURCES "*.c")
|
||||
|
||||
list(REMOVE_ITEM M_HEADERS "utils.h")
|
||||
|
||||
target_sources(utils
|
||||
PRIVATE
|
||||
${M_SOURCES}
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
${M_HEADERS}
|
||||
)
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
#include "d_array.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void init_d_arr_ptr(d_array_ptr_t *arr, int64_t init_capacity) {
|
||||
arr->capacity = init_capacity;
|
||||
arr->length = 0;
|
||||
arr->arr = malloc(sizeof(void *) * init_capacity);
|
||||
}
|
||||
|
||||
void add_d_arr_ptr(d_array_ptr_t *arr, void *ptr, int64_t idx) {
|
||||
if (idx > arr->capacity - 1) {
|
||||
arr->capacity = idx * 2;
|
||||
arr->arr = realloc(arr->arr, arr->capacity);
|
||||
}
|
||||
arr->arr[idx] = ptr;
|
||||
arr->length = idx+1;
|
||||
}
|
||||
|
||||
void free_d_arr(d_array_ptr_t *arr) {
|
||||
arr->capacity = 0;
|
||||
arr->length = 0;
|
||||
free(arr->arr);
|
||||
arr->arr = NULL;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef D_ARRAY_H
|
||||
#define D_ARRAY_H
|
||||
/* Dynamic array of numbers */
|
||||
#include <stdint.h>
|
||||
typedef struct d_array_ptr_t {
|
||||
int64_t capacity;
|
||||
int64_t length;
|
||||
void **arr;
|
||||
} d_array_ptr_t;
|
||||
|
||||
void init_d_arr_ptr(d_array_ptr_t *arr, int64_t init_capacity);
|
||||
void add_d_arr_ptr(d_array_ptr_t *arr, void *ptr, int64_t idx);
|
||||
void free_d_arr(d_array_ptr_t *arr);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef D_UTILS_H
|
||||
#define D_UTILS_H
|
||||
#include "d_array.h"
|
||||
#endif
|
||||
Reference in New Issue
Block a user