- Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfloydWarshall.h
114 lines (99 loc) · 2.97 KB
/
floydWarshall.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* pthreadChannel - an implementation of channels for pthreads
* Copyright (C) 2016-2024 G. David Butler <gdb@dbSystems.com>
*
* This file is part of pthreadChannel
*
* pthreadChannel is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* pthreadChannel 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* https://en.wikipedia.org/wiki/Floyd–Warshall_algorithm */
/* https://moorejs.github.io/APSP-in-parallel/ */
/* FWCST signed type to use for cost */
/* FWNXT unsigned type to use for next */
/* FWEQL keep equal cost next */
/* FWBLK use blocks and threads */
/* pick infinite "cost" char:2^7-1 short:2^15-1 int:2^31-1 long,long:2^63-1 */
#ifdefFWCST
typedefFWCSTfwCst_t;
#else
typedefintfwCst_t;
#endif
/* pick max "vertices" char:2^8 short:2^16 int:2^32 long,long:2^64 */
#ifdefFWNXT
typedefunsigned FWNXTfwNxt_t;
#else
typedefunsigned intfwNxt_t;
#endif
#ifdefFWEQL
structfwNxt {
fwNxt_t*x;
fwNxt_tl; /* if !x, this is the next, otherwise, a count of next */
};
#endif/* FWEQL */
structfw {
fwCst_t*cst; /* cost matrix */
#ifdefFWEQL
structfwNxt*nxt; /* next matrix */
#else/* FWEQL */
fwNxt_t*nxt; /* next matrix */
#endif/* FWEQL */
fwNxt_td; /* matrix dimension */
#ifdefFWBLK
fwNxt_tb; /* blocking factor */
#endif/* FWBLK */
};
void
fwFree(
structfw*v
);
/* cost inialized to infinite and next inialized to 0 */
structfw*
fwAlloc(
unsigned long d
#ifdefFWBLK
,fwNxt_tb/* dependent on target processor cache size */
#endif/* FWBLK */
);
/* duplicate content */
structfw*
fwDup(
conststructfw*v
);
/* compare content */
int
fwCmp(
conststructfw*v1
,conststructfw*v2
);
int
fwProcess(
structfw*v
#ifdefFWBLK
,fwNxt_tp
#endif/* FWBLK */
);
#ifdefFWSQLITE
/* SQLITE virtual table read acces to cost array */
/* sqlite3_create_module(sqlite3 *, "fwc", &fwcMod, 0) */
/* sqlite3_prepare_v2(sqlite3 *, "SELECT f AS \"from\", t AS \"to\", c AS \"cost\" FROM Fwc(?1)", -1, sqlite3_stmt *, 0) */
/* sqlite3_bind_pointer(sqlite3_stmt *, 1, struct fw *, "fw", 0) */
/* SQLITE virtual table read acces to next array */
/* sqlite3_create_module(sqlite3 *, "fwn", &fwnMod, 0) */
/* sqlite3_prepare_v2(sqlite3 *, "SELECT f AS \"from\", t AS \"to\", o AS \"ordinal\", n AS \"nextHop\" FROM Fwn(?1)", -1, sqlite3_stmt *, 0) */
/* sqlite3_bind_pointer(sqlite3_stmt *, 1, struct fw *, "fw", 0) */
externsqlite3_module
fwcMod;
externsqlite3_module
fwnMod;
#endif/* FWSQLITE */