Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
FULL SPEED; cut mif.is_connected by 90%
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Nov 7, 2024
1 parent 71bdb49 commit ab0a597
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/faebryk/core/cpp/include/graph/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class GraphInterface {

template <typename T> static std::shared_ptr<T> factory();
std::unordered_set<GI_ref_weak> get_gif_edges();
std::unordered_map<GI_ref_weak, Link_ref> get_edges();
std::unordered_map<GI_ref_weak, Link_ref> &get_edges();
std::optional<Link_ref> is_connected(GI_ref_weak to);
Graph_ref get_graph();
std::unordered_set<Node_ref> get_connected_nodes(std::vector<nb::type_object> types);
Expand Down Expand Up @@ -144,6 +144,7 @@ class Link {
class Graph {
Set<GI_ref> v;
std::vector<std::tuple<GI_ref_weak, GI_ref_weak, Link_ref>> e;

Map<GI_ref_weak, Map<GI_ref_weak, Link_ref>> e_cache = {};
Map<GI_ref_weak, Set<GI_ref_weak>> e_cache_simple = {};
bool invalidated = false;
Expand All @@ -156,7 +157,7 @@ class Graph {
static Graph_ref merge_graphs(Graph_ref g1, Graph_ref g2);

std::unordered_set<GI_ref_weak> get_gif_edges(GI_ref_weak from);
std::unordered_map<GI_ref_weak, Link_ref> get_edges(GI_ref_weak from);
std::unordered_map<GI_ref_weak, Link_ref> &get_edges(GI_ref_weak from);

Graph();
~Graph();
Expand Down
2 changes: 1 addition & 1 deletion src/faebryk/core/cpp/src/graph/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ std::unordered_set<GI_ref_weak> Graph::get_gif_edges(GI_ref_weak from) {
return this->e_cache_simple[from];
}

std::unordered_map<GI_ref_weak, Link_ref> Graph::get_edges(GI_ref_weak from) {
std::unordered_map<GI_ref_weak, Link_ref> &Graph::get_edges(GI_ref_weak from) {
return this->e_cache[from];
}

Expand Down
5 changes: 3 additions & 2 deletions src/faebryk/core/cpp/src/graph/graphinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "graph/graphinterfaces.hpp"
#include "graph/links.hpp"
#include "pyutil.hpp"
#include <chrono>

std::shared_ptr<Graph> GraphInterface::get_graph() {
return this->G;
Expand Down Expand Up @@ -71,7 +72,7 @@ void GraphInterface::register_graph(std::shared_ptr<GraphInterface> gi) {
}

std::optional<Link_ref> GraphInterface::is_connected(GI_ref_weak to) {
auto edges = this->get_edges();
auto &edges = this->get_edges();
auto edge = edges.find(to);
if (edge == edges.end()) {
return {};
Expand All @@ -83,7 +84,7 @@ Set<GI_ref_weak> GraphInterface::get_gif_edges() {
return this->G->get_gif_edges(this);
}

std::unordered_map<GI_ref_weak, Link_ref> GraphInterface::get_edges() {
std::unordered_map<GI_ref_weak, Link_ref> &GraphInterface::get_edges() {
return this->G->get_edges(this);
}

Expand Down

0 comments on commit ab0a597

Please sign in to comment.