2023-06-25 15:14:06 +02:00
|
|
|
#ifndef __LIBCPROJECT_ARRAY_LIST__
|
|
|
|
#define __LIBCPROJECT_ARRAY_LIST__
|
2023-01-07 19:27:16 +01:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-06-25 15:07:34 +02:00
|
|
|
#include "types.h"
|
|
|
|
|
2023-01-07 19:27:16 +01:00
|
|
|
#define ARRAY_LIST_INITIAL_CAPACITY 10
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief A dynamic array implementation.
|
|
|
|
* @since v1.2.0
|
|
|
|
*/
|
2023-01-07 19:27:16 +01:00
|
|
|
struct array_list {
|
|
|
|
void** data;
|
|
|
|
size_t size;
|
|
|
|
size_t capacity;
|
|
|
|
};
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Initializes a new array list.
|
|
|
|
* @since v1.2.0
|
|
|
|
*/
|
2023-01-07 19:27:16 +01:00
|
|
|
struct array_list* array_list_initialization();
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Adds an element to the end of the array list.
|
|
|
|
* @since v1.2.0
|
|
|
|
*/
|
2023-01-07 19:27:16 +01:00
|
|
|
void array_list_add(struct array_list* list, void* element);
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Removes an element from the array list.
|
|
|
|
* @since v1.2.0
|
|
|
|
*/
|
2023-01-07 19:27:16 +01:00
|
|
|
void array_list_remove(struct array_list* list, size_t index);
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Gets an element from the array list.
|
|
|
|
* @since v1.2.0
|
|
|
|
*/
|
2023-01-07 19:27:16 +01:00
|
|
|
void* array_list_get(struct array_list* list, size_t index);
|
|
|
|
|
2023-08-03 19:42:50 +02:00
|
|
|
/**
|
|
|
|
* @brief Frees the array list.
|
|
|
|
* @since v2.1.0
|
|
|
|
*/
|
|
|
|
void array_list_free(struct array_list* list);
|
|
|
|
|
2023-01-07 19:27:16 +01:00
|
|
|
#endif
|