version 1.1.1.1, 2011/06/08 07:09:12
|
version 1.1.1.2, 2012/02/17 12:50:03
|
Line 106 int __axl_list_always_true (axlPointer a, axlPointer b
|
Line 106 int __axl_list_always_true (axlPointer a, axlPointer b
|
*/ |
*/ |
void __axl_list_allocate_nodes (axlList * list) |
void __axl_list_allocate_nodes (axlList * list) |
{ |
{ |
int iterator; | int iterator; |
| axlListNode ** temp; |
| int available; |
|
|
list->available = 1; |
list->available = 1; |
list->allocated += list->available; |
list->allocated += list->available; |
|
|
/* allocate enough memory to hold all nodes already |
/* allocate enough memory to hold all nodes already |
* allocated */ |
* allocated */ |
if (list->preallocated == NULL) | if (list->preallocated == NULL) { |
list->preallocated = axl_new (axlListNode *, list->allocated); |
list->preallocated = axl_new (axlListNode *, list->allocated); |
else | if (list->preallocated == NULL) { |
| /* reduce noddes available */ |
| list->available = 0; |
| list->allocated--; |
| return; |
| } |
| } else { |
| /* realloc for the list */ |
| temp = list->preallocated; |
list->preallocated = realloc (list->preallocated, (sizeof (axlListNode *)) * list->allocated); |
list->preallocated = realloc (list->preallocated, (sizeof (axlListNode *)) * list->allocated); |
|
|
|
/* check alloc operation */ |
|
if (list->preallocated == NULL) { |
|
/* alloc failed, restore to previous pointer */ |
|
list->preallocated = temp; |
|
|
|
/* reduce noddes available */ |
|
list->available = 0; |
|
list->allocated--; |
|
|
|
return; |
|
} |
|
} /* end */ |
|
|
|
/* reached this point, alloc operation worked */ |
|
|
/* allocate a node for each available position */ |
/* allocate a node for each available position */ |
|
available = list->available; |
for (iterator = 0; iterator < list->available; iterator++) { |
for (iterator = 0; iterator < list->available; iterator++) { |
|
/* alloc node */ |
list->preallocated[iterator] = axl_new (axlListNode, 1); |
list->preallocated[iterator] = axl_new (axlListNode, 1); |
} | |
| /* check alloc operation */ |
| if (list->preallocated[iterator] == NULL) { |
| available--; |
| } /* end if */ |
| } /* end if */ |
| |
| /* update list of available nodes */ |
| list->available = available; |
|
|
return; |
return; |
} |
} |
Line 153 axlListNode * __axl_list_get_next_node_available (axlL
|
Line 188 axlListNode * __axl_list_get_next_node_available (axlL
|
axlListNode * node; |
axlListNode * node; |
|
|
/* check that there are nodes available */ |
/* check that there are nodes available */ |
if (list->available == 0) | if (list->available == 0) { |
| /* alloc nodes */ |
__axl_list_allocate_nodes (list); |
__axl_list_allocate_nodes (list); |
|
|
|
/* check if there are available nodes */ |
|
if (list->available == 0) |
|
return NULL; |
|
} /* end if */ |
|
|
/* get the next node available */ |
/* get the next node available */ |
node = list->preallocated[list->available - 1]; |
node = list->preallocated[list->available - 1]; |
Line 263 axlList * axl_list_new (axlEqualFunc are_equal, axl
|
Line 304 axlList * axl_list_new (axlEqualFunc are_equal, axl
|
|
|
axl_return_val_if_fail (are_equal, NULL); |
axl_return_val_if_fail (are_equal, NULL); |
|
|
|
/* alloc node */ |
result = axl_new (axlList, 1); |
result = axl_new (axlList, 1); |
|
/* check alloc operation */ |
|
if (result == NULL) |
|
return NULL; |
result->are_equal = are_equal; |
result->are_equal = are_equal; |
result->destroy_data = destroy_data; |
result->destroy_data = destroy_data; |
|
|
Line 385 int axl_list_equal_string (axlPointer a, axlPoint
|
Line 430 int axl_list_equal_string (axlPointer a, axlPoint
|
} |
} |
|
|
/** |
/** |
* @brief Equal function that is preprated to receive to integers and | * @brief Works like \ref axl_list_equal_string but ordering strings |
| * stored. |
| * |
| * @param a The first string to compare. |
| * @param b The second string to compare. |
| * |
| * @return 0 if both are equal, -1 if a shold go before b and 1 if a |
| * should go after b. |
| */ |
| int axl_list_order_string (axlPointer a, axlPointer b) |
| { |
| int value; |
| |
| value = strcmp (a, b); |
| if (value == 0) |
| return value; |
| if (value > 0) |
| return -1; |
| return 1; |
| } |
| |
| /** |
| * @brief Equal function that is prepared to receive to integers and |
* return if they are equal. |
* return if they are equal. |
* |
* |
* It is assumed that integers are stored in the list using the |
* It is assumed that integers are stored in the list using the |
Line 476 void axl_list_add (axlList * list, axlPointer
|
Line 543 void axl_list_add (axlList * list, axlPointer
|
axl_return_if_fail (list); |
axl_return_if_fail (list); |
|
|
new_node = __axl_list_get_next_node_available (list); |
new_node = __axl_list_get_next_node_available (list); |
|
/* check returned node */ |
|
if (new_node == NULL) |
|
return; |
new_node->data = pointer; |
new_node->data = pointer; |
|
|
/* check basic case */ |
/* check basic case */ |
Line 607 void axl_list_add_at (axlList * list, axlPointer
|
Line 677 void axl_list_add_at (axlList * list, axlPointer
|
|
|
/* allocate a new node */ |
/* allocate a new node */ |
new_node = __axl_list_get_next_node_available (list); |
new_node = __axl_list_get_next_node_available (list); |
|
/* check returned node */ |
|
if (new_node == NULL) |
|
return; |
new_node->data = pointer; |
new_node->data = pointer; |
|
|
|
|
Line 658 void axl_list_prepend (axlList * list, axlPointe
|
Line 731 void axl_list_prepend (axlList * list, axlPointe
|
|
|
/* simulate adding the node at the first position */ |
/* simulate adding the node at the first position */ |
new_node = __axl_list_get_next_node_available (list); |
new_node = __axl_list_get_next_node_available (list); |
|
/* check returned node */ |
|
if (new_node == NULL) |
|
return; |
new_node->data = pointer; |
new_node->data = pointer; |
|
|
/* make the new node the be the first one */ |
/* make the new node the be the first one */ |
Line 695 void axl_list_append (axlList * list, axlPointe
|
Line 771 void axl_list_append (axlList * list, axlPointe
|
|
|
/* simulate adding the node at the first position */ |
/* simulate adding the node at the first position */ |
new_node = __axl_list_get_next_node_available (list); |
new_node = __axl_list_get_next_node_available (list); |
|
/* check allocated node */ |
|
if (new_node == NULL) |
|
return; |
new_node->data = pointer; |
new_node->data = pointer; |
|
|
/* make the new node the be the first one */ |
/* make the new node the be the first one */ |