summaryrefslogtreecommitdiff
path: root/support/dktools/dk4bml.h
blob: 4d5a46c074732695361c08e145eca576977553e1 (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Copyright (C) 2019-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: dk4bml.ctr
*/

#ifndef DK4BML_H_INCLUDED
/** Avoid multiple inclusions. */
#define DK4BML_H_INCLUDED 1


#line 9 "dk4bml.ctr"

/**	@file	dk4bml.h	Levelize graph using a bit matrix.

	Levelizing means counting the path length from start nodes (nodes
	with no predecessor) to a certain node.

	Levelizing here must be able to handle loops.

	Two nodes are in the same loop if there is both a path from one node
	to the other and a path vice versa.

	Node a is a one-way predecessor of node b if a is a predecessor of b
	and there is a path from a to b but not path from b to a.
	This means a and b are not in the same loop.

	Nodes without a predecessor are level 0 nodes.

	In each pass all nodes not yet evaluated are checked.
	A node is evaluated if at least all one-way predecessor nodes are evaluated.
	The nodes value/level is the maximum value of all (not just the one-way)
	predecessors already evaluated, increased by one.

*/


#ifndef	DK4BM_H_INCLUDED
#if	DK4_BUILDING_DKTOOLS4
#include "dk4bm.h"
#else
#include <dktools-4/dk4bm.h>
#endif
#endif

#ifdef	__cplusplus
extern "C" {
#endif


/**	Levelize graph nodes.

	CRT on Windows: Optional.

	@param	pdest	Destination array for the node levels.
	@param	szdest	Size of destination array.
	@param	pbm		Bit matrix representing the graph.
	@param	isrev	Flag: Reverse notation is used in pbm.
	@param	erp		Error report, may be NULL.
	@return	1 on success, 0 on error.

	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  if pdest or pbm is NULL or szdest is 0,
	- DK4_E_SYNTAX<br>
	  if the matrix is not square or szdest is smaller then the number of rows,
	- DK4_E_MATH_OVERFLOW<br>
	  if a numeric overflow happens in size calculations for
	  temporary data,
	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
	  if a memory allocation attempt for temporary data fails.
*/

int
dk4bm_levelize(
	size_t					*pdest,
	size_t					 szdest,
	dk4_bit_matrix_t const	*pbm,
	int						 isrev,
	dk4_er_t				*erp
);


/**	Levelize graph nodes.

	CRT on Windows: Optional.

	@param	pdest	Destination array for the node levels.
	@param	szdest	Size of destination array.
	@param	pbm		Bit matrix representing the graph, must already be expanded.
	@param	isrev	Flag: Reverse notation is used in pbm.
	@param	erp		Error report, may be NULL.
	@return	1 on success, 0 on error.

	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  if pdest or pbm is NULL or szdest is 0,
	- DK4_E_SYNTAX<br>
	  if the matrix is not square or szdest is smaller then the number of rows,
	- DK4_E_MATH_OVERFLOW<br>
	  if a numeric overflow happens in size calculations for
	  temporary data,
	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
	  if a memory allocation attempt for temporary data fails.
*/

int
dk4bm_levelize_expanded(
	size_t					*pdest,
	size_t					 szdest,
	dk4_bit_matrix_t const	*pbm,
	int						 isrev,
	dk4_er_t				*erp
);


#ifdef	__cplusplus
}
#endif


#endif