home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 22 gnu
/
22-gnu.zip
/
BYACC.ZIP
/
WARSHALL.C
< prev
Wrap
C/C++ Source or Header
|
1992-03-16
|
1KB
|
87 lines
#include <stdlib.h>
#include "byacc.h"
void
transitive_closure(unsigned *R, int n)
{
register int rowsize;
register unsigned mask;
register unsigned *rowj;
register unsigned *rp;
register unsigned *rend;
register unsigned *ccol;
unsigned *relend;
unsigned *cword;
unsigned *rowi;
rowsize = ROWSIZE(n);
relend = (unsigned *) ((char *) R + n*rowsize);
cword = R;
mask = 1;
rowi = R;
while (rowi < relend)
{
ccol = cword;
rowj = R;
while (rowj < relend)
{
if (*ccol & mask)
{
rp = rowi;
rend = (unsigned *) ((char*) rowj + rowsize);
while (rowj < rend)
*rowj++ |= *rp++;
}
else
{
rowj = (unsigned *) ((char*) rowj + rowsize);
}
ccol = (unsigned *) ((char*) ccol + rowsize);
}
mask <<= 1;
if (mask == 0)
{
mask = 1;
cword++;
}
rowi = (unsigned *) ((char*) rowi + rowsize);
}
}
void
reflexive_transitive_closure(unsigned * R, int n)
{
register int rowsize;
register unsigned mask;
register unsigned *rp;
register unsigned *relend;
transitive_closure(R, n);
rowsize = ROWSIZE(n);
relend = (unsigned *) ((char*) R + n*rowsize);
mask = 1;
rp = R;
while (rp < relend)
{
*rp |= mask;
mask <<= 1;
if (mask == 0)
{
mask = 1;
rp++;
}
rp = (unsigned *) ((char*) rp + rowsize);
}
}