All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Fields | Private Attributes | Related Functions
as_arraylist Struct Reference

Detailed Description

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:

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():

as_arraylist_init(&list, 2, 0);

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 94 of file as_arraylist.h.

#include "as_arraylist.h"

+ Inheritance diagram for as_arraylist:
+ Collaboration diagram for as_arraylist:

Data Fields

uint32_t block_size
 
uint32_t capacity
 
as_val ** elements
 
bool free
 
uint32_t size
 
- Data Fields inherited from as_list
void * data
 
struct as_list_hooks_s * hooks
 
- Data Fields inherited from as_val
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_arraylistas_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_valas_arraylist_get (const as_arraylist *list, uint32_t index)
 
static as_bytesas_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_integeras_arraylist_get_integer (const as_arraylist *list, uint32_t index)
 
static as_listas_arraylist_get_list (const as_arraylist *list, uint32_t index)
 
static as_mapas_arraylist_get_map (const as_arraylist *list, uint32_t index)
 
char * as_arraylist_get_str (const as_arraylist *list, uint32_t index)
 
static as_stringas_arraylist_get_string (const as_arraylist *list, uint32_t index)
 
uint32_t as_arraylist_hashcode (const as_arraylist *list)
 
as_valas_arraylist_head (const as_arraylist *list)
 
as_arraylistas_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_arraylistas_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_arraylistas_arraylist_tail (const as_arraylist *list)
 
as_arraylistas_arraylist_take (const as_arraylist *list, uint32_t n)
 
int as_arraylist_trim (as_arraylist *list, uint32_t index)
 

Friends And Related Function Documentation

int as_arraylist_append ( as_arraylist list,
as_val value 
)
related

Add the value to the end of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_append_bytes ( as_arraylist list,
as_bytes value 
)
related

Add an as_bytes to the end of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 738 of file as_arraylist.h.

int as_arraylist_append_int64 ( as_arraylist list,
int64_t  value 
)
related

Add an int64_t to the end of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_append_integer ( as_arraylist list,
as_integer value 
)
related

Add an as_integer to the end of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 710 of file as_arraylist.h.

static int as_arraylist_append_list ( as_arraylist list,
as_list value 
)
related

Add an as_list to the end of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 752 of file as_arraylist.h.

static int as_arraylist_append_map ( as_arraylist list,
as_map value 
)
related

Add an as_map to the end of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 766 of file as_arraylist.h.

int as_arraylist_append_str ( as_arraylist list,
const char *  value 
)
related

Add a NULL-terminated string to the end of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_append_string ( as_arraylist list,
as_string value 
)
related

Add an as_string to the end of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 724 of file as_arraylist.h.

int as_arraylist_concat ( as_arraylist list,
const as_arraylist list2 
)
related

Append all elements of list2, in order, to list. No new list object is created.

Parameters
listThe list to append to.
list2The list from which to append.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
void as_arraylist_destroy ( as_arraylist list)
related

Destoy the list and release resources.

Parameters
listThe list to destroy.
as_arraylist * as_arraylist_drop ( const as_arraylist list,
uint32_t  n 
)
related

Return a new list with the first n elements removed.

Parameters
listThe list.
nThe number of elements to remove.
Returns
A new list of all elements after the first n elements.
bool as_arraylist_foreach ( const as_arraylist list,
as_list_foreach_callback  callback,
void *  udata 
)
related

Call the callback function for each element in the list.

Parameters
listThe list to iterate.
callbackThe function to call for each element in the list.
udataUser-data to be sent to the callback.
Returns
true if iteration completes fully. false if iteration was aborted.
as_val * as_arraylist_get ( const as_arraylist list,
uint32_t  index 
)
related

Return the value at the specified index.

Parameters
listThe list.
indexThe index of the element.
Returns
The value at given index, if it exists. Otherwise NULL.
static as_bytes * as_arraylist_get_bytes ( const as_arraylist list,
uint32_t  index 
)
related

Return an as_bytes value at the specified index of the list.

Parameters
listThe list.
indexThe index of the element.
Returns
The value at given index, if it exists. Otherwise NULL.

Definition at line 392 of file as_arraylist.h.

int64_t as_arraylist_get_int64 ( const as_arraylist list,
uint32_t  index 
)
related

Return an int64_t value at the specified index of the list.

