vector.c File Reference

Detailed Description

Implementation of the functions operating on Tvector.

See Also
Tvector,vector.h,

Definition in file vector.c.

Functions

boolean CmpID (void *a, void *b)
 Comparison operator for identifiers. More...
 
void CopyID (void *a, void *b)
 Copy constructor for identifiers. More...
 
void DeleteID (void *a)
 Destructor for identifiers. More...
 
boolean CmpDouble (void *a, void *b)
 Comparison operator for doubles. More...
 
void CopyDouble (void *a, void *b)
 Copy constructor for doubles. More...
 
void DeleteDouble (void *a)
 Destructor for doubles. More...
 
void NewDoublePair (double f, double s, TDoublePair *p)
 Constructor. More...
 
double FirstInPair (TDoublePair *p)
 The first element of a pair. More...
 
double SecondInPair (TDoublePair *p)
 The second element of a pair. More...
 
boolean CmpDoublePair (void *a, void *b)
 Comparison operator for paris of doubles. More...
 
void CopyDoublePair (void *a, void *b)
 Copy constructor for pairs of doubles. More...
 
void DeleteDoublePair (void *a)
 Destructor for pairs of doubles. More...
 
boolean CmpVoidPtr (void *a, void *b)
 Comparison operator for void pointers. More...
 
void CopyVoidPtr (void *a, void *b)
 Copy constructor for void pointers. More...
 
void DeleteVoidPtr (void *a)
 Destructor for void pointers. More...
 
void InitVector (unsigned int ele_size, void(*Copy)(void *, void *), void(*Delete)(void *), unsigned int max_ele, Tvector *vector)
 Constructor. More...
 
void ResetVector (Tvector *vector)
 Resets a vector. More...
 
void CopyVector (Tvector *v_dst, Tvector *v_src)
 Copy constructor. More...
 
unsigned int VectorFirstFreePos (Tvector *vector)
 Finds a free position in the vector. More...
 
unsigned int VectorSize (Tvector *vector)
 Gets the number of elements in a vector. More...
 
unsigned int VectorMaxSize (Tvector *vector)
 Gets the maximum number of elements in a vector. More...
 
boolean VectorEmpty (Tvector *vector)
 Checks if a vector is empty. More...
 
boolean ElementInVector (void *e, boolean(*cmp)(void *, void *), Tvector *vector)
 Search for an element in a vector. More...
 
unsigned int FindPos (void *e, boolean(*cmp)(void *, void *), Tvector *vector)
 Search for an element in a vector. More...
 
unsigned int NewVectorElement (void *e, Tvector *vector)
 Adds an element to the vector. More...
 
unsigned int NewFreeVectorElement (void *e, Tvector *vector)
 Adds an element to the vector. More...
 
void SetVectorElement (unsigned int i, void *e, Tvector *vector)
 Adds an element to the vector in a given position. More...
 
void * GetVectorElement (unsigned int i, Tvector *vector)
 Returns a pointer to a vector element. More...
 
void * GetLastElement (Tvector *vector)
 Returns a pointer to the last element of a vector. More...
 
void RemoveVectorElement (unsigned int i, Tvector *vector)
 Removes an element from the vector. More...
 
void SwapVectorElements (unsigned int i, unsigned int j, Tvector *vector)
 Swaps two elements in a vector. More...
 
void ReverseVector (Tvector *vector)
 Reverses a vector. More...
 
void ConcatVectors (Tvector *vector1, Tvector *vector)
 Concatenates two vectors. More...
 
void ExtractVectorElement (unsigned int i, void *e, Tvector *vector)
 Extracts an element from a vector. More...
 
void MoveVectorElement (unsigned int i, unsigned int ni, Tvector *vector)
 Moves a vector element from one position to another. More...
 
void DeleteVector (void *vector)
 Destructor. More...
 

Function Documentation

boolean CmpID ( void *  a,
void *  b 
)
inline

Comparison operator for identifiers. To be used when defining a vector of identifiers (i.e., unsigned int).

