Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Related Pages

Vectors


Detailed Description

implementation of vectors.

A Vector is a one-dimensional array but allows for automatic resizing.i.e,the size need not be known in advance.

Data Structures

Defines

Functions


Function Documentation

void doSorting Vector  v,
BooleanFunction *  f,
void *  data,
char  use
[static]
 

internal helper function for sorting.

Parameters:
v the vector in which the sorting operation has to be done.
f the function that is used for the sorting of the vector f.
data some additional data that is handed over to the comparison function.
use determines the usage in the program
Definition at line 500 of file vector.c.

References vectorElement(), vectorSetElement(), and vectorSize().

Referenced by vectorSort(), and vectorSortWithData().

void resizeVector Vector  v  )  [static]
 

resize vector, double capacity.

Parameters:
v the vector that has to be resized.
Returns:
the new vector after resizing.
Definition at line 85 of file vector.c.

Referenced by vectorAddElement(), vectorInsertElement(), vectorSetElement(), and vectorSetElements().

int vectorAddElement Vector  v,
void *  element
 

adds a new element to the end of the vector.

if necessary the vector automatically increases its capacity.

Parameters:
v the vector to which the new element has to be added.
element the element that has to be added to the vector v.
Returns:
the index of the vector after addition.
Definition at line 147 of file vector.c.

References resizeVector().

Referenced by arrayNew().

int vectorCapacity Vector  v  ) 
 

returns the current capacity of vector.

Parameters:
v the vector whose capacity has to be retrieved.
Returns:
the capacity of the vector v.
Definition at line 396 of file vector.c.

Referenced by vectorClone().

Vector vectorClone Vector  v  ) 
 

clones a vector.

Parameters:
v the vector that has to be cloned.
Returns:
a new vector after cloning is done.
Definition at line 455 of file vector.c.

References vectorCapacity(), vectorCopy(), and vectorNew().

Referenced by arrayClone().

Boolean vectorContains Vector  v,
void *  element
 

checks if a vector contains a given element.

Parameters:
v the vector in which a particular number has to be searched.
element the element which has to be checked in the vector v.
Returns:
TRUE if vector contains the element and FALSE otherwise.
Definition at line 436 of file vector.c.

Vector vectorCopy Vector  dst,
Vector  src
 

copies all the entries of one vector src to another vector dst.

Parameters:
src source vector from which the copying is done.
dst destination vector to which copying is done.
Returns:
the dst vector with the entries copied.
Definition at line 473 of file vector.c.

Referenced by vectorClone().

void vectorDelete Vector  v  ) 
 

deletes vector, but can't free memory for the content.

Parameters:
v the vector that has to be deleted.
Definition at line 130 of file vector.c.

Referenced by arrayDelete(), listSort(), and listSortWithData().

Pointer vectorElement Vector  v,
int  index
 

sets the element at a specific index to a new element.

if necessary the vector automatically increases its capacity.

Parameters:
v the vector in which the element has to be set.
index the index at which the element that has to be set is located.
Returns:
the old element (or NULL) at that index.
Definition at line 168 of file vector.c.

Referenced by arrayDimension(), arrayElement(), arraySetElement(), doSorting(), and vectorToList().

int vectorIndexOf Vector  v,
void *  element,
int  index
 

finds the index of an entry in the vector.

Parameters:
v the vector in which the index of the element has to be retrieved.
element the element whose index has to be retrieved in the vector v.
index determines the index of all the elements in the vector.
Returns:
index of a given element in the vector or '-1' if the element does not belong to that specified vector.
Definition at line 377 of file vector.c.

Referenced by vectorRemoveElement().

Pointer vectorInsertElement Vector  v,
void *  element,
int  index
 

inserts a new element at the specified index.

Size increases automatically if necessary. Inefficient method,Not recommended.

Parameters:
v the vector into which the new element has to be added.
element the element that has to be added in the vector v.
index the specified index at which the insertion has to be done.
Returns:
the old element at that index (or NULL).
Definition at line 249 of file vector.c.

References resizeVector().

Boolean vectorIsEmpty Vector  v  ) 
 

