Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,21 @@ cc_library(
)


cc_library(
name = "fixed_graph",
hdrs = ["include/fixed_containers/fixed_graph.hpp"],
includes = includes_config(),
strip_include_prefix = strip_include_prefix_config(),
deps = [
":concepts",
":fixed_map",
":fixed_vector",
":preconditions",
":source_location",
],
copts = ["-std=c++20"],
)

cc_library(
name = "fixed_doubly_linked_list",
hdrs = ["include/fixed_containers/fixed_doubly_linked_list.hpp"],
Expand Down Expand Up @@ -1364,6 +1379,17 @@ cc_test(
)


cc_test(
name = "fixed_graph_test",
srcs = ["test/fixed_graph_test.cpp"],
deps = [
":fixed_graph",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
copts = ["-std=c++20"],
)

cc_test(
name = "fixed_doubly_linked_list_test",
srcs = ["test/fixed_doubly_linked_list_test.cpp"],
Expand Down
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The fixed-container types have identical APIs to their std:: equivalents, so you
| `FixedCircularQueue` | `std::queue` API with Circular Buffer semantics |
| `FixedBitset` | `std::bitset` |
| `FixedString` | `std::string` |
| `FixedGraph` | (no direct `std::` equivalent) |
| `FixedMap` | `std::map` |
| `FixedSet` | `std::set` |
| `FixedUnorderedMap` | `std::unordered_map` |
Expand Down Expand Up @@ -273,6 +274,63 @@ More examples can be found [here](test/enums_test_common.hpp).
static_assert(s1.max_size() == 11);
```

- FixedGraph
```C++
#include "fixed_containers/fixed_graph.hpp"
using namespace fixed_containers;

// Directed, unweighted graph with capacity for 8 nodes, up to 6 outgoing edges each
using Graph = FixedGraph<int, void, 8, 6, true>; // <NodeType, EdgeType=void (unweighted), MAX_NODES, MAX_EDGES_PER_NODE, DIRECTED>

constexpr auto g = []() {
Graph gr{};
auto a = gr.add_node(0);
auto b = gr.add_node(1);
auto c = gr.add_node(2);
gr.add_edge(a, b); // 0 -> 1
gr.add_edge(b, c); // 1 -> 2
gr.add_edge(a, c); // 0 -> 2
return gr;
}();

static_assert(g.node_count() == 3);
static_assert(g.has_edge(0, 1));
static_assert(g.has_edge(1, 2));
static_assert(g.shortest_path(0, 2).size() == 2); // 0 -> 2 direct

// Runtime example (BFS traversal)
void traverse() {
Graph gr{};
auto n0 = gr.add_node(0);
auto n1 = gr.add_node(1);
auto n2 = gr.add_node(2);
auto n3 = gr.add_node(3);
gr.add_edge(n0, n1);
gr.add_edge(n1, n2);
gr.add_edge(n0, n3);
gr.add_edge(n3, n2);

FixedVector<int, 8> order{};
gr.bfs(n0, [&](std::size_t idx){ order.push_back(static_cast<int>(gr.node_at(idx))); });
// 'order' now holds a BFS visitation order starting from node 0
}

// Weighted undirected example using double edge weights
using WUGraph = FixedGraph<int, double, 6, 6, false>; // undirected weighted
constexpr auto wug = [](){
WUGraph gr{};
auto a = gr.add_node(0);
auto b = gr.add_node(1);
auto c = gr.add_node(2);
gr.add_edge(a, b, 1.5);
gr.add_edge(b, c, 2.25);
gr.add_edge(a, c, 5.0);
// Dijkstra shortest path 0 -> 2 should pick 0-1-2 (1.5 + 2.25 = 3.75 < 5.0)
auto path = gr.dijkstra_shortest_path(a, c);
return gr;
}();
```

- EnumMap
```C++
enum class Color { RED, YELLOW, BLUE};
Expand Down
Loading