list.c File Reference

Detailed Description

Implementation of the functions operating on Tlist.

See Also
Tlist,list.h,

Definition in file list.c.

Functions

void PrivDelEle (Tbuf *node, Tlist *list)
 Private function to delete an element from the list. More...
 
void PrivAddElement (void *Info, Tbuf *pos, boolean in_front, Tlist *list)
 Private function to add an element from the list. More...
 
void InitList (unsigned int ele_size, Tlist *list)
 Constructor. More...
 
void DeleteList (Tlist *list)
 Destructor. More...
 
void DeleteAllItems (Tlist *list)
 Resets a list. More...
 
unsigned int ListSize (Tlist *list)
 Gets the number of elements in the list. More...
 
boolean ListEmpty (Tlist *list)
 Checks if a list is empty. More...
 
void AddFirstElement (void *Info, Tlist *list)
 Adds an element at the head of the list. More...
 
void AddLastElement (void *Info, Tlist *list)
 Adds an element at the tail of the list. More...
 
void ExtractFirst (void *Info, Tlist *list)
 Extracts the first element from the list. More...
 
void ExtractLast (void *Info, Tlist *list)
 Extracts the last element from the list. More...
 
boolean HasElement (void *Info, boolean(*cmp)(void *, void *), Tlist *list)
 Searches an element in the list. More...
 
void PrintList (Tlist *l)
 Prints a list to stdout. More...
 
void InitIterator (Titerator *i, Tlist *list)
 Constructor. More...
 
void CopyIterator (Titerator *dst, Titerator *src)
 Copy constructor. More...
 
void * GetCurrent (Titerator *i)
 Gets the element pointed by the iterator. More...
 
void ExtractCurrent (void *Info, Titerator *i)
 Extract the element pointed by the iterator from the list. More...
 
void AddInFrontOfCurrent (void *Info, Titerator *i)
 Adds an element to the list in front of the position pointed by the iterator. More...
 
void AddBehindCurrent (void *Info, Titerator *i)
 Adds an element to the list behind the position pointed by the iterator. More...
 
void DeleteCurrent (Titerator *i)
 Destructor. More...
 
void First (Titerator *i)
 Moves an iterator to the first position of its associated list. More...
 
void Last (Titerator *i)
 Moves an iterator to the last position of its associated list. More...
 
boolean Advance (Titerator *i)
 Moves an iterator to the next position of its associated list. More...
 
boolean Bacward (Titerator *i)
 Moves an iterator to the previuos position of its associated list. More...
 
boolean MoveTo (unsigned int n, Titerator *i)
 Moves an iterator to a given position of its associated list. More...
 
boolean EndOfList (Titerator *i)
 Checks if an iterator is pointing at the end of the list. More...
 

Function Documentation

void PrivDelEle ( Tbuf node,
Tlist list 
)

Private function to delete an element from the list.

Parameters
nodeA pointer to the list node to be deleted.
listThe list

Definition at line 44 of file list.c.

References Tbuf::data, Tlist::first, Tlist::last, Tbuf::next, Tlist::num_ele, and Tbuf::previous.

Referenced by DeleteAllItems(), DeleteCurrent(), ExtractCurrent(), ExtractFirst(), and ExtractLast().

void PrivAddElement ( void *  Info,
Tbuf pos,
boolean  in_front,
Tlist list 
)

Private function to add an element from the list.

Parameters
InfoPointer to the buffer with the data to add to the list.
posPointer to a node in the list.
in_frontTRUE if the element is to be added in front of the pointed node. FALSE if the element is to be added behind it.
listThe list

Definition at line 71 of file list.c.

References Tbuf::data, Tlist::ele_size, Tlist::first, Tlist::last, NEW, Tbuf::next, Tlist::num_ele, and Tbuf::previous.

Referenced by AddBehindCurrent(), AddFirstElement(), AddInFrontOfCurrent(), and AddLastElement().

void InitList ( unsigned int  ele_size,
Tlist list 
)

Initializes an empty list for data with a given size.

Parameters
ele_sizeThe size (in bytes) of the data to be stored in the list.
listThe list to be initialized.

Definition at line 135 of file list.c.

References Tlist::ele_size, Tlist::first, Tlist::last, and Tlist::num_ele.

Referenced by InitListOfBoxes(), main(), and ReadListOfBoxes().

void DeleteList ( Tlist list)

Deletes a list and frees all the allocated memory in all the nodes still in the list.

Parameters
listThe list to be deleted.

Definition at line 153 of file list.c.

References DeleteAllItems().

void DeleteAllItems ( Tlist list)

Delete all the elements stored in the list.

Parameters
listThe list to be reseted.