Parameters
aPointer to the first identifier to compare.
bPointer to the second identifier to compare.
Returns
TRUE if the two inputs are the same.

Definition at line 19 of file vector.c.

Referenced by New_NewTemptativeSample().

void CopyID ( void *  a,
void *  b 
)
inline

Copy constructor for identifiers. To be used when defining a vector of identifiers (i.e., unsigned int). This is a direct assignation.

Parameters
aPointer to the identifier to initialize.
bPointer to the identifier from where to copy.

Definition at line 24 of file vector.c.

Referenced by DetectLinksAndJoints(), DetectLinksAndJointsFromResidues(), DetectLinksAndJointsFromRigidsAndHinges(), InitBranchStatus(), and InitHeap().

void DeleteID ( void *  a)
inline

Destructor for identifiers. To be used when defining a vector of identifiers (i.e., unsigned int). This basically frees the space taken by the identifier.

Parameters
aPointer to the identifier to delete.

Definition at line 29 of file vector.c.

Referenced by DetectLinksAndJoints(), DetectLinksAndJointsFromResidues(), DetectLinksAndJointsFromRigidsAndHinges(), and InitHeap().

boolean CmpDouble ( void *  a,
void *  b 
)
inline

Comparison operator for doubles. To be used when defining a vector of doubles.

Parameters
aPointer to the first double to compare.
bPointer to the second double to compare.
Returns
TRUE if the two inputs are the same.

Definition at line 34 of file vector.c.

void CopyDouble ( void *  a,
void *  b 
)
inline

Copy constructor for doubles. To be used when defining a vector of doubles. This is a direct assignation.

Parameters
aPointer to the double to initialize.
bPointer to the double from where to copy.

Definition at line 39 of file vector.c.

Referenced by InitSample(), and LoadSample().

void DeleteDouble ( void *  a)
inline

Destructor for doubles. To be used when defining a vector of doubles. This basically frees the space taken by the double.

Parameters
aPointer to the double to delete.

Definition at line 44 of file vector.c.

Referenced by InitSample(), and LoadSample().

void NewDoublePair ( double  f,
double  s,
TDoublePair p 
)
inline

Defines a double pair form two doubles.

Parameters
fThe first double.
sThe second double.
pThe resulting pair structure.

Definition at line 49 of file vector.c.

References TDoublePair::f, and TDoublePair::s.

Referenced by RecursiveReWireRRTstar(), WireAtlasRRTstar(), and WireRRTstar().

double FirstInPair ( TDoublePair p)
inline

Returns the first element of a pair of doubles.

Parameters
pThe pair.
Returns
The first element of 'p'.

Definition at line 55 of file vector.c.

References TDoublePair::f.

Referenced by RecursiveReWireRRTstar().

double SecondInPair ( TDoublePair p)
inline

Returns the second element of a pair of doubles.

Parameters
pThe pair.
Returns
The second element of 'p'.

Definition at line 60 of file vector.c.

References TDoublePair::s.

boolean CmpDoublePair ( void *  a,
void *  b 
)
inline

Comparison operator for pairs of doubles. To be used when defining a vector of pairs of doubles.

Parameters
aPointer to the first pair of doubles to compare.
bPointer to the second pair of doubles to compare.
Returns
TRUE if the two inputs are the same.

Definition at line 65 of file vector.c.

void CopyDoublePair ( void *  a,
void *  b 
)
inline

Copy constructor for pairs of doubles. To be used when defining a vector of pairs of doubles. This is a direct assignation.

Parameters
aPointer to the pair of doubles to initialize.
bPointer to the pair of doubles from where to copy.

Definition at line 71 of file vector.c.

Referenced by AtlasBiRRTstar(), AtlasRRTstar(), BiRRTstar(), and RRTstar().

void DeleteDoublePair ( void *  a)
inline

Destructor for pairs of doubles. To be used when defining a vector of doubles. This basically frees the space taken by the pair of double.

Parameters
aPointer to the double to delete.

Definition at line 77 of file vector.c.

Referenced by BiRRTstar(), and RRTstar().