checks if the vector is empty or not.

Parameters:
v the vector for which the emptiness is checked.
Returns:
TRUE if the vector is empty and FALSE otherwise.
Definition at line 422 of file vector.c.

Vector vectorNew int  capacity  ) 
 

creates a new vector with an initial capacity.

specifying a correct or nearly correct capacity may slightly improve the efficiency.

Parameters:
capacity the capacity with which the new vector has to be created.
Returns:
the new vector created with size capacity.
Definition at line 104 of file vector.c.

Referenced by arrayNew(), listToVector(), and vectorClone().

int vectorRemoveElement Vector  v,
void *  element
 

removes the specified element from the vector.

If the element occurs multiple times, the first item will be removed. If the element does not belong to the vector the program is aborted. Not efficient,not recommended.

Parameters:
v the vector from which the element to be removed is present.
element the element that has to be removed from the vector v.
Returns:
the associated index of the vector after removal.
Definition at line 221 of file vector.c.

References vectorIndexOf(), and vectorRemoveElementAt().

Pointer vectorRemoveElementAt Vector  v,
int  index
 

removes element at the index.

all later elements move one position in front and size decreases. inefficient, not recommended.

Parameters:
v the vector from which the element has to be removed.
index the index at which the element that has to be removed is located.
Returns:
the old element at the specified index.
Definition at line 189 of file vector.c.

Referenced by vectorRemoveElement().

void vectorSetAllElements Vector  v,
void *  element
 

sets all the elements to a new value.

Size increases to the current capacity of the vector.

Parameters:
v the vector in which all the elements have to be set to the new value.
element determines the element that is being set in vector v.
Definition at line 361 of file vector.c.

References vectorSetElements().

Pointer vectorSetElement Vector  v,
void *  element,
int  index
 

sets the element at the given index.

size may increase automatically if necessary.

Parameters:
v the vector in which the specified element has to be set.
element the element that has to be set in the vector v.
index the index at which the element has to be set.
Returns:
the old element at that index.
Definition at line 285 of file vector.c.

References resizeVector().

Referenced by doSorting(), and listToVector().

void vectorSetElements Vector  v,
void *  element,
int  from,
int  to
 

sets all elements between FROM and TO(excluding to) to a new value.

size may increase automatically if necessary.

Parameters:
v the vector in which the elements have to be set.
element determines the element that is being set.
from this is the source index from which the elements are set.
to this is the destination index until which the elements are set.
Returns:
the new vector after setting the elements.
Definition at line 316 of file vector.c.

References resizeVector().

Referenced by vectorSetAllElements().

int vectorSize Vector  v  ) 
 

returns the current number of entries in the vector.

Parameters:
v the vector whose current number of entries has to be determined.
Returns:
the total number of entries in the vector v.
Definition at line 409 of file vector.c.

Referenced by arrayDimension(), arrayElement(), arraySetElement(), doSorting(), and vectorToList().

Vector vectorSort Vector  v,
BooleanFunction *  f
 

sorts a vector using a user-specified compare function.

The function f is called as f(a,b)

Parameters:
v the vector that has to be sorted.
f the function that is used for sorting.
Returns:
should return TRUE if the element a should be before element b.
Definition at line 536 of file vector.c.

References doSorting().

Referenced by listSort().

Vector vectorSortWithData Vector  v,
BooleanFunction *  f,
void *  clientData
 

sorts a vector, using a user-specified compare function and some extra data.

The function f is called as f(a,b,)and some data.

Parameters:
v the vector that has to be sorted.
f the function that is used for sorting.
clientData the additional data that is handed over to the comparison function.
Returns:
should return TRUE if the element a should be before element b
Definition at line 554 of file vector.c.

References doSorting().

Referenced by listSortWithData().

List vectorToList Vector  v  ) 
 

converts a vector into a list.

Parameters:
v the vector that has to be converted into a list l.
Returns:
the list l corresponding to the vector v.
Definition at line 568 of file vector.c.

References listPrependElement(), vectorElement(), and vectorSize().

Referenced by listSort(), and listSortWithData().


BLAH 0.95 (20 Oct 2004)