Dynamic array datatype.
More...
#include <mm/mm.h>
#include <memory.h>
#include <stdint.h>
Go to the source code of this file.
|
#define | INIT_SIZE_ARRAY 8U |
| The initial size of dynamic arrays expressed in the number of elements.
|
|
#define | dyn_array(type) |
| Declares a dynamic array. More...
|
|
#define | array_items(self) ((self).items) |
| Gets the underlying actual array of elements of a dynamic array. More...
|
|
#define | array_count(self) ((self).count) |
| Gets the count of contained element in a dynamic array. More...
|
|
#define | array_capacity(self) ((self).capacity) |
| Gets the current capacity of a dynamic array. More...
|
|
#define | array_peek(self) (array_items(self)[array_count(self) - 1]) |
| Gets the current capacity of a dynamic array. More...
|
|
#define | array_get_at(self, i) (array_items(self)[(i)]) |
|
#define | array_is_empty(self) (array_count(self) == 0) |
|
#define | array_init(self) |
|
#define | array_fini(self) |
|
#define | array_push(self, elem) |
|
#define | array_pop(self) |
|
#define | array_add_at(self, i, elem) |
|
#define | array_remove_at_lazy(self, i) |
|
#define | array_remove_at(self, i) |
|
#define | array_truncate_first(self, n) |
|
#define | array_shrink(self) |
|
#define | array_expand(self) |
|
|
typedef uint_fast32_t | array_count_t |
| The type used to handle dynamic arrays count of elements and capacity.
|
|
Dynamic array datatype.
Dynamic array datatype
- Copyright
- Copyright (C) 2008-2021 HPDCS Group https://hpdcs.github.io
Definition in file array.h.
◆ array_add_at
#define array_add_at |
( |
|
self, |
|
|
|
i, |
|
|
|
elem |
|
) |
| |
Value:__extension__({ \
array_expand(self); \
array_items(self)[(i)] = (elem); \
array_count(self)++; \
})
Definition at line 94 of file array.h.
◆ array_capacity
#define array_capacity |
( |
|
self | ) |
((self).capacity) |
Gets the current capacity of a dynamic array.
- Parameters
-
self | The target dynamic array |
Definition at line 53 of file array.h.
◆ array_count
#define array_count |
( |
|
self | ) |
((self).count) |
Gets the count of contained element in a dynamic array.
- Parameters
-
self | The target dynamic array |
Definition at line 47 of file array.h.
◆ array_expand
#define array_expand |
( |
|
self | ) |
|
Value:__extension__({ \
array_capacity(self) *= 2; \
); \
} \
})
Definition at line 151 of file array.h.
◆ array_fini
#define array_fini |
( |
|
self | ) |
|
Value:
Definition at line 73 of file array.h.
◆ array_init
#define array_init |
( |
|
self | ) |
|
Value:__extension__({ \
array_count(self) = 0; \
})
Definition at line 65 of file array.h.
◆ array_items
#define array_items |
( |
|
self | ) |
((self).items) |
Gets the underlying actual array of elements of a dynamic array.
- Parameters
-
self | The target dynamic array |
- Returns
- a pointer to the underlying array of elements
You can use the array to directly index items, but do it at your own risk!
Definition at line 41 of file array.h.
◆ array_peek
Gets the current capacity of a dynamic array.
- Parameters
-
self | The target dynamic array |
Definition at line 59 of file array.h.
◆ array_pop
#define array_pop |
( |
|
self | ) |
|
Value:__extension__({ \
array_shrink(self); \
__popval; \
})
Definition at line 85 of file array.h.
◆ array_push
#define array_push |
( |
|
self, |
|
|
|
elem |
|
) |
| |
Value:__extension__({ \
array_expand(self); \
array_count(self)++; \
})
Definition at line 78 of file array.h.
◆ array_remove_at
#define array_remove_at |
( |
|
self, |
|
|
|
i |
|
) |
| |
Value:__extension__({ \
memmove( \
); \
array_shrink(self); \
__rmval; \
})
Definition at line 113 of file array.h.
◆ array_remove_at_lazy
#define array_remove_at_lazy |
( |
|
self, |
|
|
|
i |
|
) |
| |
Value:__extension__({ \
array_shrink(self); \
__rmval; \
})
Definition at line 103 of file array.h.
◆ array_shrink
#define array_shrink |
( |
|
self | ) |
|
Value:__extension__({ \
array_capacity(self) /= 2; \
); \
} \
})
Definition at line 137 of file array.h.
◆ array_truncate_first
#define array_truncate_first |
( |
|
self, |
|
|
|
n |
|
) |
| |
Value:__extension__({ \
array_count(self) -= n; \
memmove( \
); \
})
Definition at line 127 of file array.h.
◆ dyn_array
#define dyn_array |
( |
|
type | ) |
|
Value: struct { \
type *items; \
array_count_t count; \
array_count_t capacity; \
}
Declares a dynamic array.
- Parameters
-
type | The type of the contained elements |
Definition at line 27 of file array.h.