-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynarray.h
More file actions
66 lines (63 loc) · 1.78 KB
/
Copy pathdynarray.h
File metadata and controls
66 lines (63 loc) · 1.78 KB
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
/**
* @mainpage
* @author Grant S Ralls
*
* @ref dynarray.h
*/
/**
* @file dynarray.h
*
* This header file defines the publically available functions
*/
#ifndef DYNARRAY
#define DYNARRAY
#include <stdlib.h>
/**
* @brief Saves stats about the array for memory handling
*/
typedef struct {
/// The size of a single entry in bytes
size_t item_size;
/// The number of available "slots" in the array
size_t capacity;
/// The number of currently filled "slots" in the array
size_t length;
} array_info;
/**
* @brief Creates a dynamic array
* @param capacity The initial number of available slots for the array
* @param item_size The size, in bytes, of the item that will be stored in this array
* @return A pointer to the array
*/
void* dynarray_construct(size_t capacity, size_t item_size);
/**
* @brief Retrieves the array information of a given array.
* @param Array a pointer to a dynamic array
* @return A pointer to a @ref array_info "array_info block"
*/
array_info* dynarray_array_info(void* array);
/**
* @brief Inserts an item in a specific slot, overwriting any existing item
* @param array A pointer to the array
* @param item The item to be inserted
* @param pos The, zero-indexed, position to place the item
*/
void dynarray_insert_at(void* array, void* item, int pos);
/**
* @brief Gets the length of the array
* @param array A pointer to the array
* @return The length of the array
*/
size_t dynarray_length(void* array);
/**
* @brief Pushes to the back of the array length
* @param array A pointer to the array
* @param item A pointer to the item to insert
*/
void dynarray_push_back(void* array, void* item);
/**
* @brief Removes an item from the back of the array
* @param array A pointer to the array
*/
void dynarray_pop_back(void* array);
#endif