Definition at line 162 of file list.c.

References Tlist::first, Tbuf::next, and PrivDelEle().

Referenced by DeleteList().

unsigned int ListSize ( Tlist list)

Gets the number of elements in the list.

Parameters
listThe list.
Returns
The number of elements in the list.

Definition at line 180 of file list.c.

References Tlist::num_ele.

Referenced by ListOfBoxesBB(), ListOfBoxesCluster(), LoadSamples(), main(), and SaveListOfBoxes().

boolean ListEmpty ( Tlist list)

Checks if a list is empty.

Parameters
listThe list.
Returns
TRUE if the list is empty.

Definition at line 188 of file list.c.

References Tlist::num_ele.

Referenced by main().

void AddFirstElement ( void *  Info,
Tlist list 
)

Adds an element at the head of the list.

Parameters
InfoA pointer to a memory block of size ele_size bytes with the data to be stored in the list.
listThe list.

Definition at line 196 of file list.c.

References Tlist::first, PrivAddElement(), and TRUE.

Referenced by main(), MPI_SolveCuikSystem(), and ReverseListOfBoxes().

void AddLastElement ( void *  Info,
Tlist list 
)

Adds an element at the tail of the list.

Parameters
InfoA pointer to a memory block of size ele_size bytes with the data to be stored in the list.
listThe list.

Definition at line 206 of file list.c.

References FALSE, Tlist::last, and PrivAddElement().

Referenced by ConcatListOfBoxes(), CopyListOfBoxes(), DealWithCP(), Heap2List(), IncrementalSampleCuikSystemInBox(), ListOfBoxesCluster(), LoadListOfBoxes(), PostProcessBox(), ReadListOfBoxes(), and SampleCuikSystemInBox().

void ExtractFirst ( void *  Info,
Tlist list 
)

Copies the first element from the list into the given pointer and remove the element from the list.

Parameters
InfoA pointer to a memory block of size ele_size bytes where the first list element is to be stored.
listThe list.

Definition at line 212 of file list.c.

References Tbuf::data, Tlist::ele_size, Error(), Tlist::first, Tbuf::next, and PrivDelEle().

Referenced by main().

void ExtractLast ( void *  Info,
Tlist list 
)

Copies the last element from the list into the given pointer and remove the element from the list.

Parameters
InfoA pointer to a memory block of size ele_size bytes where the first list element is to be stored.
listThe list.

Definition at line 228 of file list.c.

References Tbuf::data, Tlist::ele_size, Error(), Tlist::last, Tbuf::next, and PrivDelEle().

boolean HasElement ( void *  Info,
boolean(*)(void *, void *)  cmp,
Tlist list 
)

Determines if a given element is already in the list.

Parameters
InfoA pointer to a memory block of size ele_size bytes where there is the element we want to search in the list.
cmpA function working on the elements stored in the list that retuns TRUE if the two inputs are the same.
listThe list.

Definition at line 244 of file list.c.

References Tbuf::data, FALSE, Tlist::first, and Tbuf::next.

void PrintList ( Tlist l)

Prints the list as a set of pointers. Mainly used for debug.

Parameters
lThe list.

Definition at line 261 of file list.c.

References Tbuf::data, Tlist::first, and Tbuf::next.

void InitIterator ( Titerator i,
Tlist list 
)

Generates an iterator linked to a list. Note that this constructor does not point the interator to any particular position in the list (not the first, not the last,...).

Parameters
iThe iterator to be initialized.
listThe list.

Definition at line 284 of file list.c.

References Titerator::current, and Titerator::list.

Referenced by AddList2Heap(), AnimateWorld(), ConcatListOfBoxes(), CopyListOfBoxes(), DealWithCP(), DeleteListOfBoxes(), IncrementalSampleCuikSystemInBox(), ListOfBoxesBB(), ListOfBoxesCluster(), ListOfBoxesMaxDiagonal(), ListOfBoxesMaxSize(), ListOfBoxesVolume(), LoadCSState(), LoadSamples(), main(), PrintListOfBoxes(), ReverseListOfBoxes(), SampleCuikSystemInBox(), and SaveListOfBoxes().

void CopyIterator ( Titerator dst,
Titerator src 
)

Generates an iterator from another iterator.

Parameters
dstThe iterator to be initialized.
srcThe iterator from where to copy.

Definition at line 290 of file list.c.

References Titerator::current, and Titerator::list.

void* GetCurrent ( Titerator i)

Gets the element pointed by the iterator.

Parameters
iThe iterator from where to copy.
Returns
A pointer to the data of the list node poited by the iterator.

Definition at line 299 of file list.c.

References Titerator::current, and Tbuf::data.