boolean CmpVoidPtr ( void *  a,
void *  b 
)
inline

Comparison operator for doubles. To be used when defining a vector of pointers.

Parameters
aPointer to the first pointer to compare.
bPointer to the second pointer to compare.
Returns
TRUE if the two inputs are the same.

Definition at line 82 of file vector.c.

void CopyVoidPtr ( void *  a,
void *  b 
)
inline

Copy constructor for doubles. To be used when defining a vector of pointers. This is a direct assignation.

Parameters
aPointer to the pointer to initialize.
bPointer to the pointer from where to copy.

Definition at line 87 of file vector.c.

Referenced by CopyLink(), CreateBranch(), GenerateKinTree(), InitEnvironment(), InitLink(), and InitMechanism().

void DeleteVoidPtr ( void *  a)
inline

Destructor for void pointers. To be used when defining a vector of pointers. This basically frees the space taken by the pointer.

Parameters
aPointer to the pointer to delete.

Definition at line 92 of file vector.c.

Referenced by CopyLink(), CreateBranch(), GenerateKinTree(), InitEnvironment(), InitLink(), and InitMechanism().

void InitVector ( unsigned int  ele_size,
void(*)(void *, void *)  Copy,
void(*)(void *)  Delete,
unsigned int  max_ele,
Tvector vector 
)

Initializes an empty vector Examples of use:

  • InitVector(sizeof(unsigned int),CopyID,DeleteID,MaxNumEle,&vector);
  • InitVector(sizeof(double),CopyDouble,DeleteDouble,MaxNumEle,&vector);
  • InitVector(sizeof(void *),CopyPtr,DeletePtr,MaxNumEle,&vector);

Alternatively you can also use

  • InitVector(sizeof(unsigned int),CopyID,NULL,MaxNumEle,&vector);
  • InitVector(sizeof(double),CopyDouble,NULL,MaxNumEle,&vector);
  • InitVector(sizeof(void *),CopyPtr,NULL,MaxNumEle,&vector);

since the delete functions are actually empty.

Parameters
ele_sizeNumber of bytes taken by each element in the list.
CopyCopy constructor for the elements in the list.
DeleteDestructor for the elements in the list.
max_eleInitial number of elements in the vector. This can be extended on-line but the execution it is more efficient if we have a good guess for this value.
vectorThe vector to initialize.

Definition at line 100 of file vector.c.

References Tvector::Copy, Tvector::Delete, Tvector::ele_size, Tvector::elements, Error(), Tvector::max_ele, NEW, and Tvector::num_ele.

Referenced by AtlasBiRRTstar(), BiRRTstar(), CopyLink(), CreateBranch(), DetectLinksAndJoints(), DetectLinksAndJointsFromResidues(), DetectLinksAndJointsFromRigidsAndHinges(), GenerateKinTree(), InitBranchStatus(), InitEnvironment(), InitHeap(), InitLink(), InitMechanism(), InitSample(), LoadSample(), and RRTPathSteps().

void ResetVector ( Tvector vector)

Removes all the elements from a vector but it does not frees the allocated memory nor resets the maximum number of elements. If you plan to re-use a vector it is more efficient to reset it instead of deleting it and re-initializing it again.

Parameters
vectorThe vector to reset.

Definition at line 120 of file vector.c.

References Tvector::Delete, Tvector::elements, and Tvector::num_ele.

Referenced by ChangeBiRRTSteps(), DeleteVector(), and ResetHeap().

void CopyVector ( Tvector v_dst,
Tvector v_src 
)

Initializes a vector from another vector.

Parameters
v_dstThe vector to initialize.
v_srcThe vector from where to copy.

Definition at line 138 of file vector.c.

References Tvector::Copy, Tvector::Delete, Tvector::ele_size, Tvector::elements, Tvector::max_ele, NEW, and Tvector::num_ele.

Referenced by CopyHeap(), and CopySample().

unsigned int VectorFirstFreePos ( Tvector vector)

Returns the first (i.e., with lower identifier) free position in a vector.

