2023-06-25 15:14:06 +02:00
|
|
|
#ifndef __LIBCPROJECT_ARRAY_LIST__
|
|
|
|
#define __LIBCPROJECT_ARRAY_LIST__
|
2023-01-07 19:27:16 +01:00
|
|
|
|
2023-08-07 00:11:07 +02:00
|
|
|
#include <errno.h>
|
2023-01-07 19:27:16 +01:00
|
|
|
#include <stdbool.h>
|
2024-09-25 14:26:15 +02:00
|
|
|
#include <stdio.h>
|
2023-01-07 19:27:16 +01:00
|
|
|
#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;
|
2024-09-25 14:34:33 +02:00
|
|
|
size_t capacity_step;
|
2023-01-07 19:27:16 +01:00
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
|
2024-09-25 14:34:33 +02:00
|
|
|
/**
|
|
|
|
* @brief Initializes a new array list with a capacity.
|
|
|
|
* @since v5.0.0
|
|
|
|
*/
|
|
|
|
struct array_list* array_list_initialization_with_capacity(size_t capacity);
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Adds an element to the end of the array list.
|
2023-08-09 21:08:15 +02:00
|
|
|
*
|
|
|
|
* @param list
|
|
|
|
* @param element
|
2023-06-24 21:06:45 +02:00
|
|
|
* @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.
|
2023-08-09 21:08:15 +02:00
|
|
|
*
|
|
|
|
* @param list
|
|
|
|
* @param index
|
2023-06-24 21:06:45 +02:00
|
|
|
* @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.
|
2023-08-09 21:08:15 +02:00
|
|
|
*
|
|
|
|
* @param list
|
|
|
|
* @param index
|
|
|
|
* @return void*
|
2023-06-24 21:06:45 +02:00
|
|
|
* @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.
|
2023-08-09 21:08:15 +02:00
|
|
|
*
|
|
|
|
* @param list
|
2023-08-05 15:03:53 +02:00
|
|
|
* @since v3.0.0
|
2023-08-03 19:42:50 +02:00
|
|
|
*/
|
|
|
|
void array_list_free(struct array_list* list);
|
|
|
|
|
2023-01-07 19:27:16 +01:00
|
|
|
#endif
|