op_vvec_equal()
Abstract
Compares two vectors to see whether they are identical.
Syntax
op_vvec_equal (vector1, vector2)
| Argument | Type | Description |
|---|---|---|
vector1 |
Vvec_Vector |
first of two value vectors to compare |
vector2 |
Vvec_Vector |
second of two value vectors to compare |
Return Type
int
OPC_TRUE if the vectors match, OPC_FALSE otherwise.
Example
/* determine if two value vectors are equal. */
if (op_vvec_equal (vector1, vector2))
{
/* vector1 and vector2 contain the same elements. */
printf ("Vectors are equal.\n");
}
else
{
/* Report on inequalities. */
size1 = op_vvec_size_get (vector1);
size2 = op_vvec_size_get (vector2);
if (size1 != size2)
{
printf ("Vectors have different sizes.\n);
printf (“ vector1: %d vector2: %d\n", size1, size2);
}
/* Find out where vector1 and vector2 do not match. */
size = (size1 < size2) ? size1 : size2; /* size of shorter vector */
for (i = 0; i < size; i++)
{
op_vvec_value_get (vector1, i, &val1);
op_vvec_value_get (vector2, i, &val2);
if (val1 != val2)
printf ("Values at position %d differ.\n", i);
}
}
Details
For op_vvec_equal() to return OPC_TRUE, vector1 must contain the same values in the same order as vector2. The two vectors must also have the same number of elements.
Purpose
Provide a mechanism to find out whether two vectors contain the same values.
Errors
- Recoverable Error: Value vector is invalid.
Reference
- Use the KP op_vvec_insert() to place elements from one vector into another
- Use the KP op_vvec_remove() to create a new vector consisting of elements removed from another vector