Institut de Robòtica i Informàtica Industrial
KRD Group

The CuikSuite Project

list.c File Reference

Implementation of the functions operating on Tlist. More...

#include "list.h"
#include "error.h"
#include "defines.h"
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Functions

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

Detailed Description

Implementation of the functions operating on Tlist.

See also:
Tlist,list.h,

Definition in file list.c.


Function Documentation

void PrivDelEle ( Tbuf node,
Tlist list 
)

Private function to delete an element from the list.

Parameters:
node A pointer to the list node to be deleted.
list The 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().

Here is the caller graph for this function:

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

Private function to add an element from the list.

Parameters:
Info Pointer to the buffer with the data to add to the list.
pos Pointer to a node in the list.
in_front TRUE if the element is to be added in front of the pointed node. FALSE if the element is to be added behind it.
list The 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().

Here is the caller graph for this function:

void InitList ( unsigned int  ele_size,
Tlist list 
)

Initializes an empty list for data with a given size.

Parameters:
ele_size The size (in bytes) of the data to be stored in the list.
list The 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(), and ReadListOfBoxes().

Here is the caller graph for this function:

void DeleteList ( Tlist list  ) 

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

Parameters:
list The list to be deleted.

Definition at line 153 of file list.c.

References DeleteAllItems().

Here is the call graph for this function:

void DeleteAllItems ( Tlist list  ) 

Delete all the elements stored in the list.

Parameters:
list The list to be reseted.

Definition at line 162 of file list.c.

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

Referenced by DeleteList().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int ListSize ( Tlist list  ) 

Gets the number of elements in the list.

Parameters:
list The 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(), main(), and SaveListOfBoxes().

Here is the caller graph for this function:

boolean ListEmpty ( Tlist list  ) 

Checks if a list is empty.

Parameters:
list The list.
Returns:
TRUE if the list is empty.

Definition at line 188 of file list.c.

References Tlist::num_ele.

void AddFirstElement ( void *  Info,
Tlist list 
)

Adds an element at the head of the list.

Parameters:
Info A pointer to a memory block of size ele_size bytes with the data to be stored in the list.
list The list.

Definition at line 196 of file list.c.

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

Referenced by MPI_SolveCuikSystem(), and ReverseListOfBoxes().

Here is the call graph for this function:

Here is the caller graph for this function:

void AddLastElement ( void *  Info,
Tlist list 
)

Adds an element at the tail of the list.

Parameters:
Info A pointer to a memory block of size ele_size bytes with the data to be stored in the list.
list The list.

Definition at line 206 of file list.c.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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:
Info A pointer to a memory block of size ele_size bytes where the first list element is to be stored.
list The list.

Definition at line 212 of file list.c.

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

Here is the call graph for this function:

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:
Info A pointer to a memory block of size ele_size bytes where the first list element is to be stored.
list The list.

Definition at line 228 of file list.c.

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

Here is the call graph for this function:

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

Determines if a given element is already in the list.

Parameters:
Info A pointer to a memory block of size ele_size bytes where there is the element we want to search in the list.
cmp A function working on the elements stored in the list that retuns TRUE if the two inputs are the same.
list The 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:
l The 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:
i The iterator to be initialized.
list The list.

Definition at line 284 of file list.c.

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

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

Here is the caller graph for this function:

void CopyIterator ( Titerator dst,
Titerator src 
)

Generates an iterator from another iterator.

Parameters:
dst The iterator to be initialized.
src The 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:
i The 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(), DeleteListOfBoxes(), ListOfBoxesBB(), ListOfBoxesCluster(), ListOfBoxesMaxDiagonal(), ListOfBoxesMaxSize(), ListOfBoxesVolume(), LoadCSState(), main(), PrintListOfBoxes(), ReverseListOfBoxes(), SampleCuikSystemInBox(), and SaveListOfBoxes().

Here is the caller graph for this function:

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:
Info Buffer where to copy the element pointed by the iterator.
i The iterator.

Definition at line 308 of file list.c.

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

Here is the call graph for this function:

void AddInFrontOfCurrent ( void *  Info,
Titerator i 
)

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

Parameters:
Info A pointer to the buffer with the data to add to the list.
i The iterator.

Definition at line 325 of file list.c.

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

Here is the call graph for this function:

void AddBehindCurrent ( void *  Info,
Titerator i 
)

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

Parameters:
Info A pointer to the buffer with the data to add to the list.
i The iterator.

Definition at line 333 of file list.c.

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

Here is the call graph for this function:

void DeleteCurrent ( Titerator i  ) 

Deletes a Titerator structure.

Parameters:
i The iterator to be deleted.

Definition at line 341 of file list.c.

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

Referenced by DeleteListOfBoxes().

Here is the call graph for this function:

Here is the caller graph for this function:

void First ( Titerator i  ) 

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

Parameters:
i The iterator to be updated.

Definition at line 356 of file list.c.

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

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

Here is the caller graph for this function:

void Last ( Titerator i  ) 

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

Parameters:
i The 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:
i The 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(), ListOfBoxesBB(), ListOfBoxesCluster(), ListOfBoxesMaxDiagonal(), ListOfBoxesMaxSize(), ListOfBoxesVolume(), main(), PrintListOfBoxes(), ReverseListOfBoxes(), SampleCuikSystemInBox(), and SaveListOfBoxes().

Here is the caller graph for this function:

boolean Bacward ( Titerator i  ) 

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

Parameters:
i The 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:
n The position where the iterator has to point.
i The 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().

Here is the caller graph for this function:

boolean EndOfList ( Titerator i  ) 

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

Parameters:
i The 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(), DeleteListOfBoxes(), ListOfBoxesBB(), ListOfBoxesCluster(), ListOfBoxesMaxDiagonal(), ListOfBoxesMaxSize(), ListOfBoxesVolume(), main(), PrintListOfBoxes(), ReverseListOfBoxes(), SampleCuikSystemInBox(), and SaveListOfBoxes().

Here is the caller graph for this function: