Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / byacc / dist / warshall.c
blobdce9f160cafd146838f16085719afa15adedd99f
1 /* $NetBSD$ */
2 /* Id: warshall.c,v 1.6 2008/11/24 21:30:35 tom Exp */
4 #include "defs.h"
6 #include <sys/cdefs.h>
7 __RCSID("$NetBSD: warshall.c,v 1.8 2006/05/24 18:01:43 christos Exp $");
9 static void
10 transitive_closure(unsigned *R, int n)
12 int rowsize;
13 unsigned i;
14 unsigned *rowj;
15 unsigned *rp;
16 unsigned *rend;
17 unsigned *ccol;
18 unsigned *relend;
19 unsigned *cword;
20 unsigned *rowi;
22 rowsize = WORDSIZE(n);
23 relend = R + n * rowsize;
25 cword = R;
26 i = 0;
27 rowi = R;
28 while (rowi < relend)
30 ccol = cword;
31 rowj = R;
33 while (rowj < relend)
35 if (*ccol & (1 << i))
37 rp = rowi;
38 rend = rowj + rowsize;
39 while (rowj < rend)
40 *rowj++ |= *rp++;
42 else
44 rowj += rowsize;
47 ccol += rowsize;
50 if (++i >= BITS_PER_WORD)
52 i = 0;
53 cword++;
56 rowi += rowsize;
60 void
61 reflexive_transitive_closure(unsigned *R, int n)
63 int rowsize;
64 unsigned i;
65 unsigned *rp;
66 unsigned *relend;
68 transitive_closure(R, n);
70 rowsize = WORDSIZE(n);
71 relend = R + n * rowsize;
73 i = 0;
74 rp = R;
75 while (rp < relend)
77 *rp |= (1 << i);
78 if (++i >= BITS_PER_WORD)
80 i = 0;
81 rp++;
84 rp += rowsize;