2007-06-11 13:01:04 +01:00
|
|
|
/*
|
|
|
|
* Scyther : An automatic verifier for security protocols.
|
|
|
|
* Copyright (C) 2007 Cas Cremers
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|