Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/graphitemaster/dep_sort
Generic topological sorting for sorting a list of dependencies in C++17
https://github.com/graphitemaster/dep_sort
Last synced: about 2 months ago
JSON representation
Generic topological sorting for sorting a list of dependencies in C++17
- Host: GitHub
- URL: https://github.com/graphitemaster/dep_sort
- Owner: graphitemaster
- License: mit
- Created: 2018-10-18T09:19:40.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-18T09:30:55.000Z (about 6 years ago)
- Last Synced: 2024-08-04T02:09:39.587Z (5 months ago)
- Language: C++
- Size: 3.91 KB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- AwesomeCppGameDev - dep_sort
README
# Dependency sorting
Generic topological sorting for sorting a list of dependencies in C++17
# Use
There are two interfaces to choose from: `dep_sort_stl` and `dep_sort`.The first will use `std::vector`, `std::unordered_set` and `std::unordered_map`
to implement a highly efficent `O(V+E)` dependency resolver container.There's also however a `dep_sort` class which lets you supplement your
own `vector`, `set` and `map` implementions. You can use drop in
replacements like Google's `densehash` or `sparsehash` and stuff like
Boost's `multimap` if working with highly dense or sparse data.As a result this code has no real dependencies other than a working C++17
compiler.# Example
```cpp
int main() {
dep_sort_stl dep;
dep.add_node("a");
dep.add_node("b");
dep.add_node("c");
dep.add_node("d");
std::vector as = { "b", "c" };
std::vector bs = { "c" };
std::vector cs = { "d" };
dep.add_dependencies("a", as);
dep.add_dependencies("b", bs);
dep.add_dependencies("c", cs);
const auto& result = dep.sort();
if (!result.has_cycles()) {
// print the sorted list
for (const auto& value : result.sorted) {
std::cout << value << std::endl;
}
} else {
// print nodes that could not be sorted due to cycles
for (const auto& value : result.unsorted) {
std::cout << value << std::endl;
}
}
}
```# Documentation
The interfaces are documented in `dep_sort.h`