Commit | Line | Data |
---|---|---|
26b5ab8e KB |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Robert Paul Corbett. | |
7 | * | |
8 | * Redistribution and use in source and binary forms are permitted | |
9 | * provided that the above copyright notice and this paragraph are | |
10 | * duplicated in all such forms and that any documentation, | |
11 | * advertising materials, and other materials related to such | |
12 | * distribution and use acknowledge that the software was developed | |
13 | * by the University of California, Berkeley. The name of the | |
14 | * University may not be used to endorse or promote products derived | |
15 | * from this software without specific prior written permission. | |
16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
17 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
19 | */ | |
20 | ||
21 | #ifndef lint | |
22 | static char sccsid[] = "@(#)warshall.c 5.1 (Berkeley) %G%"; | |
23 | #endif /* not lint */ | |
24 | ||
25 | #include "defs.h" | |
26 | ||
27 | transitive_closure(R, n) | |
28 | unsigned *R; | |
29 | int n; | |
30 | { | |
31 | register int rowsize; | |
32 | register unsigned mask; | |
33 | register unsigned *rowj; | |
34 | register unsigned *rp; | |
35 | register unsigned *rend; | |
36 | register unsigned *ccol; | |
37 | ||
38 | unsigned *relend; | |
39 | unsigned *cword; | |
40 | unsigned *rowi; | |
41 | ||
42 | rowsize = ROWSIZE(n); | |
43 | relend = (unsigned *) ((unsigned) R + n*rowsize); | |
44 | ||
45 | cword = R; | |
46 | mask = 1; | |
47 | rowi = R; | |
48 | while (rowi < relend) | |
49 | { | |
50 | ccol = cword; | |
51 | rowj = R; | |
52 | ||
53 | while (rowj < relend) | |
54 | { | |
55 | if (*ccol & mask) | |
56 | { | |
57 | rp = rowi; | |
58 | rend = (unsigned *) ((unsigned) rowj + rowsize); | |
59 | ||
60 | while (rowj < rend) | |
61 | *rowj++ |= *rp++; | |
62 | } | |
63 | else | |
64 | { | |
65 | rowj = (unsigned *) ((unsigned) rowj + rowsize); | |
66 | } | |
67 | ||
68 | ccol = (unsigned *) ((unsigned) ccol + rowsize); | |
69 | } | |
70 | ||
71 | mask <<= 1; | |
72 | if (mask == 0) | |
73 | { | |
74 | mask = 1; | |
75 | cword++; | |
76 | } | |
77 | ||
78 | rowi = (unsigned *) ((unsigned) rowi + rowsize); | |
79 | } | |
80 | } | |
81 | ||
82 | reflexive_transitive_closure(R, n) | |
83 | unsigned *R; | |
84 | int n; | |
85 | { | |
86 | register int rowsize; | |
87 | register unsigned mask; | |
88 | register unsigned *rp; | |
89 | register unsigned *relend; | |
90 | ||
91 | transitive_closure(R, n); | |
92 | ||
93 | rowsize = ROWSIZE(n); | |
94 | relend = (unsigned *) ((unsigned) R + n*rowsize); | |
95 | ||
96 | mask = 1; | |
97 | rp = R; | |
98 | while (rp < relend) | |
99 | { | |
100 | *rp |= mask; | |
101 | ||
102 | mask <<= 1; | |
103 | if (mask == 0) | |
104 | { | |
105 | mask = 1; | |
106 | rp++; | |
107 | } | |
108 | ||
109 | rp = (unsigned *) ((unsigned) rp + rowsize); | |
110 | } | |
111 | } |