Arbiter
Dependency manager library that supports decentralization
Graph.h
Go to the documentation of this file.
1 #ifndef ARBITER_GRAPH_H
2 #define ARBITER_GRAPH_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include <stdbool.h>
9 #include <stddef.h>
10 
11 // forward declarations
12 struct ArbiterProjectIdentifier;
13 struct ArbiterRequirement;
14 struct ArbiterResolvedDependency;
15 struct ArbiterSelectedVersion;
16 
17 /**
18  * Represents a fully consistent, resolved dependency graph, preserving
19  * relationships between dependencies.
20  */
21 typedef struct ArbiterResolvedDependencyGraph ArbiterResolvedDependencyGraph;
22 
23 /**
24  * Creates an empty resolved dependency graph.
25  *
26  * The returned identifier must be freed with ArbiterFree().
27  */
28 ArbiterResolvedDependencyGraph *ArbiterResolvedDependencyGraphCreate (void);
29 
30 /**
31  * Attempts to add a root node into the dependency graph, without making it
32  * inconsistent.
33  *
34  * If the given dependency refers to a project which already exists in the
35  * graph, this will attempt to intersect the version requirements of both.
36  *
37  * Returns whether the addition succeeded. If `false` is returned and `error` is
38  * not NULL, it may be set to a string describing the error, which the caller is
39  * responsible for freeing.
40  */
41 bool ArbiterResolvedDependencyGraphAddRoot (ArbiterResolvedDependencyGraph *graph, const struct ArbiterResolvedDependency *node, const struct ArbiterRequirement *requirement, char **error);
42 
43 /**
44  * Attempts to add an edge (dependency relationship) into the dependency graph,
45  * from `dependent` to `dependency`, without making it inconsistent.
46  *
47  * If `dependency` refers to a project which already exists in the graph, this
48  * will attempt to intersect the version requirements of both.
49  *
50  * Returns whether the addition succeeded. If `false` is returned and `error` is
51  * not NULL, it may be set to a string describing the error, which the caller is
52  * responsible for freeing.
53  */
54 bool ArbiterResolvedDependencyGraphAddEdge (ArbiterResolvedDependencyGraph *graph, const struct ArbiterProjectIdentifier *dependent, const struct ArbiterResolvedDependency *dependency, const struct ArbiterRequirement *requirement, char **error);
55 
56 /**
57  * Returns the number of unique nodes in the given graph, for use with
58  * ArbiterResolvedDependencyGraphGetAll().
59  *
60  * The returned count may be invalidated if the graph is modified.
61  */
62 size_t ArbiterResolvedDependencyGraphCount (const ArbiterResolvedDependencyGraph *graph);
63 
64 /**
65  * Copies all of the resolved dependencies in the given graph into the C array
66  * `buffer`, which must have enough space to contain
67  * ArbiterResolvedDependencyGraphCount() elements.
68  *
69  * This operation does not guarantee a specific ordering to the copied items.
70  *
71  * The copied objects must be individually freed with ArbiterFree().
72  */
73 void ArbiterResolvedDependencyGraphCopyAll (const ArbiterResolvedDependencyGraph *graph, struct ArbiterResolvedDependency **buffer);
74 
75 /**
76  * Returns the version which was selected for the given project in the
77  * dependency graph, or NULL if the project is not part of the graph.
78  *
79  * The returned pointer is guaranteed to remain valid until the
80  * ArbiterResolvedDependencyGraph it was obtained from is modified or freed.
81  */
82 const struct ArbiterSelectedVersion *ArbiterResolvedDependencyGraphProjectVersion (const ArbiterResolvedDependencyGraph *graph, const struct ArbiterProjectIdentifier *project);
83 
84 /**
85  * Returns the requirement which is attached to the given project in the
86  * dependency graph, or NULL if the project is not part of the graph.
87  *
88  * The returned pointer is guaranteed to remain valid until the
89  * ArbiterResolvedDependencyGraph it was obtained from is modified or freed.
90  */
91 const struct ArbiterRequirement *ArbiterResolvedDependencyGraphProjectRequirement (const ArbiterResolvedDependencyGraph *graph, const struct ArbiterProjectIdentifier *project);
92 
93 /**
94  * Returns the number of dependencies that the given project has in the graph,
95  * or 0 if the project does not exist in the graph.
96  *
97  * The returned count may be invalidated if the graph is modified.
98  */
99 size_t ArbiterResolvedDependencyGraphCountDependencies (const ArbiterResolvedDependencyGraph *graph, const struct ArbiterProjectIdentifier *project);
100 
101 /**
102  * Copies pointers to the projects representing the given project's dependencies
103  * into the C array `buffer`, which must have enough space to contain
104  * ArbiterResolvedDependencyGraphCountDependencies() elements.
105  *
106  * This operation guarantees that project identifiers will appear in the buffer
107  * in ascending order.
108  *
109  * The copied pointers are guaranteed to remain valid until the
110  * ArbiterResolvedDependencyGraph they were obtained from is modified or freed.
111  */
112 void ArbiterResolvedDependencyGraphGetAllDependencies (const ArbiterResolvedDependencyGraph *graph, const struct ArbiterProjectIdentifier *project, const struct ArbiterProjectIdentifier **buffer);
113 
114 /**
115  * Enumerates a resolved dependency graph in "install order," where all projects
116  * listed within one phase may be safely installed in parallel with respect to
117  * each another, and the projects within _each successive phase_ must be
118  * installed only after the projects in _all previous phases_ have been
119  * completely installed.
120  */
121 typedef struct ArbiterResolvedDependencyInstaller ArbiterResolvedDependencyInstaller;
122 
123 /**
124  * Creates an installer for the given resolved dependency graph.
125  *
126  * The dependency graph can be safely freed after calling this function.
127  *
128  * The returned installer must be freed with ArbiterFree().
129  */
130 ArbiterResolvedDependencyInstaller *ArbiterResolvedDependencyInstallerCreate (const ArbiterResolvedDependencyGraph *graph);
131 
132 /**
133  * Returns the number of phases that the installer has, for use with
134  * ArbiterResolvedDependencyInstallerCountInPhase() and
135  * ArbiterResolvedDependencyInstallerGetAllInPhase().
136  */
137 size_t ArbiterResolvedDependencyInstallerPhaseCount (const ArbiterResolvedDependencyInstaller *installer);
138 
139 /**
140  * Returns the number of resolved dependencies that exist within the given
141  * zero-based installer phase, for use with
142  * ArbiterResolvedDependencyInstallerGetAllInPhase().
143  *
144  * This represents a set of projects which can safely be built or installed in
145  * parallel with one another.
146  */
147 size_t ArbiterResolvedDependencyInstallerCountInPhase (const ArbiterResolvedDependencyInstaller *installer, size_t phaseIndex);
148 
149 /**
150  * Copies pointers to the resolved dependencies which exist at the given
151  * zero-based installer phase into the C array `buffer`, which must have enough
152  * space to contain ArbiterResolvedDependencyInstallerCountInPhase() elements.
153  *
154  * This operation guarantees that resolved dependencies will appear in the
155  * buffer in ascending order of their project identifiers.
156  *
157  * The copied pointers are guaranteed to remain valid until the
158  * ArbiterResolvedDependencyInstaller they were obtained from is freed.
159  */
160 void ArbiterResolvedDependencyInstallerGetAllInPhase (const ArbiterResolvedDependencyInstaller *installer, size_t phaseIndex, const struct ArbiterResolvedDependency **buffer);
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif
bool ArbiterResolvedDependencyGraphAddRoot(ArbiterResolvedDependencyGraph *graph, const struct ArbiterResolvedDependency *node, const struct ArbiterRequirement *requirement, char **error)
Attempts to add a root node into the dependency graph, without making it inconsistent.
bool ArbiterResolvedDependencyGraphAddEdge(ArbiterResolvedDependencyGraph *graph, const struct ArbiterProjectIdentifier *dependent, const struct ArbiterResolvedDependency *dependency, const struct ArbiterRequirement *requirement, char **error)
Attempts to add an edge (dependency relationship) into the dependency graph, from dependent to depend...
void ArbiterResolvedDependencyGraphCopyAll(const ArbiterResolvedDependencyGraph *graph, struct ArbiterResolvedDependency **buffer)
Copies all of the resolved dependencies in the given graph into the C array buffer, which must have enough space to contain ArbiterResolvedDependencyGraphCount() elements.
const struct ArbiterSelectedVersion * ArbiterResolvedDependencyGraphProjectVersion(const ArbiterResolvedDependencyGraph *graph, const struct ArbiterProjectIdentifier *project)
Returns the version which was selected for the given project in the dependency graph, or NULL if the project is not part of the graph.
size_t ArbiterResolvedDependencyGraphCountDependencies(const ArbiterResolvedDependencyGraph *graph, const struct ArbiterProjectIdentifier *project)
Returns the number of dependencies that the given project has in the graph, or 0 if the project does ...
const struct ArbiterRequirement * ArbiterResolvedDependencyGraphProjectRequirement(const ArbiterResolvedDependencyGraph *graph, const struct ArbiterProjectIdentifier *project)
Returns the requirement which is attached to the given project in the dependency graph, or NULL if the project is not part of the graph.
size_t ArbiterResolvedDependencyInstallerCountInPhase(const ArbiterResolvedDependencyInstaller *installer, size_t phaseIndex)
Returns the number of resolved dependencies that exist within the given zero-based installer phase...
size_t ArbiterResolvedDependencyInstallerPhaseCount(const ArbiterResolvedDependencyInstaller *installer)
Returns the number of phases that the installer has, for use with ArbiterResolvedDependencyInstallerC...
ArbiterResolvedDependencyGraph * ArbiterResolvedDependencyGraphCreate(void)
Creates an empty resolved dependency graph.
ArbiterResolvedDependencyInstaller * ArbiterResolvedDependencyInstallerCreate(const ArbiterResolvedDependencyGraph *graph)
Creates an installer for the given resolved dependency graph.
virtual std::unique_ptr< ArbiterRequirement > intersect(const ArbiterRequirement &rhs) const =0
Attempts to create a requirement which expresses the intersection of this requirement and the given o...
void ArbiterResolvedDependencyGraphGetAllDependencies(const ArbiterResolvedDependencyGraph *graph, const struct ArbiterProjectIdentifier *project, const struct ArbiterProjectIdentifier **buffer)
Copies pointers to the projects representing the given project&#39;s dependencies into the C array buffer...
size_t ArbiterResolvedDependencyGraphCount(const ArbiterResolvedDependencyGraph *graph)
Returns the number of unique nodes in the given graph, for use with ArbiterResolvedDependencyGraphGet...
void ArbiterResolvedDependencyInstallerGetAllInPhase(const ArbiterResolvedDependencyInstaller *installer, size_t phaseIndex, const struct ArbiterResolvedDependency **buffer)
Copies pointers to the resolved dependencies which exist at the given zero-based installer phase into...