Open SCAP Library
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
src
common
tsort.h
1
/*
2
* Copyright 2010 Red Hat Inc., Durham, North Carolina.
3
* All Rights Reserved.
4
*
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
9
*
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
14
*
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Authors:
20
* Lukas Kuklinek <lkuklinek@redhat.com>
21
*/
22
23
24
// topological sort
25
26
#include "list.h"
27
28
#ifndef OSCAP_TSORT_H_
29
#define OSCAP_TSORT_H_
30
31
OSCAP_HIDDEN_START;
32
33
// returns nodest with an edge from given node
34
typedef
struct
oscap_list
* (*oscap_tsort_edge_func)(
void
*node,
void
*userdata);
35
36
/*
37
* Topological sort.
38
*
39
* Performs a topological sort on a directed graph.
40
*
41
* @a edge_func is supposed to return an oscap_list of nodes edges coming from the current node
42
* (passed to it as an argument) are pointing to. It takes the node as a first argument
43
* and a pointer passed as @a userdata as a second argument.
44
*
45
* The purpose of @a cmp_func is to compare nodes. If it is NULL raw pointer comparison
46
* is used, which should be good enough in most cases.
47
*
48
* Pointer @a output will be set to a list with result. If you want to just check whether
49
* there is a topological order defined on the graph (i.e. it is an acyclic graph), pass NULL.
50
* If the function manages to find a topological order of the nodes (returns true),
51
* it is returned in this variable. Otherwise, it will contain an encountered loop.
52
* You are responsible to free this list.
53
*
54
* @param input set of nodes to sort
55
* @param output this pointer will be set to the result of the algorithm
56
* @param edge_func function to return target nodes of outgoing edges from the current one
57
* @param cmp_func node compasrison function
58
* @param userdata arbitrary data pointer to be forwarded to the edge_func
59
* @returns whether the algorithm managed to topologically sort the graph
60
* @retval true input was sorted, result is in the *output pointer
61
* @retval false a loop was detected, *output points to the encountered loop
62
*/
63
bool
oscap_tsort(
struct
oscap_list
*input,
struct
oscap_list
**output, oscap_tsort_edge_func edge_func, oscap_cmp_func cmp_func,
void
*userdata);
64
65
OSCAP_HIDDEN_END;
66
67
#endif // OSCAP_TSORT_H_
68
oscap_list
Definition:
list.h:54
Generated by
1.8.5