Azinix

array.c File Reference

Array code. More...

#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_tArray_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_tArray_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_tArray_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


Detailed Description

Array code.

Definition in file array.c.


Typedef Documentation

typedef struct Array_Test_t Array_Test_t

Definition at line 511 of file array.c.


Function Documentation

int Array_Abort ( Array_t a,
int  i 
)

Helper function for aborting an array computation.

Would like to be void, except used in macros which need a return type

Definition at line 329 of file array.c.

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.

Definition at line 117 of file array.c.

Array_t* Array_DoAlloc ( int  size,
int  number 
)

Allocate an array of number objects, each of size size.

Definition at line 38 of file array.c.

char* Array_DoData ( Array_t array  ) 

Return a regular C array from given array.

Definition at line 189 of file array.c.

Array_t* Array_Dup ( Array_t old  ) 

Create a duplicate copy of an array.

If memory cannot be allocated for the new array, NIL(Array_t) is returned.

Definition at line 86 of file array.c.

void Array_Free ( Array_t array  ) 

Deallocate an array.

If array is NULL nothing is done. Freeing the individual elements of the array is the responsibility of the user.

Definition at line 68 of file array.c.

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.

Definition at line 154 of file array.c.

void Array_Merge ( Array_t result,
Array_t rulesFromFsm,
Array_t rulesFromShortStringTable,
Array_t rulesFromNoContentTable 
)

Form the union of 3 Array_t.

nil arg means array empty. Entries are ints, indicating applicable rules. Assuming arrays passed in are sorted in ascending order, result is sorted in ascending order.

Definition at line 413 of file array.c.

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 );
               }

Definition at line 397 of file array.c.

int Array_Resize ( Array_t array,
int  new_size 
)

Resize given array.

Definition at line 205 of file array.c.

void Array_Sort ( Array_t array,
int(*)()  compare 
)

Sort the elements of an array.

The compare function is defined as:

                int
                compare(obj1, obj2)
                char **obj1;
                char **obj2;
and should return -1 if obj1 < obj2, 0 if obj1 == obj2, or 1 if obj1 > obj2.

Definition at line 247 of file array.c.

void array_test (  ) 

Definition at line 571 of file array.c.

void Array_Test (  ) 

Simple test of Array_t package.

Definition at line 519 of file array.c.

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.

Definition at line 282 of file array.c.


Variable Documentation

int array_global_index

Definition at line 22 of file array.c.

int array_global_insert

Definition at line 21 of file array.c.

const int ARRAY_INIT_SIZE = 3

Default number of entries in a new array.

Definition at line 15 of file array.c.