-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray-list.h
31 lines (25 loc) · 1.12 KB
/
array-list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// SPDX-License-Identifier: GPL-3.0-or-later
#include <stdbool.h>
#include <stdlib.h>
// structure that stores an array list
// capacity is set to 0 if we failed to allocate the memory
// or there is an error in the array list
struct array_list {
void **items;
size_t capacity;
size_t length;
};
// Creates an array list that can contain capacity number of items
// array_list.capacity is set to 0 if we failed allocate the memory
struct array_list array_list_create(const size_t initial_capacity);
// Get the value in index of the array list
void *array_list_get(const struct array_list array, const size_t index);
// Pushes (puts at the end) a value at the end of the array list
// Returns true if success, returns false if failure
bool array_list_push(struct array_list *array, void *item);
// Remove a specific index from an array list
// Returns true if success, returns false if failure (doesn't exist)
bool array_list_remove(struct array_list *array, const size_t index);
// Simply free array.items and set the capacity and length to 0
// Returns true if success and false if failure
bool array_list_free(struct array_list *array);