![]() |
An dynamic array implementation for as_list.
as_arryalist can either be initialize on the stack or the heap.
For stack allocation, you have two choices:
as_arraylist_init()
- uses cf_malloc()
to initialize the internal storage on the heap.as_arraylist_inita()
- uses alloca()
to initialize the internal storage on the stack.The key differences between the two is as_arraylist_inita()
can't be dynamically resized and is solely on the stack.
The following is using a as_arraylist_inita()
:
You will notice that the code is quite similar to as_arraylist_init()
:
If you need a new heap allocated list, then use as_arraylist_new()
:
When you are finished using the list, then you should release the list and associated resources, using as_arraylist_destroy()
:
The as_arraylist
is a subtype of as_list
. This allows you to alternatively use as_list
functions, by typecasting as_arraylist
to as_list
.
Each of the as_list
functions proxy to the as_arraylist
functions. So, calling as_list_destroy()
is equivalent to calling as_arraylist_destroy()
.
Definition at line 95 of file as_arraylist.h.
#include "as_arraylist.h"
Data Fields | |
uint32_t | block_size |
uint32_t | capacity |
as_val ** | elements |
bool | free |
uint32_t | size |
![]() | |
uint32_t | flags |
const struct as_list_hooks_s * | hooks |
![]() | |
uint32_t | count |
bool | free |
as_val_t | type |
Related Symbols | |
(Note that these are not member symbols.) | |
AS_EXTERN int | as_arraylist_append (as_arraylist *list, as_val *value) |
static int | as_arraylist_append_as_double (as_arraylist *list, as_double *value) |
static int | as_arraylist_append_bytes (as_arraylist *list, as_bytes *value) |
AS_EXTERN int | as_arraylist_append_double (as_arraylist *list, double value) |
AS_EXTERN int | as_arraylist_append_int64 (as_arraylist *list, int64_t value) |
static int | as_arraylist_append_integer (as_arraylist *list, as_integer *value) |
static int | as_arraylist_append_list (as_arraylist *list, as_list *value) |
static int | as_arraylist_append_map (as_arraylist *list, as_map *value) |
AS_EXTERN int | as_arraylist_append_str (as_arraylist *list, const char *value) |
static int | as_arraylist_append_string (as_arraylist *list, as_string *value) |
AS_EXTERN int | as_arraylist_concat (as_arraylist *list, const as_arraylist *list2) |
AS_EXTERN void | as_arraylist_destroy (as_arraylist *list) |
AS_EXTERN as_arraylist * | as_arraylist_drop (const as_arraylist *list, uint32_t n) |
AS_EXTERN bool | as_arraylist_foreach (const as_arraylist *list, as_list_foreach_callback callback, void *udata) |
AS_EXTERN as_val * | as_arraylist_get (const as_arraylist *list, uint32_t index) |
static as_double * | as_arraylist_get_as_double (const as_arraylist *list, uint32_t index) |
static as_bytes * | as_arraylist_get_bytes (const as_arraylist *list, uint32_t index) |
AS_EXTERN double | as_arraylist_get_double (const as_arraylist *list, uint32_t index) |
AS_EXTERN int64_t | as_arraylist_get_int64 (const as_arraylist *list, uint32_t index) |
static as_integer * | as_arraylist_get_integer (const as_arraylist *list, uint32_t index) |
static as_list * | as_arraylist_get_list (const as_arraylist *list, uint32_t index) |
static as_map * | as_arraylist_get_map (const as_arraylist *list, uint32_t index) |
AS_EXTERN char * | as_arraylist_get_str (const as_arraylist *list, uint32_t index) |
static as_string * | as_arraylist_get_string (const as_arraylist *list, uint32_t index) |
AS_EXTERN uint32_t | as_arraylist_hashcode (const as_arraylist *list) |
AS_EXTERN as_val * | as_arraylist_head (const as_arraylist *list) |
AS_EXTERN as_arraylist * | as_arraylist_init (as_arraylist *list, uint32_t capacity, uint32_t block_size) |
#define | as_arraylist_inita(__list, __n) |
AS_EXTERN int | as_arraylist_insert (as_arraylist *list, uint32_t index, as_val *value) |
static int | as_arraylist_insert_as_double (as_arraylist *list, uint32_t index, as_double *value) |
static int | as_arraylist_insert_bytes (as_arraylist *list, uint32_t index, as_bytes *value) |
AS_EXTERN int | as_arraylist_insert_double (as_arraylist *list, uint32_t index, double value) |
AS_EXTERN int | as_arraylist_insert_int64 (as_arraylist *list, uint32_t index, int64_t value) |
static int | as_arraylist_insert_integer (as_arraylist *list, uint32_t index, as_integer *value) |
static int | as_arraylist_insert_list (as_arraylist *list, uint32_t index, as_list *value) |
static int | as_arraylist_insert_map (as_arraylist *list, uint32_t index, as_map *value) |
AS_EXTERN int | as_arraylist_insert_str (as_arraylist *list, uint32_t index, const char *value) |
static int | as_arraylist_insert_string (as_arraylist *list, uint32_t index, as_string *value) |
AS_EXTERN as_arraylist * | as_arraylist_new (uint32_t capacity, uint32_t block_size) |
AS_EXTERN int | as_arraylist_prepend (as_arraylist *list, as_val *value) |
static int | as_arraylist_prepend_as_double (as_arraylist *list, as_double *value) |
static int | as_arraylist_prepend_bytes (as_arraylist *list, as_bytes *value) |
AS_EXTERN int | as_arraylist_prepend_double (as_arraylist *list, double value) |
AS_EXTERN int | as_arraylist_prepend_int64 (as_arraylist *list, int64_t value) |
static int | as_arraylist_prepend_integer (as_arraylist *list, as_integer *value) |
static int | as_arraylist_prepend_list (as_arraylist *list, as_list *value) |
static int | as_arraylist_prepend_map (as_arraylist *list, as_map *value) |
AS_EXTERN int | as_arraylist_prepend_str (as_arraylist *list, const char *value) |
static int | as_arraylist_prepend_string (as_arraylist *list, as_string *value) |
AS_EXTERN int | as_arraylist_remove (as_arraylist *list, uint32_t index) |
AS_EXTERN int | as_arraylist_set (as_arraylist *list, uint32_t index, as_val *value) |
static int | as_arraylist_set_as_double (as_arraylist *list, uint32_t index, as_double *value) |
static int | as_arraylist_set_bytes (as_arraylist *list, uint32_t index, as_bytes *value) |
AS_EXTERN int | as_arraylist_set_double (as_arraylist *list, uint32_t index, double value) |
AS_EXTERN int | as_arraylist_set_int64 (as_arraylist *list, uint32_t index, int64_t value) |
static int | as_arraylist_set_integer (as_arraylist *list, uint32_t index, as_integer *value) |
static int | as_arraylist_set_list (as_arraylist *list, uint32_t index, as_list *value) |
static int | as_arraylist_set_map (as_arraylist *list, uint32_t index, as_map *value) |
AS_EXTERN int | as_arraylist_set_str (as_arraylist *list, uint32_t index, const char *value) |
static int | as_arraylist_set_string (as_arraylist *list, uint32_t index, as_string *value) |
AS_EXTERN uint32_t | as_arraylist_size (const as_arraylist *list) |
AS_EXTERN as_arraylist * | as_arraylist_tail (const as_arraylist *list) |
AS_EXTERN as_arraylist * | as_arraylist_take (const as_arraylist *list, uint32_t n) |
AS_EXTERN int | as_arraylist_trim (as_arraylist *list, uint32_t index) |
![]() | |
static int | as_list_append (as_list *list, as_val *value) |
static int | as_list_append_as_double (as_list *list, as_double *value) |
static int | as_list_append_bytes (as_list *list, as_bytes *value) |
static int | as_list_append_double (as_list *list, double value) |
static int | as_list_append_int64 (as_list *list, int64_t value) |
static int | as_list_append_integer (as_list *list, as_integer *value) |
static int | as_list_append_list (as_list *list, as_list *value) |
static int | as_list_append_map (as_list *list, struct as_map_s *value) |
static int | as_list_append_str (as_list *list, const char *value) |
static int | as_list_append_string (as_list *list, as_string *value) |
static int | as_list_concat (as_list *list, const as_list *list2) |
AS_EXTERN as_list * | as_list_cons (as_list *list, bool free, const as_list_hooks *hooks) |
static void | as_list_destroy (as_list *list) |
static as_list * | as_list_drop (const as_list *list, uint32_t n) |
static bool | as_list_foreach (const as_list *list, as_list_foreach_callback callback, void *udata) |
static as_list * | as_list_fromval (as_val *v) |
static as_val * | as_list_get (const as_list *list, uint32_t i) |
static as_double * | as_list_get_as_double (const as_list *list, uint32_t i) |
static as_bytes * | as_list_get_bytes (const as_list *list, uint32_t i) |
static double | as_list_get_double (const as_list *list, uint32_t i) |
static int64_t | as_list_get_int64 (const as_list *list, uint32_t i) |
static as_integer * | as_list_get_integer (const as_list *list, uint32_t i) |
static as_list * | as_list_get_list (const as_list *list, uint32_t i) |
static struct as_map_s * | as_list_get_map (const as_list *list, uint32_t i) |
static char * | as_list_get_str (const as_list *list, uint32_t i) |
static as_string * | as_list_get_string (const as_list *list, uint32_t i) |
static uint32_t | as_list_hashcode (as_list *list) |
static as_val * | as_list_head (const as_list *list) |
AS_EXTERN as_list * | as_list_init (as_list *list, const as_list_hooks *hooks) |
static int | as_list_insert (as_list *list, uint32_t i, as_val *value) |
static int | as_list_insert_as_double (as_list *list, uint32_t i, as_double *value) |
static int | as_list_insert_bytes (as_list *list, uint32_t i, as_bytes *value) |
static int | as_list_insert_double (as_list *list, uint32_t i, double value) |
static int | as_list_insert_int64 (as_list *list, uint32_t i, int64_t value) |
static int | as_list_insert_integer (as_list *list, uint32_t i, as_integer *value) |
static int | as_list_insert_list (as_list *list, uint32_t i, as_list *value) |
static int | as_list_insert_map (as_list *list, uint32_t i, struct as_map_s *value) |
static int | as_list_insert_str (as_list *list, uint32_t i, const char *value) |
static int | as_list_insert_string (as_list *list, uint32_t i, as_string *value) |
static union as_list_iterator_u * | as_list_iterator_init (union as_list_iterator_u *it, const as_list *list) |
static union as_list_iterator_u * | as_list_iterator_new (const as_list *list) |
AS_EXTERN as_list * | as_list_new (const as_list_hooks *hooks) |
static int | as_list_prepend (as_list *list, as_val *value) |
static int | as_list_prepend_as_double (as_list *list, as_double *value) |
static int | as_list_prepend_bytes (as_list *list, as_bytes *value) |
static int | as_list_prepend_double (as_list *list, double value) |
static int | as_list_prepend_int64 (as_list *list, int64_t value) |
static int | as_list_prepend_integer (as_list *list, as_integer *value) |
static int | as_list_prepend_list (as_list *list, as_list *value) |
static int | as_list_prepend_map (as_list *list, struct as_map_s *value) |
static int | as_list_prepend_str (as_list *list, const char *value) |
static int | as_list_prepend_string (as_list *list, as_string *value) |
static int | as_list_remove (as_list *list, uint32_t index) |
static int | as_list_set (as_list *list, uint32_t i, as_val *value) |
static int | as_list_set_as_double (as_list *list, uint32_t i, as_double *value) |
static int | as_list_set_bytes (as_list *list, uint32_t i, as_bytes *value) |
static int | as_list_set_double (as_list *list, uint32_t i, double value) |
static int | as_list_set_int64 (as_list *list, uint32_t i, int64_t value) |
static int | as_list_set_integer (as_list *list, uint32_t i, as_integer *value) |
static int | as_list_set_list (as_list *list, uint32_t i, as_list *value) |
static int | as_list_set_map (as_list *list, uint32_t i, struct as_map_s *value) |
static int | as_list_set_str (as_list *list, uint32_t i, const char *value) |
static int | as_list_set_string (as_list *list, uint32_t i, as_string *value) |
static uint32_t | as_list_size (const as_list *list) |
static as_list * | as_list_tail (const as_list *list) |
static as_list * | as_list_take (const as_list *list, uint32_t n) |
static as_val * | as_list_toval (as_list *list) |
static int | as_list_trim (as_list *list, uint32_t index) |
|
related |
Add the value to the end of the list.
list | The list. |
value | The value to prepend. |
|
related |
Add an as_double to the end of the list.
list | The list. |
value | The value to prepend. |
Definition at line 862 of file as_arraylist.h.
References as_arraylist_append().
|
related |
Add an as_bytes to the end of the list.
list | The list. |
value | The value to prepend. |
Definition at line 892 of file as_arraylist.h.
References as_arraylist_append().
|
related |
Add a double to the end of the list.
list | The list. |
value | The value to prepend. |
|
related |
Add an int64_t to the end of the list.
list | The list. |
value | The value to prepend. |
|
related |
Add an as_integer to the end of the list.
list | The list. |
value | The value to prepend. |
Definition at line 847 of file as_arraylist.h.
References as_arraylist_append().
|
related |
Add an as_list to the end of the list.
list | The list. |
value | The value to prepend. |
Definition at line 907 of file as_arraylist.h.
References as_arraylist_append().
|
related |
Add an as_map to the end of the list.
list | The list. |
value | The value to prepend. |
Definition at line 922 of file as_arraylist.h.
References as_arraylist_append().
|
related |
Add a NULL-terminated string to the end of the list.
list | The list. |
value | The value to prepend. |
|
related |
Add an as_string to the end of the list.
list | The list. |
value | The value to prepend. |
Definition at line 877 of file as_arraylist.h.
References as_arraylist_append().
|
related |
Append all elements of list2, in order, to list. No new list object is created.
list | The list to append to. |
list2 | The list from which to append. |
|
related |
Destoy the list and release resources.
list | The list to destroy. |
|
related |
Return a new list with the first n elements removed.
list | The list. |
n | The number of elements to remove. |
|
related |
Call the callback function for each element in the list.
list | The list to iterate. |
callback | The function to call for each element in the list. |
udata | User-data to be sent to the callback. |
|
related |
Return the value at the specified index.
list | The list. |
index | The index of the element. |
|
related |
Return an as_double value at the specified index of the list.
list | The list. |
index | The index of the element. |
Definition at line 407 of file as_arraylist.h.
References as_arraylist_get(), and as_double_fromval().
|
related |
Return an as_bytes value at the specified index of the list.
list | The list. |
index | The index of the element. |
Definition at line 437 of file as_arraylist.h.
References as_arraylist_get(), and as_bytes_fromval().
|
related |
Return a double value at the specified index of the list.
list | The list. |
index | The index of the element. |
|
related |
Return an int64_t value at the specified index of the list.
list | The list. |
index | The index of the element. |
|
related |
Return an as_integer value at the specified index of the list.
list | The list. |
index | The index of the element. |
Definition at line 392 of file as_arraylist.h.
References as_arraylist_get(), and as_integer_fromval().
|
related |
Return an as_list value at the specified index of the list.
list | The list. |
index | The index of the element. |
Definition at line 452 of file as_arraylist.h.
References as_arraylist_get(), and as_list_fromval().
|
related |
Return an as_map value at the specified index of the list.
list | The list. |
index | The index of the element. |
Definition at line 467 of file as_arraylist.h.
References as_arraylist_get(), and as_map_fromval().
|
related |
Return a NULL-terminated value at the specified index of the list.
list | The list. |
index | The index of the element. |
|
related |
Return an as_string value at the specified index of the list.
list | The list. |
index | The index of the element. |
Definition at line 422 of file as_arraylist.h.
References as_arraylist_get(), and as_string_fromval().
|
related |
The hash value of the list.
list | The list. |
|
related |
Get the first element of the list.
list | The list to get the first element from. |
|
related |
Initialize a stack allocated as_arraylist, with element storage on the heap.
This differs from as_arraylist_inita(), in that as_arraylist_inita() allocates element storage on the stack.
list | The as_list to initialize |
capacity | The number of elements to allocate to the list. |
block_size | The number of elements to grow the list by, when the capacity has been reached. |
|
related |
Initialize a stack allocated as_arraylist, with element storage on the stack.
This differs from as_arraylist_init(), in that as_arraylist_init() allocates element storage on the heap.
__list | The as_list to initialize |
__n | The number of elements to allocate to the list. |
Definition at line 177 of file as_arraylist.h.
|
related |
Insert a value at the specified index of the list.
Any elements at and beyond specified index will be shifted so their indexes increase by 1. It's ok to insert beyond the current end of the list.
list | The list. |
index | Position in the list. |
value | The value to insert at the given index. |
|
related |
Insert an as_double value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to insert at the given index. |
Definition at line 716 of file as_arraylist.h.
References as_arraylist_insert().
|
related |
Insert an as_bytes value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to insert at the given index. |
Definition at line 748 of file as_arraylist.h.
References as_arraylist_insert().
|
related |
Insert a double value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to insert at the given index. |
|
related |
Insert an int64_t value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to insert at the given index. |
|
related |
Insert an as_integer value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to insert at the given index. |
Definition at line 700 of file as_arraylist.h.
References as_arraylist_insert().
|
related |
Insert an as_list value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to insert at the given index. |
Definition at line 764 of file as_arraylist.h.
References as_arraylist_insert().
|
related |
Insert an as_map value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to insert at the given index. |
Definition at line 780 of file as_arraylist.h.
References as_arraylist_insert().
|
related |
Insert a NULL-terminated string value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to insert at the given index. |
|
related |
Insert an as_string value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to insert at the given index. |
Definition at line 732 of file as_arraylist.h.
References as_arraylist_insert().
|
related |
Create and initialize a heap allocated list as as_arraylist.
capacity | The number of elements to allocate to the list. |
block_size | The number of elements to grow the list by, when the capacity has been reached. |
|
related |
Add the value to the beginning of the list.
list | The list. |
value | The value to prepend. |
|
related |
Add an as_double to the beginning of the list.
list | The list. |
value | The value to prepend. |
Definition at line 1004 of file as_arraylist.h.
References as_arraylist_prepend().
|
related |
Add an as_bytes to the beginning of the list.
list | The list. |
value | The value to prepend. |
Definition at line 1032 of file as_arraylist.h.
References as_arraylist_prepend().
|
related |
Add a double to the beginning of the list.
list | The list. |
value | The value to prepend. |
|
related |
Add an int64_t to the beginning of the list.
list | The list. |
value | The value to prepend. |
|
related |
Add an as_integer to the beginning of the list.
list | The list. |
value | The value to prepend. |
Definition at line 989 of file as_arraylist.h.
References as_arraylist_prepend().
|
related |
Add an as_list to the beginning of the list.
list | The list. |
value | The value to prepend. |
Definition at line 1046 of file as_arraylist.h.
References as_arraylist_prepend().
|
related |
Add an as_map to the beginning of the list.
list | The list. |
value | The value to prepend. |
Definition at line 1060 of file as_arraylist.h.
References as_arraylist_prepend().
|
related |
Add a NULL-terminated string to the beginning of the list.
list | The list. |
value | The value to prepend. |
|
related |
Add an as_string to the beginning of the list.
list | The list. |
value | The value to prepend. |
Definition at line 1018 of file as_arraylist.h.
References as_arraylist_prepend().
|
related |
Remove element at specified index.
Any elements beyond specified index will be shifted so their indexes decrease by 1. The element at specified index will be destroyed.
list | The list. |
index | The index of the element to remove. |
|
related |
Set a value at the specified index of the list.
Notice that in order to maintain proper object/memory management, we just first destroy (as_val_destroy()) the old object at element position(i) before assigning the new element. Also note that the object at element position (i) is assumed to exist, so all element positions must be appropriately initialized to zero.
list | The list. |
index | Position in the list. |
value | The value to set at the given index. |
|
related |
Set an as_double value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to set at the given index. |
Definition at line 561 of file as_arraylist.h.
References as_arraylist_set().
|
related |
Set an as_bytes value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to set at the given index. |
Definition at line 593 of file as_arraylist.h.
References as_arraylist_set().
|
related |
Set a double value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to set at the given index. |
|
related |
Set an int64_t value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to set at the given index. |
|
related |
Set an as_integer value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to set at the given index. |
Definition at line 545 of file as_arraylist.h.
References as_arraylist_set().
|
related |
Set an as_list value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to set at the given index. |
Definition at line 609 of file as_arraylist.h.
References as_arraylist_set().
|
related |
Set an as_map value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to set at the given index. |
Definition at line 625 of file as_arraylist.h.
References as_arraylist_set().
|
related |
Set a NULL-terminated string value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to set at the given index. |
|
related |
Set an as_string value at the specified index of the list.
list | The list. |
index | Position in the list. |
value | The value to set at the given index. |
Definition at line 577 of file as_arraylist.h.
References as_arraylist_set().
|
related |
The number of elements in the list.
list | The list. |
|
related |
Returns a new list containing all elements other than the head
list | The list to get the elements from. |
|
related |
Return a new list containing the first n elements.
list | The list. |
n | The number of elements to take. |
|
related |
Delete (and destroy) all elements at and beyond specified index. Capacity is not reduced.
list | The list to trim. |
index | The index from which to trim. |
uint32_t as_arraylist::block_size |
Number of elements to add, when capacity is reached. If 0 (zero), then capacity can't be expanded.
Definition at line 108 of file as_arraylist.h.
uint32_t as_arraylist::capacity |
The total number elements allocated.
Definition at line 113 of file as_arraylist.h.
as_val** as_arraylist::elements |
The elements of the list.
Definition at line 123 of file as_arraylist.h.
bool as_arraylist::free |
If true, then as_arraylist.elements will be freed when as_arraylist_destroy() is called.
Definition at line 129 of file as_arraylist.h.
uint32_t as_arraylist::size |
The number of elements used.
Definition at line 118 of file as_arraylist.h.