-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray_list.h
83 lines (73 loc) · 2.19 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef ARRAY_LIST_H
#define ARRAY_LIST_H
/**
* @file array_list.h
* @brief Generic Array List
*/
#ifndef ARRAY_LIST_INITIAL_CAPACITY
#define ARRAY_LIST_INITIAL_CAPACITY_EXPONENT 5 ///< default array list init capacity (2^5 = 32)
#endif
/**
* @brief Array list chunk structure
*/
struct array_list {
struct array_list *next; ///< Pointer to the next chunk
int arc; ///< Length of the chunks array
void *arv[]; ///< The chunks array
};
/**
* @brief Array list iterator structure
*/
struct array_list_iterator {
struct array_list *current_chunk; ///< Pointer to the current chunk
int current; ///< Index of current element in chunk
};
/**
* @brief Insert value into array list.
*
* If *al is NULL, allocate new array list and expand it to the right size.
* The size of the array list grows while beeing used in
* 2^n (1, 1, 2, 4, 8, ...).
*
* \param al Pointer to the pointer of the array list struct
* \param idx Index of the array, at which the element is inserted
* \param elem Pointer to payload/value
*
* \return Nothing
*/
void array_list_set(struct array_list **al, int idx, void *elem);
/**
* @brief Get value from array list.
*
* \param al Pointer to the pointer of the array list struct
* \param idx Index of the array, at which the element is inserted
*
* \return Pointer to the payload/value
*/
void *array_list_get(struct array_list *const *al, int idx);
/**
* @brief Initialize a new array list iterator.
*
* \param al Pointer to the pointer of the array list struct
*
* \return Pointer to the initialized array list iterator
*/
struct array_list_iterator *array_list_iterator_init(struct array_list *const *al);
/**
* @brief Get the next array list element from iterator.
*
* \param it Pointer to the array list iterator struct
*
* \return Pointer to the element
*/
void *array_list_iterator_next(struct array_list_iterator *const *it);
/**
* @brief Frees an array list.
*
* \param al Pointer to the pointer of the array list struct
* \param elem_free Pointer to a function that frees the payload element
*
* \return Nothing
*/
void array_list_free(struct array_list **al, void (*elem_free)(void *));
#endif