Parameters
vectorThe vector to query.
Returns
The index of the free position.

Definition at line 162 of file vector.c.

References Tvector::elements.

Referenced by NewFreeVectorElement().

unsigned int VectorSize ( Tvector vector)

Returns the number of elements in a vector. Note that the vector can have "holes", i.e., empty slots in position explicitly deleted using RemoveVectorElement.

Parameters
vectorThe vector to query.
Returns
The number of elements in the vector.
See Also
RemoveVectorElement

Definition at line 173 of file vector.c.

References Tvector::num_ele.

Referenced by ChangeBiRRTSteps(), CheckHeap(), GetEnvironmentNObstacles(), GetMechanismLinkID(), GetMechanismNJoints(), GetMechanismNLinks(), GetObstacleID(), GetSampleDim(), InitWorldKinCS(), LinkNBodies(), nStepsBranch(), PrintSample(), SaveSample(), Steps2PathinAtlasRRT(), Steps2PathinRRT(), and UpdateBiRRTSteps().

unsigned int VectorMaxSize ( Tvector vector)

Returns the maximum number of elements in a vector. Note that the vector can have "holes", i.e., empty slots in position explicitly deleted using RemoveVectorElement.

Parameters
vectorThe vector to query.
Returns
The maximum number of elements in the vector.

Definition at line 178 of file vector.c.

References Tvector::max_ele.

boolean VectorEmpty ( Tvector vector)

Checks if a vector is empty

Parameters
vectorThe vector to query.
Returns
TRUE if there are no elements in the vector.

Definition at line 183 of file vector.c.

References Tvector::num_ele.

boolean ElementInVector ( void *  e,
boolean(*)(void *, void *)  cmp,
Tvector vector 
)

Looks for an element in a vector.

Parameters
eThe element we are looking for.
cmpThe comparison operator to use to determine if two elements are the same. Note that for structured types the comparison can be based on a particular field and that only those field need to be initialized in parameter e.
vectorThe vector to query.
Returns
TRUE if the vector includes the requested element.

Definition at line 188 of file vector.c.

References FindPos().

Referenced by New_NewTemptativeSample().

unsigned int FindPos ( void *  e,
boolean(*)(void *, void *)  cmp,
Tvector vector 
)

Looks for an element in a vector.

Parameters
eThe element we are looking for.
cmpThe comparison operator to use to determine if two elements are the same. Note that for structured types the comparison can be based on a particular field and that only those field need to be initialized in parameter e.
vectorThe vector to query.
Returns
The position in the vector holding the requested element or NO_UINT if the vector does not include the element.

Definition at line 193 of file vector.c.

References Tvector::elements, FALSE, and TRUE.

Referenced by ElementInVector().

unsigned int NewVectorElement ( void *  e,
Tvector vector 
)

Adds an element at the end of the list.

Parameters
eThe element add to the vector.
vectorThe vector to update.
Returns
The position in the vector where the element has been stored.

Definition at line 216 of file vector.c.

References Tvector::num_ele, and SetVectorElement().

Referenced by AddBody2Link(), AddShape2Environment(), AddStepToBranch(), ChangeBiRRTSteps(), ConcatVectors(), DetectLinksAndJoints(), DetectLinksAndJointsFromResidues(), DetectLinksAndJointsFromRigidsAndHinges(), GenerateKinTree(), InitBranchStatus(), New_AddBranchToAtlasRRT(), New_NewTemptativeSample(), and RRTPathSteps().

unsigned int NewFreeVectorElement ( void *  e,
Tvector vector 
)

Looks for a free vector position and stores the given element.

Parameters
eThe element add to the vector.
vectorThe vector to update.
Returns
The position in the vector where the element has been stored.

Definition at line 227 of file vector.c.

References SetVectorElement(), and VectorFirstFreePos().

void SetVectorElement ( unsigned int  i,
void *  e,
Tvector vector 
)

Adds an element to the vector in a given position. If the vector position was already occupied, the stored element is deleted before copying the new element.