Parameters
listThe list.
indexThe index of the element.
Returns
The value at given index, if it exists. Otherwise NULL.
static as_integer * as_arraylist_get_integer ( const as_arraylist list,
uint32_t  index 
)
related

Return an as_integer value at the specified index of the list.

Parameters
listThe list.
indexThe index of the element.
Returns
The value at given index, if it exists. Otherwise NULL.

Definition at line 364 of file as_arraylist.h.

static as_list * as_arraylist_get_list ( const as_arraylist list,
uint32_t  index 
)
related

Return an as_list value at the specified index of the list.

Parameters
listThe list.
indexThe index of the element.
Returns
The value at given index, if it exists. Otherwise NULL.

Definition at line 406 of file as_arraylist.h.

static as_map * as_arraylist_get_map ( const as_arraylist list,
uint32_t  index 
)
related

Return an as_map value at the specified index of the list.

Parameters
listThe list.
indexThe index of the element.
Returns
The value at given index, if it exists. Otherwise NULL.

Definition at line 420 of file as_arraylist.h.

char * as_arraylist_get_str ( const as_arraylist list,
uint32_t  index 
)
related

Return a NULL-terminated value at the specified index of the list.

Parameters
listThe list.
indexThe index of the element.
Returns
The value at given index, if it exists. Otherwise NULL.
static as_string * as_arraylist_get_string ( const as_arraylist list,
uint32_t  index 
)
related

Return an as_string value at the specified index of the list.

Parameters
listThe list.
indexThe index of the element.
Returns
The value at given index, if it exists. Otherwise NULL.

Definition at line 378 of file as_arraylist.h.

uint32_t as_arraylist_hashcode ( const as_arraylist list)
related

The hash value of the list.

Parameters
listThe list.
Returns
The hash value of the list.
as_val * as_arraylist_head ( const as_arraylist list)
related

Get the first element of the list.

Parameters
listThe list to get the first element from.
Returns
The first element of the list. Otherwise NULL.
as_arraylist * as_arraylist_init ( as_arraylist list,
uint32_t  capacity,
uint32_t  block_size 
)
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.

Parameters
listThe as_list to initialize
capacityThe number of elements to allocate to the list.
block_sizeThe number of elements to grow the list by, when the capacity has been reached.
Returns
On success, the initialize list. Otherwise NULL.
#define as_arraylist_inita (   __list,
  __n 
)
related
Value:
as_arraylist_init((__list), 0, 0);\
(__list)->free = false;\
(__list)->capacity = __n;\
(__list)->size = 0;\
(__list)->elements = (as_val **) alloca(sizeof(as_val *) * __n);

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.

Parameters
__listThe as_list to initialize
__nThe number of elements to allocate to the list.
Returns
On success, the initialize list. Otherwise NULL.

Definition at line 176 of file as_arraylist.h.

int as_arraylist_insert ( as_arraylist list,
uint32_t  index,
as_val value 
)
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.

Parameters
listThe list.
indexPosition in the list.
valueThe value to insert at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_insert_bytes ( as_arraylist list,
uint32_t  index,
as_bytes value 
)
related

Insert an as_bytes value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to insert at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 629 of file as_arraylist.h.

int as_arraylist_insert_int64 ( as_arraylist list,
uint32_t  index,
int64_t  value 
)
related

Insert an int64_t value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to insert at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_insert_integer ( as_arraylist list,
uint32_t  index,
as_integer value 
)
related

Insert an as_integer value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to insert at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 599 of file as_arraylist.h.

static int as_arraylist_insert_list ( as_arraylist list,
uint32_t  index,
as_list value 
)
related

Insert an as_list value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to insert at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 644 of file as_arraylist.h.

static int as_arraylist_insert_map ( as_arraylist list,
uint32_t  index,
as_map value 
)
related

Insert an as_map value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to insert at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 659 of file as_arraylist.h.

int as_arraylist_insert_str ( as_arraylist list,
uint32_t  index,
const char *  value 
)
related

Insert a NULL-terminated string value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to insert at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_insert_string ( as_arraylist list,
uint32_t  index,
as_string value 
)
related

Insert an as_string value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to insert at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 614 of file as_arraylist.h.

as_arraylist * as_arraylist_new ( uint32_t  capacity,
uint32_t  block_size 
)
related

Create and initialize a heap allocated list as as_arraylist.

