#include <stdio.h>
#include "util.h"
#include "array.h"
Go to the source code of this file.
Typedefs | |
| typedef Array_Test_t | Array_Test_t |
Functions | |
| Array_t * | Array_DoAlloc (int size, int number) |
| Allocate an array of number objects, each of size size. | |
| void | Array_Free (Array_t *array) |
| Deallocate an array. | |
| Array_t * | Array_Dup (Array_t *old) |
| Create a duplicate copy of an array. | |
| int | Array_Append (Array_t *array1, Array_t *array2) |
Appends the elements of array2 to the end of array1. Returns 1 if the operation is successful otherwise returns ARRAY_OUT_OF_MEM. | |
| Array_t * | Array_Join (Array_t *array1, Array_t *array2) |
Returns a new array which consists of the elements from array1 followed by the elements of array2. If the operation is not successful NIL(Array_t) is returned. | |
| char * | Array_DoData (Array_t *array) |
| Return a regular C array from given array. | |
| int | Array_Resize (Array_t *array, int new_size) |
| Resize given array. | |
| void | Array_Sort (Array_t *array, int(*compare)()) |
| Sort the elements of an array. | |
| void | Array_Uniq (Array_t *array, int(*compare)(), void(*free_func)()) |
| Compare adjacent elements of the array, and delete any duplicates. | |
| int | Array_Abort (Array_t *a, int i) |
| Helper function for aborting an array computation. | |
| void | Array_Reset (Array_t *a) |
| Set the array->num field to 0. This means that insert_last will happen from the beginning. array->n_size, which is the actual number of allocated bytes is unchanged. | |
| void | Array_Merge (Array_t *result, Array_t *rulesFromFsm, Array_t *rulesFromShortStringTable, Array_t *rulesFromNoContentTable) |
| Form the union of 3 Array_t. | |
| void | Array_Test () |
| Simple test of Array_t package. | |
| void | array_test () |
Variables | |
| const int | ARRAY_INIT_SIZE = 3 |
| Default number of entries in a new array. | |
| int | array_global_insert |
| int | array_global_index |
Definition in file array.c.
| typedef struct Array_Test_t Array_Test_t |
| int Array_Abort | ( | Array_t * | a, | |
| int | i | |||
| ) |
| Array_t* Array_DoAlloc | ( | int | size, | |
| int | number | |||
| ) |
| char* Array_DoData | ( | Array_t * | array | ) |
Create a duplicate copy of an array.
If memory cannot be allocated for the new array, NIL(Array_t) is returned.
| void Array_Free | ( | Array_t * | array | ) |
Returns a new array which consists of the elements from array1 followed by the elements of array2. If the operation is not successful NIL(Array_t) is returned.
| void Array_Reset | ( | Array_t * | a | ) |
Set the array->num field to 0. This means that insert_last will happen from the beginning. array->n_size, which is the actual number of allocated bytes is unchanged.
This function exists simply to allow us to reuse an array. For example,
Array_t *foo;
foo = Array_Alloc( int, 8 );
for ( i = 0 ; i < 1024; i++ ) {
// do something with foo
// now we want to use foo again after we loop,
// so call
Array_Reset( foo );
}
| int Array_Resize | ( | Array_t * | array, | |
| int | new_size | |||
| ) |
| void Array_Sort | ( | Array_t * | array, | |
| int(*)() | compare | |||
| ) |
| void Array_Uniq | ( | Array_t * | array, | |
| int(*)() | compare, | |||
| void(*)() | free_func | |||
| ) |
Compare adjacent elements of the array, and delete any duplicates.
Usually the array should be sorted (using Array_Sort) before calling Array_Uniq. `compare' is defined as:
int
compare(obj1, obj2)
char *obj1;
char *obj2;
and returns -1 if obj1 < obj2, 0 if obj1 == obj2, or 1 if obj1 > obj2. free_func (if non-null) is defined as:
void
free_func(obj1)
char *obj1;
and frees the given array element.
| const int ARRAY_INIT_SIZE = 3 |