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 99 of file modules/common/src/include/aerospike/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)
 
int as_arraylist_append_bytes (as_arraylist *list, as_bytes *value)
 
int as_arraylist_append_int64 (as_arraylist *list, int64_t value)
 
int as_arraylist_append_integer (as_arraylist *list, as_integer *value)
 
int as_arraylist_append_list (as_arraylist *list, as_list *value)
 
int as_arraylist_append_map (as_arraylist *list, as_map *value)
 
int as_arraylist_append_str (as_arraylist *list, const char *value)
 
int as_arraylist_append_string (as_arraylist *list, as_string *value)
 
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, const uint32_t index)
 
as_bytesas_arraylist_get_bytes (const as_arraylist *list, const uint32_t index)
 
int64_t as_arraylist_get_int64 (const as_arraylist *list, const uint32_t index)
 
as_integeras_arraylist_get_integer (const as_arraylist *list, const uint32_t index)
 
as_listas_arraylist_get_list (const as_arraylist *list, const uint32_t index)
 
as_mapas_arraylist_get_map (const as_arraylist *list, const uint32_t index)
 
char * as_arraylist_get_str (const as_arraylist *list, const uint32_t index)
 
as_stringas_arraylist_get_string (const as_arraylist *list, const 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)
 
as_arraylistas_arraylist_new (uint32_t capacity, uint32_t block_size)
 
int as_arraylist_prepend (as_arraylist *list, as_val *value)
 
int as_arraylist_prepend_bytes (as_arraylist *list, as_bytes *value)
 
int as_arraylist_prepend_int64 (as_arraylist *list, int64_t value)
 
int as_arraylist_prepend_integer (as_arraylist *list, as_integer *value)
 
int as_arraylist_prepend_list (as_arraylist *list, as_list *value)
 
int as_arraylist_prepend_map (as_arraylist *list, as_map *value)
 
int as_arraylist_prepend_str (as_arraylist *list, const char *value)
 
int as_arraylist_prepend_string (as_arraylist *list, as_string *value)
 
int as_arraylist_set (as_arraylist *list, const uint32_t index, as_val *value)
 
int as_arraylist_set_bytes (as_arraylist *list, const uint32_t index, as_bytes *value)
 
int as_arraylist_set_int64 (as_arraylist *list, const uint32_t index, int64_t value)
 
int as_arraylist_set_integer (as_arraylist *list, const uint32_t index, as_integer *value)
 
int as_arraylist_set_list (as_arraylist *list, const uint32_t index, as_list *value)
 
int as_arraylist_set_map (as_arraylist *list, const uint32_t index, as_map *value)
 
int as_arraylist_set_str (as_arraylist *list, const uint32_t index, const char *value)
 
int as_arraylist_set_string (as_arraylist *list, const 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)
 

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.
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 596 of file modules/common/src/include/aerospike/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.
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 568 of file modules/common/src/include/aerospike/as_arraylist.h.

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 610 of file modules/common/src/include/aerospike/as_arraylist.h.

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 624 of file modules/common/src/include/aerospike/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.
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 582 of file modules/common/src/include/aerospike/as_arraylist.h.

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,
const 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.
as_bytes * as_arraylist_get_bytes ( const as_arraylist list,
const 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 368 of file modules/common/src/include/aerospike/as_arraylist.h.

int64_t as_arraylist_get_int64 ( const as_arraylist list,
const 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.
as_integer * as_arraylist_get_integer ( const as_arraylist list,
const 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 340 of file modules/common/src/include/aerospike/as_arraylist.h.

as_list * as_arraylist_get_list ( const as_arraylist list,
const 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 382 of file modules/common/src/include/aerospike/as_arraylist.h.

as_map * as_arraylist_get_map ( const as_arraylist list,
const 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 396 of file modules/common/src/include/aerospike/as_arraylist.h.

char * as_arraylist_get_str ( const as_arraylist list,
const 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.
as_string * as_arraylist_get_string ( const as_arraylist list,
const 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 354 of file modules/common/src/include/aerospike/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.
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 modules/common/src/include/aerospike/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.
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 703 of file modules/common/src/include/aerospike/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.
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 675 of file modules/common/src/include/aerospike/as_arraylist.h.

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 717 of file modules/common/src/include/aerospike/as_arraylist.h.

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 731 of file modules/common/src/include/aerospike/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.
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 689 of file modules/common/src/include/aerospike/as_arraylist.h.

int as_arraylist_set ( as_arraylist list,
const 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.
int as_arraylist_set_bytes ( as_arraylist list,
const 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 487 of file modules/common/src/include/aerospike/as_arraylist.h.

int as_arraylist_set_int64 ( as_arraylist list,
const 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.
int as_arraylist_set_integer ( as_arraylist list,
const 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 457 of file modules/common/src/include/aerospike/as_arraylist.h.

int as_arraylist_set_list ( as_arraylist list,
const 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 502 of file modules/common/src/include/aerospike/as_arraylist.h.

int as_arraylist_set_map ( as_arraylist list,
const 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 517 of file modules/common/src/include/aerospike/as_arraylist.h.

int as_arraylist_set_str ( as_arraylist list,
const 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.
int as_arraylist_set_string ( as_arraylist list,
const 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 472 of file modules/common/src/include/aerospike/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.

Field Documentation

as_list as_arraylist::_
private
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 112 of file modules/common/src/include/aerospike/as_arraylist.h.

uint32_t as_arraylist::capacity

The total number elements allocated.

Definition at line 117 of file modules/common/src/include/aerospike/as_arraylist.h.

as_val ** as_arraylist::elements

The elements of the list.

Definition at line 127 of file modules/common/src/include/aerospike/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 133 of file modules/common/src/include/aerospike/as_arraylist.h.

uint32_t as_arraylist::size

The number of elements used.

Definition at line 122 of file modules/common/src/include/aerospike/as_arraylist.h.


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