ks_array.c File Reference

libkarmaclient's basic array type. More...

#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_tks_array_type ()
ks_array_tks_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_tks_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)


Detailed Description

libkarmaclient's basic array type.

Definition in file ks_array.c.


Function Documentation

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.

Parameters:
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
Returns:
nothing

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.

Parameters:
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
Returns:
nothing

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

Parameters:
a a pointer to the ks_array_t to be emptied
Returns:
nothing

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.

Parameters:
a a pointer to the ks_array_t to be destroyed
Returns:
Nothing

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.

Parameters:
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.
Returns:
a pointer to the ks_base_t indexed by idx in 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.

Parameters:
a a pointer to the ks_array_t to be initialised.
Returns:
nothing.

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.

Parameters:
a the ks_array_t whose length we are interested in.
Returns:
the number of elements stored in the given ks_array_t.

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

Returns:
A pointer to the newly created ks_array_t on success, or NULL on failure.

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.

Parameters:
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.
Returns:
nothing

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.

Parameters:
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
Returns:
nothing

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.

Parameters:
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.

Returns:
A pointer to ks_array's metaclass

Definition at line 88 of file ks_array.c.


Generated on Wed May 9 01:01:57 2007 for libkarmaclient by  doxygen 1.5.1