}
/** Compute elementwise minimum. */
-void vc_min(VectorClock* const result,
- const VectorClock* const rhs)
+void vc_min(VectorClock* const result, const VectorClock* const rhs)
{
unsigned i;
unsigned j;
- unsigned shared;
- unsigned new_size;
tl_assert(result);
tl_assert(rhs);
- /* First count the number of shared thread ID's. */
- j = 0;
- shared = 0;
- for (i = 0; i < result->size; i++)
- {
- while (j < rhs->size && rhs->vc[j].threadid < result->vc[i].threadid)
- j++;
- if (j >= rhs->size)
- break;
- if (result->vc[i].threadid == rhs->vc[j].threadid)
- shared++;
- }
-
- vc_check(result);
-
- new_size = result->size + rhs->size - shared;
- if (new_size > result->capacity)
- vc_reserve(result, new_size);
-
vc_check(result);
/* Next, combine both vector clocks into one. */
i = 0;
for (j = 0; j < rhs->size; j++)
{
- vc_check(result);
-
while (i < result->size && result->vc[i].threadid < rhs->vc[j].threadid)
{
/* Thread ID is missing in second vector clock. Clear the count. */
}
if (i >= result->size)
{
- result->size++;
- result->vc[i] = rhs->vc[j];
- vc_check(result);
- }
- else if (result->vc[i].threadid > rhs->vc[j].threadid)
- {
- /* Thread ID is missing in first vector clock. Leave out. */
+ break;
}
- else
+ if (result->vc[i].threadid <= rhs->vc[j].threadid)
{
/* The thread ID is present in both vector clocks. Compute the minimum */
/* of vc[i].count and vc[j].count. */
{
result->vc[i].count = rhs->vc[j].count;
}
- vc_check(result);
}
}
vc_check(result);
i = 0;
for (j = 0; j < rhs->size; j++)
{
- vc_check(result);
-
while (i < result->size && result->vc[i].threadid < rhs->vc[j].threadid)
i++;
if (i >= result->size)
{
result->size++;
result->vc[i] = rhs->vc[j];
- vc_check(result);
}
else if (result->vc[i].threadid > rhs->vc[j].threadid)
{
}
result->size++;
result->vc[i] = rhs->vc[j];
- vc_check(result);
}
else
{
{
result->vc[i].count = rhs->vc[j].count;
}
- vc_check(result);
}
}
vc_check(result);