Parameters
capacityThe number of elements to allocate to the list.
block_sizeThe number of elements to grow the list by, when the capacity has been reached.
Returns
On success, the new list. Otherwise NULL.
int as_arraylist_prepend ( as_arraylist list,
as_val value 
)
related

Add the value to the beginning of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_prepend_bytes ( as_arraylist list,
as_bytes value 
)
related

Add an as_bytes to the beginning of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 845 of file as_arraylist.h.

int as_arraylist_prepend_int64 ( as_arraylist list,
int64_t  value 
)
related

Add an int64_t to the beginning of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_prepend_integer ( as_arraylist list,
as_integer value 
)
related

Add an as_integer to the beginning of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 817 of file as_arraylist.h.

static int as_arraylist_prepend_list ( as_arraylist list,
as_list value 
)
related

Add an as_list to the beginning of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 859 of file as_arraylist.h.

static int as_arraylist_prepend_map ( as_arraylist list,
as_map value 
)
related

Add an as_map to the beginning of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 873 of file as_arraylist.h.

int as_arraylist_prepend_str ( as_arraylist list,
const char *  value 
)
related

Add a NULL-terminated string to the beginning of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_prepend_string ( as_arraylist list,
as_string value 
)
related

Add an as_string to the beginning of the list.

Parameters
listThe list.
valueThe value to prepend.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 831 of file as_arraylist.h.

int as_arraylist_remove ( as_arraylist list,
uint32_t  index 
)
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.

Parameters
listThe list.
indexThe index of the element to remove.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
int as_arraylist_set ( as_arraylist list,
uint32_t  index,
as_val value 
)
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.

Parameters
listThe list.
indexPosition in the list.
valueThe value to set at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_set_bytes ( as_arraylist list,
uint32_t  index,
as_bytes value 
)
related

Set an as_bytes value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to set at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 511 of file as_arraylist.h.

int as_arraylist_set_int64 ( as_arraylist list,
uint32_t  index,
int64_t  value 
)
related

Set an int64_t value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to set at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_set_integer ( as_arraylist list,
uint32_t  index,
as_integer value 
)
related

Set an as_integer value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to set at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 481 of file as_arraylist.h.

static int as_arraylist_set_list ( as_arraylist list,
uint32_t  index,
as_list value 
)
related

Set an as_list value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to set at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 526 of file as_arraylist.h.

static int as_arraylist_set_map ( as_arraylist list,
uint32_t  index,
as_map value 
)
related

Set an as_map value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to set at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 541 of file as_arraylist.h.

int as_arraylist_set_str ( as_arraylist list,
uint32_t  index,
const char *  value 
)
related

Set a NULL-terminated string value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to set at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.
static int as_arraylist_set_string ( as_arraylist list,
uint32_t  index,
as_string value 
)
related

Set an as_string value at the specified index of the list.

Parameters
listThe list.
indexPosition in the list.
valueThe value to set at the given index.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Definition at line 496 of file as_arraylist.h.

uint32_t as_arraylist_size ( const as_arraylist list)
related

The number of elements in the list.

Parameters
listThe list.
Returns
The number of elements in the list.
as_arraylist * as_arraylist_tail ( const as_arraylist list)
related

Returns a new list containing all elements other than the head

Parameters
listThe list to get the elements from.
Returns
A new list of all elements after the first element.
as_arraylist * as_arraylist_take ( const as_arraylist list,
uint32_t  n 
)
related

Return a new list containing the first n elements.

Parameters
listThe list.
nThe number of elements to take.
Returns
A new list of the first n elements.
int as_arraylist_trim ( as_arraylist list,
uint32_t  index 
)
related

Delete (and destroy) all elements at and beyond specified index. Capacity is not reduced.

Parameters
listThe list to trim.
indexThe index from which to trim.
Returns
AS_ARRAYLIST_OK on success. Otherwise an error occurred.

Field Documentation

as_list as_arraylist::_
private

as_arraylist is an as_list. You can cast as_arraylist to as_list.

Definition at line 101 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 107 of file as_arraylist.h.

uint32_t as_arraylist::capacity

The total number elements allocated.

Definition at line 112 of file as_arraylist.h.

as_val** as_arraylist::elements

The elements of the list.

Definition at line 122 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 128 of file as_arraylist.h.

uint32_t as_arraylist::size

The number of elements used.

Definition at line 117 of file as_arraylist.h.


The documentation for this struct was generated from the following file: