#include "ks_config.h"
#include "ks_array.h"
#include "ks_string.h"
#include <string.h>
#include <stdio.h>
Go to the source code of this file.
Functions | |
| int | ks_array_length (ks_array_t *a) |
| ks_type_t * | ks_array_type () |
| ks_array_t * | ks_array_new (void) |
| void | ks_array_init (ks_array_t *a) |
| void | ks_array_free (ks_array_t *a) |
| void | ks_array_fini (ks_array_t *a) |
| void | ks_array_extend (ks_array_t *a, int size) |
| void | ks_array_set (ks_array_t *a, int idx, ks_base_t *ptr) |
| ks_base_t * | ks_array_get (ks_array_t *a, int idx) |
| void | ks_array_add (ks_array_t *a, ks_base_t *ptr) |
| void | ks_array_remove (ks_array_t *a, int idx) |
| void | ks_array_sort (ks_array_t *a, ks_array_compar func) |
Definition in file ks_array.c.
| void ks_array_add | ( | ks_array_t * | a, | |
| ks_base_t * | ptr | |||
| ) |
Add a new object to a ks_array_t. If there is no room left in the ks_array_t array, the amount of memory allocated to the ks_array_t is doubled using ks_array_extend(), and then the new object is added.
| a | a pointer to the ks_array_t to which the new object is to be added. | |
| ptr | a pointer to the object to be stored in the ks_array_t |
Definition at line 252 of file ks_array.c.
References _ks_array_t::data, ks_array_extend(), _ks_array_t::length, and _ks_array_t::size.
Referenced by ks_assoc_keys(), ks_assoc_put(), ks_bquery_combiner_add(), ks_bquery_composite_add(), ks_bquery_feed_add(), ks_bquery_identity_add_tagged(), and main().
| void ks_array_extend | ( | ks_array_t * | a, | |
| int | size | |||
| ) |
Increase the amount of memory allocated for storing elements in a ks_array_t.
| a | a pointer to the ks_array_t to be extended | |
| size | the number of sizeof(ks_base_t *) byte blocks to add to the current allocation |
Definition at line 193 of file ks_array.c.
References _ks_array_t::data, ks_realloc(), and _ks_array_t::size.
Referenced by ks_array_add().
| void ks_array_fini | ( | ks_array_t * | a | ) |
Destroy all of the elements stored in a ks_array_t, and free the memory used to hold store those elements in the given ks_array_t, leaving the ks_array_t empty (in the same state as a ks_array_t newly created by ks_array_new()).
| a | a pointer to the ks_array_t to be emptied |
Definition at line 151 of file ks_array.c.
References _ks_array_t::data, ks_array_get(), ks_free(), and _ks_array_t::length.
Referenced by ks_array_free(), ks_assoc_fini(), ks_bquery_free(), and ks_socket_free().
| void ks_array_free | ( | ks_array_t * | a | ) |
Destroy a given ks_array_t and free all memory that has been allocated for it and any elements it contains.
| a | a pointer to the ks_array_t to be destroyed |
Definition at line 134 of file ks_array.c.
References ks_array_fini(), and ks_free().
Referenced by main().
| ks_base_t* ks_array_get | ( | ks_array_t * | a, | |
| int | idx | |||
| ) |
Retrieve the element stored at a given location in a ks_array_t.
| a | a pointer to the ks_array_t from which the element is to be retrieved | |
| idx | indexes the element to be retrieved within the given ks_array_t. |
Definition at line 234 of file ks_array.c.
References _ks_array_t::data.
Referenced by ks_array_fini(), ks_assoc_keys(), and ks_response_fact().
| void ks_array_init | ( | ks_array_t * | a | ) |
Initialise a ks_array_t to a known, default state. The given ks_array_t should be empty (either have been freshly created with ks_array_new(), or have just been cleared by ks_array_fini()) to prevent memory leaks.
| a | a pointer to the ks_array_t to be initialised. |
Definition at line 117 of file ks_array.c.
References _ks_array_t::base, _ks_array_t::data, ks_malloc(), _ks_array_t::length, _ks_array_t::size, and _ks_base_t::type.
Referenced by ks_array_new(), ks_assoc_init(), ks_bquery_new(), and ks_socket_new().
| int ks_array_length | ( | ks_array_t * | a | ) | [inline] |
Return the number of elements stored a given ks_array_t.
| a | the ks_array_t whose length we are interested in. |
Definition at line 47 of file ks_array.c.
References _ks_array_t::length.
Referenced by ks_array_sort(), ks_assoc_keys(), ks_assoc_size(), ks_response_facts_length(), and main().
| ks_array_t* ks_array_new | ( | void | ) |
Create a new ks_array_t
Definition at line 100 of file ks_array.c.
References ks_array_init(), and ks_malloc().
Referenced by ks_assoc_keys(), and main().
| void ks_array_remove | ( | ks_array_t * | a, | |
| int | idx | |||
| ) |
Remove a specific object from a ks_array_t, healing the hole it leaves behind.
| a | a pointer to the ks_array_t we wish to remove an object from. | |
| idx | the index of the object to be removed within the ks_array_t. |
Definition at line 270 of file ks_array.c.
References _ks_array_t::data, and _ks_array_t::length.
| void ks_array_set | ( | ks_array_t * | a, | |
| int | idx, | |||
| ks_base_t * | ptr | |||
| ) |
Store a ks_base_t in a specific location in a ks_array_t, first destroying anything that was originally stored at that location in the ks_array_t.
| a | a pointer to the ks_array_t into which the object is to be stored | |
| idx | the location in the ks_array_t that the new object is to be stored. | |
| ptr | a pointer to the new ks_vase_t object to be stored in the ks_array_t |
Definition at line 216 of file ks_array.c.
References _ks_array_t::data.
| void ks_array_sort | ( | ks_array_t * | a, | |
| ks_array_compar | func | |||
| ) |
Sort a ks_array_t.
| a | a pointer to the ks_array_t to be sorted | |
| func | a pointer to a comparrisson function that is able to sort the objects stored in the ks_array_t. |
Definition at line 290 of file ks_array.c.
References _ks_array_t::data, and ks_array_length().
| ks_type_t* ks_array_type | ( | void | ) |
Get metaclass for ks_array_t objects.
Definition at line 88 of file ks_array.c.
1.5.1