Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

Array abstraction


Data Structures

struct  s_array

Typedefs

typedef s_array t_array

Functions

void array_init (t_array *ary, size_t element_size, void(*array_destroy)(void *))
void array_push (t_array *ary, const void *element)
void * array_pop (t_array *ary)
void * array_shift (t_array *ary)
void array_unshift (t_array *ary, const void *element)
void array_sort (t_array *ary, int(*compar)(const void *, const void *))
void * array_bsearch (t_array *ary, const void *key, int(*compar)(const void *, const void *))
void * array_element_at (t_array *ary, size_t index)
void array_destroy (t_array *ary)

Typedef Documentation

typedef struct s_array t_array
 

Array "class". This struct contains all necessary information about the array


Function Documentation

void* array_bsearch t_array ary,
const void *  key,
int(*  compar)(const void *, const void *)
 

This function does a binary search on the array. Has to be sorted first!

Parameters:
ary The array structure pointer +
key The key to search for
compar THe comparing function. See bsearch(3) for information of the return values and the arguments of this comparing function.
Returns:
Returns NULL if element not found or element if found

Definition at line 652 of file utils.c.

void array_destroy t_array ary  ) 
 

This function destroys an array. It calls the destroy function specified to array_init() for each argument and then free()s the array itself.

Parameters:
ary The array structure pointer

Definition at line 665 of file utils.c.

void* array_element_at t_array ary,
size_t  index
 

This function returns an element at a specified position.

Parameters:
ary The array structure pointer
index The index of the wanted element
Returns:
The element at the specified position or NULL on failure

Definition at line 656 of file utils.c.

void array_init t_array ary,
size_t  element_size,
void(*  array_destroy)(void *)
 

This function initializes an array structure (it could be the constructor)

Parameters:
ary The array structure pointer
element_size The size of one element in the array
array_destroy The destroy function for an array element. This function will be called whenever an element in the array has to be deleted. Could be NULL if a function like this is not needed and a simple free() call is enough.

Definition at line 606 of file utils.c.

void* array_pop t_array ary  ) 
 

This function deletes the last element in the array.

Parameters:
ary The array structure pointer
Returns:
A copy of the 'popped' element
Attention:
Because this function returns a copy of this element, the destroy function will not be called!

Definition at line 624 of file utils.c.

void array_push t_array ary,
const void *  element
 

This function pushes an element to the end of the array. The element is being copied via a memdup() function, which only is a malloc() with a memcpy().

Parameters:
ary The array structure pointer
element The element to push to the end

Definition at line 614 of file utils.c.

void* array_shift t_array ary  ) 
 

This function deletes the first element in the array

Parameters:
ary The array structure pointer
Returns:
A copy of the 'shifted' element
Attention:
Because this function returns a copy of this element, the destroy function will not be called!

Definition at line 629 of file utils.c.

void array_sort t_array ary,
int(*  compar)(const void *, const void *)
 

This function sorts an array via the quick sort algorithm

Parameters:
ary The array structure pointer
compar The comparing function. See qsort(3) for informations of the return values and arguments of this coparing function.

Definition at line 648 of file utils.c.

void array_unshift t_array ary,
const void *  element
 

This function inserts an element at the beginning of the array.

Parameters:
ary The array structure pointer
element The pointer to the element

Definition at line 637 of file utils.c.


Generated on Sun Apr 25 16:37:40 2004 for Classic Forum by doxygen 1.3.5