![]() |
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 98 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 |
![]() | |
void * | data |
const struct as_list_hooks_s * | hooks |
![]() | |
cf_atomic32 | count |
bool | free |
enum as_val_t | type |
Private Attributes | |
as_list | _ |
Related Functions | |
(Note that these are not member functions.) | |
int | as_arraylist_append (as_arraylist *list, as_val *value) |
static int | as_arraylist_append_bytes (as_arraylist *list, as_bytes *value) |
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) |
int | as_arraylist_append_str (as_arraylist *list, const char *value) |
static int | as_arraylist_append_string (as_arraylist *list, as_string *value) |
int | as_arraylist_concat (as_arraylist *list, const as_arraylist *list2) |
void | as_arraylist_destroy (as_arraylist *list) |
as_arraylist * | as_arraylist_drop (const as_arraylist *list, uint32_t n) |
bool | as_arraylist_foreach (const as_arraylist *list, as_list_foreach_callback callback, void *udata) |
as_val * | as_arraylist_get (const as_arraylist *list, uint32_t index) |
static as_bytes * | as_arraylist_get_bytes (const as_arraylist *list, uint32_t index) |
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) |
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) |
uint32_t | as_arraylist_hashcode (const as_arraylist *list) |
as_val * | as_arraylist_head (const as_arraylist *list) |
as_arraylist * | as_arraylist_init (as_arraylist *list, uint32_t capacity, uint32_t block_size) |
#define | as_arraylist_inita(__list, __n) |
int | as_arraylist_insert (as_arraylist *list, uint32_t index, as_val *value) |
static int | as_arraylist_insert_bytes (as_arraylist *list, uint32_t index, as_bytes *value) |
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) |
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_arraylist * | as_arraylist_new (uint32_t capacity, uint32_t block_size) |
int | as_arraylist_prepend (as_arraylist *list, as_val *value) |
static int | as_arraylist_prepend_bytes (as_arraylist *list, as_bytes *value) |
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) |
int | as_arraylist_prepend_str (as_arraylist *list, const char *value) |
static int | as_arraylist_prepend_string (as_arraylist *list, as_string *value) |
int | as_arraylist_remove (as_arraylist *list, uint32_t index) |
int | as_arraylist_set (as_arraylist *list, uint32_t index, as_val *value) |
static int | as_arraylist_set_bytes (as_arraylist *list, uint32_t index, as_bytes *value) |
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) |
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) |
uint32_t | as_arraylist_size (const as_arraylist *list) |
as_arraylist * | as_arraylist_tail (const as_arraylist *list) |
as_arraylist * | as_arraylist_take (const as_arraylist *list, uint32_t n) |
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_bytes (as_list *list, as_bytes *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_list * | as_list_cons (as_list *list, bool free, void *data, 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_bytes * | as_list_get_bytes (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_list * | as_list_init (as_list *list, void *data, const as_list_hooks *hooks) |
static int | as_list_insert (as_list *list, uint32_t i, as_val *value) |
static int | as_list_insert_bytes (as_list *list, uint32_t i, as_bytes *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_list * | as_list_new (void *data, const as_list_hooks *hooks) |
static int | as_list_prepend (as_list *list, as_val *value) |
static int | as_list_prepend_bytes (as_list *list, as_bytes *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_bytes (as_list *list, uint32_t i, as_bytes *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 (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_bytes to the end of the list.
list | The list. |
value | The value to prepend. |
Definition at line 742 of file as_arraylist.h.
|
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 714 of file as_arraylist.h.
|
related |
Add an as_list to the end of the list.
list | The list. |
value | The value to prepend. |
Definition at line 756 of file as_arraylist.h.
|
related |
Add an as_map to the end of the list.
list | The list. |
value | The value to prepend. |
Definition at line 770 of file as_arraylist.h.
|
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 728 of file as_arraylist.h.
|
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_bytes value at the specified index of the list.
list | The list. |
index | The index of the element. |
Definition at line 396 of file as_arraylist.h.
|
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 368 of file as_arraylist.h.
|
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 410 of file as_arraylist.h.
|
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 424 of file as_arraylist.h.
|
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 382 of file as_arraylist.h.
|
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 180 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_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 633 of file as_arraylist.h.
|
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 603 of file as_arraylist.h.
|
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 648 of file as_arraylist.h.
|
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 663 of file as_arraylist.h.
|
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 618 of file as_arraylist.h.
|
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_bytes to the beginning of the list.
list | The list. |
value | The value to prepend. |
Definition at line 849 of file as_arraylist.h.
|
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 821 of file as_arraylist.h.
|
related |
Add an as_list to the beginning of the list.
list | The list. |
value | The value to prepend. |
Definition at line 863 of file as_arraylist.h.
|
related |
Add an as_map to the beginning of the list.
list | The list. |
value | The value to prepend. |
Definition at line 877 of file as_arraylist.h.
|
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 835 of file as_arraylist.h.
|
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_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 515 of file as_arraylist.h.
|
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 485 of file as_arraylist.h.
|
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 530 of file as_arraylist.h.
|
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 545 of file as_arraylist.h.
|
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 500 of file as_arraylist.h.
|
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. |
|
private |
as_arraylist is an as_list. You can cast as_arraylist to as_list.
Definition at line 105 of file as_arraylist.h.
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 111 of file as_arraylist.h.
uint32_t as_arraylist::capacity |
The total number elements allocated.
Definition at line 116 of file as_arraylist.h.
as_val** as_arraylist::elements |
The elements of the list.
Definition at line 126 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 132 of file as_arraylist.h.
uint32_t as_arraylist::size |
The number of elements used.
Definition at line 121 of file as_arraylist.h.