Parameters
iThe vector position where to store the element.
eThe element add to the vector.
vectorThe vector to update.

Definition at line 238 of file vector.c.

References Tvector::Copy, Tvector::Delete, Tvector::ele_size, Tvector::elements, Tvector::max_ele, MEM_EXPAND, NEW, and Tvector::num_ele.

Referenced by AddElement2Heap(), AddJoint2Mechanism(), AddLink2Mechanism(), AddShape2Environment(), InitSample(), LoadSample(), NewFreeVectorElement(), NewVectorElement(), and UpdateHeapElement().

void* GetLastElement ( Tvector vector)

Returns a pointer to a the last element of a vector.

Parameters
vectorThe vector to query.
Returns
A pointer to the last element of the vector.

Definition at line 278 of file vector.c.

References Tvector::elements, and Tvector::num_ele.

void RemoveVectorElement ( unsigned int  i,
Tvector vector 
)

Removes an element from the vector. Note that elements in the vector are not compacted after the deletion. In this way indexes in other data structured refered to this vector still hold after the deletion. The drawnback is that we can end up with a vector with "holes" and we have to be carefull when retriving elements from the vector.

Parameters
iThe vector position to delete.
vectorThe vector to query.

Definition at line 286 of file vector.c.

References Tvector::Delete, Tvector::elements, and Tvector::num_ele.

Referenced by ExtractMinElement(), ExtractVectorElement(), and MoveVectorElement().

void SwapVectorElements ( unsigned int  i,
unsigned int  j,
Tvector vector 
)

Swaps two elements in a vector. This operation is provided since it is more efficient than extracting the two elements and then inserting them again in the vector in their new positions.

If one of the two elements to swap is empty, this function triggers an error.

Parameters
iIndex of the first element to swap.
jIndex of the second element to swap.
vectorThe vector to update.

Definition at line 299 of file vector.c.

References Tvector::elements, and Error().

Referenced by ExtractMinElement(), HeapDown(), and HeapUp().

void ReverseVector ( Tvector vector)

Reverses the elements in a vector.

Parameters
vectorThe vector to reverse.

Definition at line 319 of file vector.c.

References Tvector::elements, and Tvector::num_ele.

void ConcatVectors ( Tvector vector1,
Tvector vector 
)

Adds a vector to the end of another vector.

Parameters
vector1The vector to add.
vectorThe vector where to add.

Definition at line 333 of file vector.c.

References Tvector::elements, NewVectorElement(), and Tvector::num_ele.

Referenced by ChangeBiRRTSteps().

void ExtractVectorElement ( unsigned int  i,
void *  e,
Tvector vector 
)

Extracts an element from a vector.

The element is copied to the given buffer and removed from the vector.

If the given element of the vector is empty, this function triggers an error.

Parameters
iIndex of the element to be extracted.
eBuffer where to copy the extracted element.
vectorThe vector to update.

Definition at line 342 of file vector.c.

References Tvector::Copy, Tvector::elements, Error(), and RemoveVectorElement().

Referenced by ExtractMinElement().

void MoveVectorElement ( unsigned int  i,
unsigned int  ni,
Tvector vector 
)

Moves a vector element from one position to another.

If the element to move is empty, this function triggers an error.

If the element where to store the moved element is full, it is removed before the moving.

Parameters
iThe index of the element to move.
niThe desired new index for this element.
vectorThe vector to update.

Definition at line 363 of file vector.c.

References Tvector::elements, Error(), and RemoveVectorElement().

void DeleteVector ( void *  vector)

Deletes the information stored in the vector and frees the allocated memory space.

Parameters
vectorThe vector to be deleted.

Definition at line 389 of file vector.c.

References ResetVector().

Referenced by AtlasBiRRTstar(), BiRRTstar(), ChangeBiRRTSteps(), DeleteBioWorld(), DeleteBranch(), DeleteBranchStatus(), DeleteEnvironment(), DeleteHeap(), DeleteLink(), DeleteMechanism(), DeleteSample(), InitWorldKinCS(), and ReconstructRRTPath().