next up previous contents index
Next: The structures Dlist and Up: Lists of n-tuple reals Previous: Related file (external) types   Contents   Index


Functions Summary

The following is a description of all the functions related to the Flists type. The list is in alphabetical order. Notice that these functions do not manage the data field.

$ \bigcirc$Name


mw_change_flists - Define and allocate a Flists structure




$ \bigcirc$Summary


Flists mw_change_flists(ls,max_size,size)

Flist ls;

int max_size,size;




$ \bigcirc$Description


This function changes the memory allocation of the list array of a Flists structure, even if no previously memory allocation was done. The new size (number of lists) of the structure is given by size, and the size to allocate (maximal number of lists) by max_size.

It can also create the structure if the input ls = NULL. Therefore, this function can replace both mw_new_flists and mw_realloc_flists. Since the function can set the address of ls, the variable must be set to the return value of the function (See example below).

The function mw_change_flists returns NULL if not enough memory is available to allocate the structure or the list array, and an error message is issued. Your code should check this return value to eventually send a fatal error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Flists ls;

/* 
   Allocate ls to handle at most 10 lists, the current number of
   lists being 0 (no list).
*/
ls = mw_change_flists(NULL,10,0);
if (!ls) mwerror(FATAL,1,"Not enough memory to continue !\n");

$ \bigcirc$Name


mw_copy_flists - Copy the lists contained in a Flists structure




$ \bigcirc$Summary


Flists mw_copy_flists(in,out)

Flists in,out;




$ \bigcirc$Description


This function copies the list array and data field of the Flists structure in into out : each list contained in in are duplicated. The duplicated Flists out is allocated to at least the current size of in.

Since the function can set the address of out, the variable must be set to the return value of the function (See example below).

The function mw_copy_flists returns NULL if not enough memory is available to allocate the structure or the list array, and an error message is issued. Your code should check this return value to eventually send a fatal error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Flists in,out=NULL;

/* 
   Allocate ls to handle at most 10 lists, the current number of
   lists being 3.
*/
ls = mw_change_flists(NULL,10,3);
if (!ls) mwerror(FATAL,1,"Not enough memory to continue !\n");


/* ... (Here fill the lists) ... */

/*
 Copy in into out. Allocated size for out is 3 lists.
*/
out=mw_copy_flists(in,out);
if (!out) mwerror(FATAL,1,"Not enough memory to copy the lists !\n");

$ \bigcirc$Name


mw_delete_flists - Delete the lists and the Flists structure




$ \bigcirc$Summary


void mw_delete_flists(ls)

Flist ls;




$ \bigcirc$Description


This function deletes the lists contained in the list array, and the structure Flists itself. Warning : the memory of the user-defined field data is not freed. If this field has been allocated, you should free it before calling mw_delete_flists.




$ \bigcirc$Example

Flist ls;
int i;

/*
    ... (Assume ls has been previoulsy allocated)...
*/

/* 
  Free the lists, including data field. 
*/
for (i=ls->size;i--;) if (ls->list[i]->data) free(ls->list[i]->data);
if (ls->data) free(ls->data);
mw_delete_flists(ls);

$ \bigcirc$Name


mw_enlarge_flists - Enlarge the number of lists a Flists may contain




$ \bigcirc$Summary


Flists mw_enlarge_flist(ls)

Flist ls;




$ \bigcirc$Description


This function performs a memory reallocation on the array ls->list to increase the number of lists that can be recorded. The enlargement factor is fixed by the constant MW_LIST_ENLARGE_FACTOR defined in the include file list.h. This function is useful when one does not know by advance the number of lists, and when one wish to avoid multiple reallocations.

If not enough memory is available to perform the reallocation, an error message is issued and the function returns NULL. Otherwise, the function returns ls.




$ \bigcirc$Example

/* Fill a flists with lists until the user enters 'Q'.
*/

Flist ls; 
Flist l;
char c;

ls = mw_change_flists(NULL,10,0);
if (ls==NULL) mwerror(FATAL,1,"Not enough memory to continue !\n");
do {
  if (ls->size == ls->max_size) 
    if (mw_enlarge_flists(ls)==NULL)
      mwerror(FATAL,1,"Not enough memory to continue !\n");
  l = mw_change_flist(NULL,10,10,2);
  if (l==NULL) mwerror(FATAL,1,"Not enough memory to continue !\n");
  mw_clear_flist(l,1.0)
  ls->list[ls->size++] = l;
  scanf("%c",&c);
    } while (c!='Q');

$ \bigcirc$Name


mw_new_flists - Create a Flists structure




$ \bigcirc$Summary


Flists mw_new_flists()




$ \bigcirc$Description


This function creates a new Flists structure. The fields are initialized to 0 or NULLvalue. The function returns the address of the new structure, or NULL if not enough memory is available.




$ \bigcirc$Example

Flists ls;

/*
  Define the structure
*/
ls = mw_new_flists();
if (!ls) mwerror(FATAL,1,"Not enough memory to define the lists !\n");

/* 
  At that time, the FLists is empty (no lists).
*/

$ \bigcirc$Name


mw_realloc_flists - Realloc the list array of the Flists




$ \bigcirc$Summary


Flists mw_realloc_flists(ls,n)

Flists ls;

int n;




$ \bigcirc$Description


This function performs a memory reallocation on the array ls->list so that at most n lists can be recorded.

If not enough memory is available to perform the reallocation, an error message is issued and the function returns NULL. Otherwise, the function returns ls.




$ \bigcirc$Example

Flists ls;

/*
   Allocate ls to handle 10 lists.
*/

ls = mw_new_flists();
if (!ls) mwerror(FATAL,1,"Not enough memory to continue !\n");
ls = mw_realloc_flists(ls,10);
if (!ls) mwerror(FATAL,1,"Not enough memory to continue !\n");


next up previous contents index
Next: The structures Dlist and Up: Lists of n-tuple reals Previous: Related file (external) types   Contents   Index
mw 2004-05-05