Referenced by AddList2Heap(), AnimateWorld(), ConcatListOfBoxes(), CopyListOfBoxes(), DealWithCP(), DeleteListOfBoxes(), IncrementalSampleCuikSystemInBox(), ListOfBoxesBB(), ListOfBoxesCluster(), ListOfBoxesMaxDiagonal(), ListOfBoxesMaxSize(), ListOfBoxesVolume(), LoadCSState(), LoadSamples(), main(), PrintListOfBoxes(), ReverseListOfBoxes(), SampleCuikSystemInBox(), and SaveListOfBoxes().

void ExtractCurrent ( void *  Info,
Titerator i 
)

Copies the element pointed by the iterator into the given buffer and removes the element from the list. The iterator is moved to the next element in the list.

Parameters
InfoBuffer where to copy the element pointed by the iterator.
iThe iterator.

Definition at line 308 of file list.c.

References Titerator::current, Tbuf::data, Tlist::ele_size, Titerator::list, Tbuf::next, and PrivDelEle().

void AddInFrontOfCurrent ( void *  Info,
Titerator i 
)

Adds an element to the list in front of the position pointed by the iterator.

Parameters
InfoA pointer to the buffer with the data to add to the list.
iThe iterator.

Definition at line 325 of file list.c.

References Titerator::current, Titerator::list, PrivAddElement(), and TRUE.

void AddBehindCurrent ( void *  Info,
Titerator i 
)

Adds an element to the list behind the position pointed by the iterator.

Parameters
InfoA pointer to the buffer with the data to add to the list.
iThe iterator.

Definition at line 333 of file list.c.

References Titerator::current, FALSE, Titerator::list, and PrivAddElement().

void DeleteCurrent ( Titerator i)

Deletes a Titerator structure.

Parameters
iThe iterator to be deleted.

Definition at line 341 of file list.c.

References Titerator::current, Titerator::list, Tbuf::next, and PrivDelEle().

Referenced by DeleteListOfBoxes().

void Last ( Titerator i)

Moves an iterator to the last position of its associated list.

Parameters
iThe iterator to be updated.

Definition at line 364 of file list.c.

References Titerator::current, Tlist::last, and Titerator::list.

boolean Advance ( Titerator i)

Moves an iterator to the next position of its associated list.

Parameters
iThe iterator to be updated.
Returns
TRUE if the iterator can be actually displaced (i.e., it was not at the last position of the list).

Definition at line 373 of file list.c.

References Titerator::current, FALSE, Tbuf::next, and TRUE.

Referenced by AddList2Heap(), AnimateWorld(), ConcatListOfBoxes(), CopyListOfBoxes(), DealWithCP(), IncrementalSampleCuikSystemInBox(), ListOfBoxesBB(), ListOfBoxesCluster(), ListOfBoxesMaxDiagonal(), ListOfBoxesMaxSize(), ListOfBoxesVolume(), LoadSamples(), main(), PrintListOfBoxes(), ReverseListOfBoxes(), SampleCuikSystemInBox(), and SaveListOfBoxes().

boolean Bacward ( Titerator i)

Moves an iterator to the previous position of its associated list.

Parameters
iThe iterator to be updated.
Returns
TRUE if the iterator can be actually displaced (i.e., it was not at the first position of the list).

Definition at line 395 of file list.c.

References Titerator::current, FALSE, Tbuf::previous, and TRUE.

boolean MoveTo ( unsigned int  n,
Titerator i 
)

Moves an iterator to a given position of its associated list.

Parameters
nThe position where the iterator has to point.
iThe iterator to be updated.
Returns
TRUE if the iterator can be actually displaced (i.e., the list has, at least, n elements).

Definition at line 417 of file list.c.

References Titerator::current, FALSE, Tlist::first, Titerator::list, Tbuf::next, Tlist::num_ele, and TRUE.

Referenced by main().

boolean EndOfList ( Titerator i)

Checks if an iterator is pointing at the end of the list.

Parameters
iThe iterator to be checked.
Returns
TRUE if the iterator is at the end of the list.

Definition at line 445 of file list.c.

References Titerator::current.

Referenced by AddList2Heap(), AnimateWorld(), ConcatListOfBoxes(), CopyListOfBoxes(), DealWithCP(), DeleteListOfBoxes(), IncrementalSampleCuikSystemInBox(), ListOfBoxesBB(), ListOfBoxesCluster(), ListOfBoxesMaxDiagonal(), ListOfBoxesMaxSize(), ListOfBoxesVolume(), LoadSamples(), main(), PrintListOfBoxes(), ReverseListOfBoxes(), SampleCuikSystemInBox(), and SaveListOfBoxes().