2006-02-26 15:00:58 +00:00
|
|
|
// @file warshall.c
|
|
|
|
/* Based on public-domain code from Berkeley Yacc */
|
2004-08-16 10:50:37 +01:00
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
#include "warshall.h"
|
|
|
|
|
2004-08-16 10:50:37 +01:00
|
|
|
void
|
2006-02-26 15:00:58 +00:00
|
|
|
transitive_closure (unsigned int *R, int n)
|
2004-08-16 10:50:37 +01:00
|
|
|
{
|
2006-02-26 15:00:58 +00:00
|
|
|
register int rowsize;
|
|
|
|
register unsigned mask;
|
|
|
|
register unsigned *rowj;
|
|
|
|
register unsigned *rp;
|
|
|
|
register unsigned *rend;
|
|
|
|
register unsigned *ccol;
|
|
|
|
register unsigned *relend;
|
|
|
|
register unsigned *cword;
|
|
|
|
register unsigned *rowi;
|
|
|
|
|
|
|
|
rowsize = WORDSIZE (n);
|
|
|
|
relend = R + n * rowsize;
|
|
|
|
|
|
|
|
cword = R;
|
|
|
|
mask = 1;
|
|
|
|
rowi = R;
|
|
|
|
while (rowi < relend)
|
2004-08-16 10:50:37 +01:00
|
|
|
{
|
2006-02-26 15:00:58 +00:00
|
|
|
ccol = cword;
|
|
|
|
rowj = R;
|
2004-08-16 10:50:37 +01:00
|
|
|
|
2006-02-26 15:00:58 +00:00
|
|
|
while (rowj < relend)
|
2004-08-17 10:48:29 +01:00
|
|
|
{
|
2006-02-26 15:00:58 +00:00
|
|
|
if (*ccol & mask)
|
|
|
|
{
|
|
|
|
rp = rowi;
|
|
|
|
rend = rowj + rowsize;
|
|
|
|
while (rowj < rend)
|
|
|
|
*rowj++ |= *rp++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rowj += rowsize;
|
|
|
|
}
|
2004-08-16 10:50:37 +01:00
|
|
|
|
2006-02-26 15:00:58 +00:00
|
|
|
ccol += rowsize;
|
|
|
|
}
|
2004-08-16 10:50:37 +01:00
|
|
|
|
2006-02-26 15:00:58 +00:00
|
|
|
mask <<= 1;
|
|
|
|
if (mask == 0)
|
2004-08-16 10:50:37 +01:00
|
|
|
{
|
2006-02-26 15:00:58 +00:00
|
|
|
mask = 1;
|
|
|
|
cword++;
|
2004-08-16 10:50:37 +01:00
|
|
|
}
|
2006-02-26 15:00:58 +00:00
|
|
|
|
|
|
|
rowi += rowsize;
|
2004-08-16 10:50:37 +01:00
|
|
|
}
|
|
|
|
}
|
2004-10-25 15:28:53 +01:00
|
|
|
|
2006-02-26 15:00:58 +00:00
|
|
|
void
|
|
|
|
reflexive_transitive_closure (unsigned int *R, int n)
|
2004-10-25 15:28:53 +01:00
|
|
|
{
|
2006-02-26 15:00:58 +00:00
|
|
|
register int rowsize;
|
|
|
|
register unsigned mask;
|
|
|
|
register unsigned *rp;
|
|
|
|
register unsigned *relend;
|
2004-10-25 15:28:53 +01:00
|
|
|
|
2006-02-26 15:00:58 +00:00
|
|
|
transitive_closure (R, n);
|
2004-10-25 15:28:53 +01:00
|
|
|
|
2006-02-26 15:00:58 +00:00
|
|
|
rowsize = WORDSIZE (n);
|
|
|
|
relend = R + n * rowsize;
|
2004-10-25 15:28:53 +01:00
|
|
|
|
2006-02-26 15:00:58 +00:00
|
|
|
mask = 1;
|
|
|
|
rp = R;
|
|
|
|
while (rp < relend)
|
|
|
|
{
|
|
|
|
*rp |= mask;
|
|
|
|
mask <<= 1;
|
|
|
|
if (mask == 0)
|
2004-10-25 15:28:53 +01:00
|
|
|
{
|
2006-02-26 15:00:58 +00:00
|
|
|
mask = 1;
|
|
|
|
rp++;
|
2004-10-25 15:28:53 +01:00
|
|
|
}
|
2006-02-26 15:00:58 +00:00
|
|
|
|
|
|
|
rp += rowsize;
|
2004-10-25 15:28:53 +01:00
|
|
|
}
|
|
|
|
}
|