diff --git a/.gitignore b/.gitignore index f982ca42..e9886f10 100644 --- a/.gitignore +++ b/.gitignore @@ -31,8 +31,12 @@ *.out *.app -# ignore the build folder contents from git +# ignore the build folder contents build/ +# ignore ctest files +Testing/ +# ignore cmake generated files +include/CXXGraph/CXXGraphConfig.h # ignore the packaging folder contents from git packaging/ # ignore vscode files diff --git a/CXXGraphConfig.h.in b/CXXGraphConfig.h.in index dd946630..802a9f30 100644 --- a/CXXGraphConfig.h.in +++ b/CXXGraphConfig.h.in @@ -1,4 +1,57 @@ // the configured options and settings for CXXGraph #define CXXGraph_VERSION_MAJOR @CXXGraph_VERSION_MAJOR@ #define CXXGraph_VERSION_MINOR @CXXGraph_VERSION_MINOR@ -#define CXXGraph_VERSION_PATCH @CXXGraph_VERSION_PATCH@ \ No newline at end of file +#define CXXGraph_VERSION_PATCH @CXXGraph_VERSION_PATCH@ + +#pragma once +#if defined(CXXGraph_CUSTOM_MAP_HEADER) +// Very custom types, not explictly supported. +// Should be usable as a replacement std::unordered_map and set. +# if defined(CXXGraph_NO_CUSTOM_MAP_HEADER_INCLUDE) +// User does not want us to include the custom map header +// They might not want to define lots of macros +// They will have to do all the includes themselves +# elif !__has_include( CXXGraph_CUSTOM_MAP_HEADER ) +# error "CXXGraph_CUSTOM_MAP_HEADER is defined but is not a valid include path. \ +Use CXXGraph_NO_CUSTOM_MAP_HEADER_INCLUDE to disable this check" +# else +// If one include is fine, assume the rest are also fine. +# include CXXGraph_CUSTOM_MAP_HEADER +# include CXXGraph_CUSTOM_SET_HEADER +# include CXXGraph_CUSTOM_ORDERED_SET_HEADER +# include CXXGraph_CUSTOM_ORDERED_MAP_HEADER +// Users are expected to declare types in our namespace (saves us gessing what they are) +# endif +#elif __has_include() +// Frozen library is available, use it for better performance +# include +# include +# include +# include + + namespace CXXGraph { + template + using Map = frozen::unordered_map; + template + using OrderedMap = frozen::map; + template + using OrderedSet = frozen::set; + template + using Set = frozen::set; + } +#else +# include +# include +# include +# include + namespace CXXGraph { + template + using Map = std::unordered_map; + template + using OrderedMap = std::map; + template + using Set = std::unordered_set; + template + using OrderedSet = std::set; + } +#endif diff --git a/benchmark/BFS_BM.cpp b/benchmark/BFS_BM.cpp index ed0d07ef..ad966c3c 100644 --- a/benchmark/BFS_BM.cpp +++ b/benchmark/BFS_BM.cpp @@ -7,7 +7,7 @@ static void BFS_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); @@ -39,7 +39,7 @@ static void PSEUDO_CONCURRENCY_BFS_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); @@ -70,7 +70,7 @@ static void CONCURRENCY_BFS_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/BellmanFord_BM.cpp b/benchmark/BellmanFord_BM.cpp index 092dd64f..e11c87ff 100644 --- a/benchmark/BellmanFord_BM.cpp +++ b/benchmark/BellmanFord_BM.cpp @@ -7,7 +7,7 @@ static void BellmanFord_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/Boruvka_BM.cpp b/benchmark/Boruvka_BM.cpp index 66748cbc..9fe7feb8 100644 --- a/benchmark/Boruvka_BM.cpp +++ b/benchmark/Boruvka_BM.cpp @@ -7,7 +7,7 @@ static void Boruvka_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/Connectivity_BM.cpp b/benchmark/Connectivity_BM.cpp index ad293249..b8d256b0 100644 --- a/benchmark/Connectivity_BM.cpp +++ b/benchmark/Connectivity_BM.cpp @@ -7,7 +7,7 @@ static void Connectivity_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); @@ -36,7 +36,7 @@ static void StrongConnectivity_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/CycleCheck_BM.cpp b/benchmark/CycleCheck_BM.cpp index fee1c09b..19ca7698 100644 --- a/benchmark/CycleCheck_BM.cpp +++ b/benchmark/CycleCheck_BM.cpp @@ -7,7 +7,7 @@ static void CycleCheckBFS_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); @@ -36,7 +36,7 @@ static void CycleCheckDFS_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/DFS_BM.cpp b/benchmark/DFS_BM.cpp index f1073ce4..89602d9e 100644 --- a/benchmark/DFS_BM.cpp +++ b/benchmark/DFS_BM.cpp @@ -7,7 +7,7 @@ static void DFS_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/Dial_BM.cpp b/benchmark/Dial_BM.cpp index 76ad1abb..606b9581 100644 --- a/benchmark/Dial_BM.cpp +++ b/benchmark/Dial_BM.cpp @@ -7,7 +7,7 @@ static void Dial_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/Dijkstra_BM.cpp b/benchmark/Dijkstra_BM.cpp index 53dd7519..6ee22797 100644 --- a/benchmark/Dijkstra_BM.cpp +++ b/benchmark/Dijkstra_BM.cpp @@ -7,7 +7,7 @@ static void Dijkstra_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/EulerPath_BM.cpp b/benchmark/EulerPath_BM.cpp index a54b4566..e9a0df33 100644 --- a/benchmark/EulerPath_BM.cpp +++ b/benchmark/EulerPath_BM.cpp @@ -7,7 +7,7 @@ static void EulerPath_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = undirectedEdges.begin(); auto range_end = undirectedEdges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/FordFulkerson_BM.cpp b/benchmark/FordFulkerson_BM.cpp index 6ad1c856..29742e0d 100644 --- a/benchmark/FordFulkerson_BM.cpp +++ b/benchmark/FordFulkerson_BM.cpp @@ -7,7 +7,7 @@ static void FordFulkerson_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/GraphSlicing_BM.cpp b/benchmark/GraphSlicing_BM.cpp index 201414e3..7746c20c 100644 --- a/benchmark/GraphSlicing_BM.cpp +++ b/benchmark/GraphSlicing_BM.cpp @@ -7,7 +7,7 @@ static void GraphSlicing_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/Graph_BM.cpp b/benchmark/Graph_BM.cpp index 84e4d3c9..bcbcff26 100644 --- a/benchmark/Graph_BM.cpp +++ b/benchmark/Graph_BM.cpp @@ -30,7 +30,7 @@ static void AddEdgeX(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto _ : state) { for (auto e : edgesX) { @@ -58,7 +58,7 @@ static void getEdgeSetX(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); @@ -78,7 +78,7 @@ static void getNodeSetX(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); @@ -116,7 +116,7 @@ static void getAdjMatrixX(benchmark::State &state) { CXXGraph::Graph g; auto range_start = undirectedEdges.begin(); auto range_end = undirectedEdges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/Kosaraju_BM.cpp b/benchmark/Kosaraju_BM.cpp index ec3e6201..cbb3f02d 100644 --- a/benchmark/Kosaraju_BM.cpp +++ b/benchmark/Kosaraju_BM.cpp @@ -7,7 +7,7 @@ static void Kosaraju_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/Kruskal_BM.cpp b/benchmark/Kruskal_BM.cpp index a7cc216f..78775c63 100644 --- a/benchmark/Kruskal_BM.cpp +++ b/benchmark/Kruskal_BM.cpp @@ -7,7 +7,7 @@ static void Kruskal_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/Partition_BM.cpp b/benchmark/Partition_BM.cpp index 64be59d0..c18be72c 100644 --- a/benchmark/Partition_BM.cpp +++ b/benchmark/Partition_BM.cpp @@ -7,7 +7,7 @@ static void PartitionHDRF_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); @@ -38,7 +38,7 @@ static void PartitionEBVC_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); @@ -70,7 +70,7 @@ static void PartitionGVC_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); @@ -102,7 +102,7 @@ static void PartitionEBV_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/Prim_BM.cpp b/benchmark/Prim_BM.cpp index 78371e05..ccc03e3d 100644 --- a/benchmark/Prim_BM.cpp +++ b/benchmark/Prim_BM.cpp @@ -7,7 +7,7 @@ static void Prim_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/benchmark/TopologicalSort_BM.cpp b/benchmark/TopologicalSort_BM.cpp index dcd0ff6f..79c778a7 100644 --- a/benchmark/TopologicalSort_BM.cpp +++ b/benchmark/TopologicalSort_BM.cpp @@ -7,7 +7,7 @@ static void TopologicalSort_X(benchmark::State &state) { CXXGraph::Graph g; auto range_start = edges.begin(); auto range_end = edges.find(state.range(0)); - std::unordered_map *> edgesX; + CXXGraph::Map *> edgesX; edgesX.insert(range_start, range_end); for (auto e : edgesX) { g.addEdge(&(*e.second)); diff --git a/include/CXXGraph/CXXGraph.hpp b/include/CXXGraph/CXXGraph.hpp index e64fd9f8..36633b6b 100755 --- a/include/CXXGraph/CXXGraph.hpp +++ b/include/CXXGraph/CXXGraph.hpp @@ -1,5 +1,7 @@ -#ifndef __CXXGRAPH_H__ -#define __CXXGRAPH_H__ +#ifndef CXXGRAPH_H_ +#define CXXGRAPH_H_ + +#pragma once #include "CXXGraph/CXXGraphConfig.h" #include "CXXGraph/Edge/DirectedEdge.h" @@ -25,4 +27,4 @@ #include "CXXGraph/Partitioning/PartitioningStats.hpp" #include "CXXGraph/Partitioning/Record.hpp" -#endif // __CXXGRAPH_H__ +#endif // CXXGRAPH_H_ diff --git a/include/CXXGraph/CXXGraphConfig.h b/include/CXXGraph/CXXGraphConfig.h deleted file mode 100644 index 44cfc71d..00000000 --- a/include/CXXGraph/CXXGraphConfig.h +++ /dev/null @@ -1,4 +0,0 @@ -// the configured options and settings for CXXGraph -#define CXXGraph_VERSION_MAJOR 4 -#define CXXGraph_VERSION_MINOR 1 -#define CXXGraph_VERSION_PATCH 0 diff --git a/include/CXXGraph/Graph/Algorithm/BellmanFord_impl.hpp b/include/CXXGraph/Graph/Algorithm/BellmanFord_impl.hpp index e9d72508..a32b138f 100644 --- a/include/CXXGraph/Graph/Algorithm/BellmanFord_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/BellmanFord_impl.hpp @@ -52,7 +52,7 @@ const BellmanFordResult Graph::bellmanford(const Node &source, return result; } // setting all the distances initially to INF_DOUBLE - std::unordered_map>, double, nodeHash> dist, + CXXGraph::Map>, double, nodeHash> dist, currentDist; // n denotes the number of vertices in graph auto n = nodeSet.size(); diff --git a/include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp b/include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp index 8f9fc872..13b4474b 100644 --- a/include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp @@ -117,7 +117,7 @@ const std::vector> Graph::concurrency_breadth_first_search( return bfs_result; } - std::unordered_map>, size_t, nodeHash> node_to_index; + CXXGraph::Map>, size_t, nodeHash> node_to_index; for (const auto &node : nodeSet) { node_to_index[node] = node_to_index.size(); } diff --git a/include/CXXGraph/Graph/Algorithm/Boruvka_impl.hpp b/include/CXXGraph/Graph/Algorithm/Boruvka_impl.hpp index b093da1e..29243d07 100644 --- a/include/CXXGraph/Graph/Algorithm/Boruvka_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Boruvka_impl.hpp @@ -42,7 +42,7 @@ const MstResult Graph::boruvka() const { const auto n = nodeSet.size(); // Use std map for storing n subsets. - auto subsets = make_shared>(); + auto subsets = make_shared>(); // Initially there are n different trees. // Finally there will be one tree that will be MST @@ -51,7 +51,7 @@ const MstResult Graph::boruvka() const { // check if all edges are weighted and store the weights // in a map whose keys are the edge ids and values are the edge weights const auto edgeSet = Graph::getEdgeSet(); - std::unordered_map edgeWeight; + CXXGraph::Map edgeWeight; for (const auto &edge : edgeSet) { if (edge->isWeighted().has_value() && edge->isWeighted().value()) edgeWeight[edge->getId()] = @@ -73,7 +73,7 @@ const MstResult Graph::boruvka() const { while (numTrees > 1) { // Everytime initialize cheapest map // It stores index of the cheapest edge of subset. - std::unordered_map cheapest; + CXXGraph::Map cheapest; for (const auto &node : nodeSet) cheapest[node->getId()] = INT_MAX; // Traverse through all edges and update @@ -137,7 +137,7 @@ const MstResult Graph::boruvka_deterministic() const { const auto n = nodeSet.size(); // Use std map for storing n subsets. - auto subsets = make_shared>(); + auto subsets = make_shared>(); // Initially there are n different trees. // Finally there will be one tree that will be MST @@ -146,7 +146,7 @@ const MstResult Graph::boruvka_deterministic() const { // check if all edges are weighted and store the weights // in a map whose keys are the edge ids and values are the edge weights const auto edgeSet = Graph::getEdgeSet(); - std::unordered_map edgeWeight; + CXXGraph::Map edgeWeight; for (const auto &edge : edgeSet) { if (edge->isWeighted().has_value() && edge->isWeighted().value()) edgeWeight[edge->getId()] = @@ -168,7 +168,7 @@ const MstResult Graph::boruvka_deterministic() const { while (numTrees > 1) { // Everytime initialize cheapest map // It stores index of the cheapest edge of subset. - std::unordered_map cheapest; + CXXGraph::Map cheapest; for (const auto &node : nodeSet) cheapest[node->getId()] = INT_MAX; // Traverse through all edges and update diff --git a/include/CXXGraph/Graph/Algorithm/Connectivity_impl.hpp b/include/CXXGraph/Graph/Algorithm/Connectivity_impl.hpp index 44714925..9ab10918 100644 --- a/include/CXXGraph/Graph/Algorithm/Connectivity_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Connectivity_impl.hpp @@ -33,7 +33,7 @@ bool Graph::isConnectedGraph() const { } else { auto nodeSet = getNodeSet(); // created visited map - std::unordered_map visited; + CXXGraph::Map visited; for (const auto &node : nodeSet) { visited[node->getId()] = false; } @@ -73,7 +73,7 @@ bool Graph::isStronglyConnectedGraph() const { auto nodeSet = getNodeSet(); for (const auto &start_node : nodeSet) { // created visited map - std::unordered_map visited; + CXXGraph::Map visited; for (const auto &node : nodeSet) { visited[node->getId()] = false; } diff --git a/include/CXXGraph/Graph/Algorithm/CycleDetection_impl.hpp b/include/CXXGraph/Graph/Algorithm/CycleDetection_impl.hpp index 779fa8e2..c96dec1f 100644 --- a/include/CXXGraph/Graph/Algorithm/CycleDetection_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/CycleDetection_impl.hpp @@ -42,7 +42,7 @@ bool Graph::isCyclicDirectedGraphDFS() const { * * Initially, all nodes are in "not_visited" state. */ - std::unordered_map state; + CXXGraph::Map state; for (const auto &node : nodeSet) { state[node->getId()] = not_visited; } @@ -55,13 +55,13 @@ bool Graph::isCyclicDirectedGraphDFS() const { if (state[node->getId()] == not_visited) { // Check for cycle. std::function>, - std::unordered_map &, + CXXGraph::Map &, shared>)> isCyclicDFSHelper; isCyclicDFSHelper = [&isCyclicDFSHelper]( const std::shared_ptr> adjMatrix, - std::unordered_map &states, + CXXGraph::Map &states, shared> node) { // Add node "in_stack" state. states[node->getId()] = in_stack; @@ -108,7 +108,7 @@ bool Graph::isCyclicDirectedGraphDFS() const { template bool Graph::containsCycle(const T_EdgeSet *edgeSet) const { auto edgeSet_ptr = make_shared>(*edgeSet); - auto subset = make_shared>(); + auto subset = make_shared>(); // initialize the subset parent and rank values for (const auto &edge : *edgeSet_ptr) { auto &[first, second] = edge->getNodePair(); @@ -134,7 +134,7 @@ bool Graph::containsCycle(const T_EdgeSet *edgeSet) const { template bool Graph::containsCycle(shared> edgeSet) const { - auto subset = make_shared>(); + auto subset = make_shared>(); // initialize the subset parent and rank values for (const auto &edge : *edgeSet) { auto &[first, second] = edge->getNodePair(); @@ -161,7 +161,7 @@ bool Graph::containsCycle(shared> edgeSet) const { template bool Graph::containsCycle( shared> edgeSet, - shared> subset) const { + shared> subset) const { for (const auto &edge : *edgeSet) { auto &[first, second] = edge->getNodePair(); auto set1 = Graph::setFind(subset, first->getId()); @@ -179,7 +179,7 @@ bool Graph::isCyclicDirectedGraphBFS() const { } auto nodeSet = Graph::getNodeSet(); - std::unordered_map indegree; + CXXGraph::Map indegree; for (const auto &node : nodeSet) { indegree[node->getId()] = 0; } diff --git a/include/CXXGraph/Graph/Algorithm/Dial_impl.hpp b/include/CXXGraph/Graph/Algorithm/Dial_impl.hpp index d27a51d3..2c3828d9 100644 --- a/include/CXXGraph/Graph/Algorithm/Dial_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Dial_impl.hpp @@ -49,7 +49,7 @@ const DialResult Graph::dial(const Node &source, int maxWeight) const { dist[i].first = distance of ith vertex from src vertex dits[i].second = vertex i in bucket number */ auto V = nodeSet.size(); - std::unordered_map>, + CXXGraph::Map>, std::pair>>, nodeHash> dist; diff --git a/include/CXXGraph/Graph/Algorithm/Dijkstra_impl.hpp b/include/CXXGraph/Graph/Algorithm/Dijkstra_impl.hpp index 60bff765..65fb80b7 100644 --- a/include/CXXGraph/Graph/Algorithm/Dijkstra_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Dijkstra_impl.hpp @@ -55,7 +55,7 @@ const DijkstraResult Graph::dijkstra(const Node& source, // auto n = cachedAdjMatrix->size(); // setting all the distances initially to INF_DOUBLE - std::unordered_map>, double, nodeHash> dist; + CXXGraph::Map>, double, nodeHash> dist; for (const auto& node : nodeSet) { dist[node] = INF_DOUBLE; @@ -75,7 +75,7 @@ const DijkstraResult Graph::dijkstra(const Node& source, // marking the distance of source as 0 dist[*source_node_it] = 0; - std::unordered_map parent; + CXXGraph::Map parent; parent[source.getUserId()] = ""; while (!pq.empty()) { @@ -180,7 +180,7 @@ const DijkstraResult Graph::dijkstra_deterministic( // auto n = cachedAdjMatrix->size(); // setting all the distances initially to INF_DOUBLE - std::unordered_map>, double, nodeHash> dist; + CXXGraph::Map>, double, nodeHash> dist; std::map>> userIds; for (const auto& node : nodeSet) { @@ -188,7 +188,7 @@ const DijkstraResult Graph::dijkstra_deterministic( userIds[node->getUserId()] = node; } - std::unordered_map>, size_t, nodeHash> stableIds; + CXXGraph::Map>, size_t, nodeHash> stableIds; size_t index(0); for (const auto& it : userIds) stableIds[it.second] = index++; @@ -218,7 +218,7 @@ const DijkstraResult Graph::dijkstra_deterministic( // marking the distance of source as 0 dist[*source_node_it] = 0; - std::unordered_map parent; + CXXGraph::Map parent; parent[source.getUserId()] = ""; while (!pq.empty()) { @@ -328,7 +328,7 @@ const DijkstraResult Graph::dijkstra_deterministic2( // auto n = cachedAdjMatrix->size(); // setting all the distances initially to INF_DOUBLE - std::unordered_map>, double, nodeHash> dist; + CXXGraph::Map>, double, nodeHash> dist; std::map>> userIds; for (const auto& node : nodeSet) { @@ -336,7 +336,7 @@ const DijkstraResult Graph::dijkstra_deterministic2( userIds[node->getUserId()] = node; } - std::unordered_map>, uint64_t, nodeHash> stableIds; + CXXGraph::Map>, uint64_t, nodeHash> stableIds; size_t index(0); for (const auto& it : userIds) stableIds[it.second] = index++; @@ -374,7 +374,7 @@ const DijkstraResult Graph::dijkstra_deterministic2( // marking the distance of source as 0 dist[*source_node_it] = 0; - std::unordered_map parent; + CXXGraph::Map parent; parent[source.getUserId()] = ""; while (!pq.empty()) { @@ -484,7 +484,7 @@ const DijkstraResult Graph::criticalpath_deterministic( // auto n = cachedAdjMatrix->size(); // setting all the distances initially to -INF_DOUBLE - std::unordered_map>, double, nodeHash> dist; + CXXGraph::Map>, double, nodeHash> dist; std::map>> userIds; for (const auto& node : nodeSet) { @@ -492,7 +492,7 @@ const DijkstraResult Graph::criticalpath_deterministic( userIds[node->getUserId()] = node; } - std::unordered_map>, size_t, nodeHash> stableIds; + CXXGraph::Map>, size_t, nodeHash> stableIds; size_t index(0); for (const auto& it : userIds) stableIds[it.second] = index++; @@ -522,7 +522,7 @@ const DijkstraResult Graph::criticalpath_deterministic( // marking the distance of source as 0 dist[*source_node_it] = 0; - std::unordered_map parent; + CXXGraph::Map parent; parent[source.getUserId()] = ""; while (!pq.empty()) { diff --git a/include/CXXGraph/Graph/Algorithm/FloydWarshall_impl.hpp b/include/CXXGraph/Graph/Algorithm/FloydWarshall_impl.hpp index 79305a5d..2b431361 100644 --- a/include/CXXGraph/Graph/Algorithm/FloydWarshall_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/FloydWarshall_impl.hpp @@ -30,7 +30,7 @@ const FWResult Graph::floydWarshall() const { FWResult result; result.success = false; result.errorMessage = ""; - std::unordered_map, double, + CXXGraph::Map, double, CXXGraph::pair_hash> pairwise_dist; const auto &nodeSet = Graph::getNodeSet(); diff --git a/include/CXXGraph/Graph/Algorithm/FordFulkerson_impl.hpp b/include/CXXGraph/Graph/Algorithm/FordFulkerson_impl.hpp index c0ad641f..c22b8990 100644 --- a/include/CXXGraph/Graph/Algorithm/FordFulkerson_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/FordFulkerson_impl.hpp @@ -35,11 +35,11 @@ double Graph::fordFulkersonMaxFlow(const Node &source, return -1; } double maxFlow = 0; - std::unordered_map>, shared>, nodeHash> + CXXGraph::Map>, shared>, nodeHash> parent; - std::unordered_map< + CXXGraph::Map< shared>, - std::unordered_map>, double, nodeHash>, + CXXGraph::Map>, double, nodeHash>, nodeHash> weightMap; // build weight map @@ -69,7 +69,7 @@ double Graph::fordFulkersonMaxFlow(const Node &source, auto bfs_helper = [&source_node_ptr, &target_node_ptr, &parent, &weightMap]() -> bool { - std::unordered_map>, bool, nodeHash> visited; + CXXGraph::Map>, bool, nodeHash> visited; std::queue>> queue; queue.push(source_node_ptr); visited[source_node_ptr] = true; diff --git a/include/CXXGraph/Graph/Algorithm/Kahn_impl.hpp b/include/CXXGraph/Graph/Algorithm/Kahn_impl.hpp index 0778c79e..7d46029b 100644 --- a/include/CXXGraph/Graph/Algorithm/Kahn_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Kahn_impl.hpp @@ -37,7 +37,7 @@ TopoSortResult Graph::kahn() const { const auto nodeSet = Graph::getNodeSet(); result.nodesInTopoOrder.reserve(cachedAdjMatrix->size()); - std::unordered_map indegree; + CXXGraph::Map indegree; for (const auto &node : nodeSet) { indegree[node->getId()] = 0; } diff --git a/include/CXXGraph/Graph/Algorithm/Kosaraju_impl.hpp b/include/CXXGraph/Graph/Algorithm/Kosaraju_impl.hpp index 74eb003b..95d29b2e 100644 --- a/include/CXXGraph/Graph/Algorithm/Kosaraju_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Kosaraju_impl.hpp @@ -39,7 +39,7 @@ SCCResult Graph::kosaraju() const { } else { auto nodeSet = getNodeSet(); // created visited map - std::unordered_map visited; + CXXGraph::Map visited; for (const auto &node : nodeSet) { visited[node->getId()] = false; } diff --git a/include/CXXGraph/Graph/Algorithm/Kruskal_impl.hpp b/include/CXXGraph/Graph/Algorithm/Kruskal_impl.hpp index 71027221..00b6f8df 100644 --- a/include/CXXGraph/Graph/Algorithm/Kruskal_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Kruskal_impl.hpp @@ -58,7 +58,7 @@ const MstResult Graph::kruskal() const { } } - auto subset = make_shared>(); + auto subset = make_shared>(); for (const auto &node : nodeSet) { Subset set{node->getId(), 0}; diff --git a/include/CXXGraph/Graph/Algorithm/Prim_impl.hpp b/include/CXXGraph/Graph/Algorithm/Prim_impl.hpp index a3cd7d1f..78ad12d1 100644 --- a/include/CXXGraph/Graph/Algorithm/Prim_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Prim_impl.hpp @@ -45,7 +45,7 @@ const MstResult Graph::prim() const { /* auto n = nodeSet.size(); */ // setting all the distances initially to INF_DOUBLE - std::unordered_map>, double, nodeHash> dist; + CXXGraph::Map>, double, nodeHash> dist; for (const auto &elem : (*cachedAdjMatrix)) { dist[elem.first] = INF_DOUBLE; } @@ -68,7 +68,7 @@ const MstResult Graph::prim() const { doneNode.push_back(source->getId()); // stores the parent and corresponding child node // of the edges that are part of MST - std::unordered_map parentNode; + CXXGraph::Map parentNode; while (!pq.empty()) { // second element of pair denotes the node / vertex shared> currentNode = pq.top().second; diff --git a/include/CXXGraph/Graph/Algorithm/Tarjan_impl.hpp b/include/CXXGraph/Graph/Algorithm/Tarjan_impl.hpp index d692b0ab..c9e1576a 100644 --- a/include/CXXGraph/Graph/Algorithm/Tarjan_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Tarjan_impl.hpp @@ -49,9 +49,9 @@ const TarjanResult Graph::tarjan(const unsigned int typeMask) const { } const auto &nodeSet = getNodeSet(); - std::unordered_map + CXXGraph::Map discoveryTime; // the timestamp when a node is visited - std::unordered_map + CXXGraph::Map lowestDisc; // the lowest discovery time of all // reachable nodes from current node int timestamp = 0; @@ -59,7 +59,7 @@ const TarjanResult Graph::tarjan(const unsigned int typeMask) const { std::stack> sccNodeStack; std::stack> ebccNodeStack; std::stack> vbccNodeStack; - std::unordered_set inStack; + CXXGraph::Set inStack; std::function>, const shared>)> dfs_helper = [this, typeMask, isDirected, &dfs_helper, &discoveryTime, &lowestDisc, ×tamp, &rootId, &sccNodeStack, diff --git a/include/CXXGraph/Graph/Algorithm/TopologicalSort_impl.hpp b/include/CXXGraph/Graph/Algorithm/TopologicalSort_impl.hpp index 95ccaece..deb73459 100644 --- a/include/CXXGraph/Graph/Algorithm/TopologicalSort_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/TopologicalSort_impl.hpp @@ -39,7 +39,7 @@ TopoSortResult Graph::topologicalSort() const { return result; } else { const auto &nodeSet = getNodeSet(); - std::unordered_map>, bool, nodeHash> visited; + CXXGraph::Map>, bool, nodeHash> visited; std::function>)> postorder_helper = [this, &postorder_helper, &visited, diff --git a/include/CXXGraph/Graph/Algorithm/TransitiveReduction_impl.hpp b/include/CXXGraph/Graph/Algorithm/TransitiveReduction_impl.hpp index 417381db..56c125e2 100644 --- a/include/CXXGraph/Graph/Algorithm/TransitiveReduction_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/TransitiveReduction_impl.hpp @@ -39,7 +39,7 @@ const Graph Graph::transitiveReduction() const { Graph result(this->edgeSet); CXXGraph::id_t edgeId = 0; - std::unordered_set>, nodeHash> nodes = + CXXGraph::Set>, nodeHash> nodes = this->getNodeSet(); for (auto x : nodes) { for (auto y : nodes) { diff --git a/include/CXXGraph/Graph/Graph_decl.h b/include/CXXGraph/Graph/Graph_decl.h index e6d7983c..f6c265d1 100644 --- a/include/CXXGraph/Graph/Graph_decl.h +++ b/include/CXXGraph/Graph/Graph_decl.h @@ -104,11 +104,11 @@ class Graph { const std::string &graphName) const; int readFromDot(const std::string &workingDir, const std::string &fileName); void recreateGraph( - std::unordered_map> + CXXGraph::Map> &edgeMap, - std::unordered_map &edgeDirectedMap, - std::unordered_map &nodeFeatMap, - std::unordered_map &edgeWeightMap); + CXXGraph::Map &edgeDirectedMap, + CXXGraph::Map &nodeFeatMap, + CXXGraph::Map &edgeWeightMap); #ifdef WITH_COMPRESSION int compressFile(const std::string &inputFile, @@ -508,7 +508,7 @@ class Graph { * @return parent node of elem * Note: No Thread Safe */ - virtual CXXGraph::id_t setFind(std::unordered_map *, + virtual CXXGraph::id_t setFind(CXXGraph::Map *, const CXXGraph::id_t elem) const; /** @@ -523,7 +523,7 @@ class Graph { * Note: No Thread Safe */ virtual CXXGraph::id_t setFind( - shared>, + shared>, const CXXGraph::id_t elem) const; /** @@ -535,7 +535,7 @@ class Graph { * NOTE: Original subset is no longer available after union. * Note: No Thread Safe */ - virtual void setUnion(std::unordered_map *, + virtual void setUnion(CXXGraph::Map *, const CXXGraph::id_t set1, const CXXGraph::id_t elem2) const; @@ -548,7 +548,7 @@ class Graph { * NOTE: Original subset is no longer available after union. * Note: No Thread Safe */ - virtual void setUnion(shared>, + virtual void setUnion(shared>, const CXXGraph::id_t set1, const CXXGraph::id_t elem2) const; @@ -828,7 +828,7 @@ class Graph { */ virtual bool containsCycle( shared> edgeSet, - shared>) const; + shared>) const; /** * \brief diff --git a/include/CXXGraph/Graph/Graph_impl.hpp b/include/CXXGraph/Graph/Graph_impl.hpp index 950cd8da..8454d0e3 100644 --- a/include/CXXGraph/Graph/Graph_impl.hpp +++ b/include/CXXGraph/Graph/Graph_impl.hpp @@ -375,8 +375,8 @@ const std::optional>> Graph::getNode( } template -std::unordered_set>, nodeHash> Graph::nodeSet() { - std::unordered_set>, nodeHash> nodeSet; +CXXGraph::Set >, nodeHash> Graph::nodeSet() { + CXXGraph::Set>, nodeHash> nodeSet; for (auto &edgeSetIt : edgeSet) { nodeSet.insert( std::const_pointer_cast>(edgeSetIt->getNodePair().first)); @@ -392,10 +392,10 @@ std::unordered_set>, nodeHash> Graph::nodeSet() { template CXXGraph::id_t Graph::setFind( - std::unordered_map *subsets, + CXXGraph::Map *subsets, const CXXGraph::id_t nodeId) const { auto subsets_ptr = - make_shared>(*subsets); + make_shared>(*subsets); // find root and make root as parent of i // (path compression) if ((*subsets)[nodeId].parent != nodeId) { @@ -408,7 +408,7 @@ CXXGraph::id_t Graph::setFind( template CXXGraph::id_t Graph::setFind( - shared> subsets, + shared> subsets, const CXXGraph::id_t nodeId) const { // find root and make root as parent of i // (path compression) @@ -421,10 +421,10 @@ CXXGraph::id_t Graph::setFind( } template -void Graph::setUnion(std::unordered_map *subsets, +void Graph::setUnion(CXXGraph::Map *subsets, const CXXGraph::id_t elem1, const CXXGraph::id_t elem2) const { - /* auto subsets_ptr = make_shared>(*subsets); */ // if both sets have same parent // then there's nothing to be done @@ -456,7 +456,7 @@ void Graph::setUnion(std::unordered_map *subsets, template void Graph::setUnion( - shared> subsets, + shared> subsets, const CXXGraph::id_t elem1, const CXXGraph::id_t elem2) const { // if both sets have same parent // then there's nothing to be done @@ -646,7 +646,7 @@ void Graph::cacheTransitionMatrix() { } template -const std::unordered_set>, nodeHash> +const CXXGraph::Set>, nodeHash> Graph::outNeighbors(const Node *node) const { auto node_shared = make_shared>(*node); @@ -654,14 +654,14 @@ Graph::outNeighbors(const Node *node) const { } template -const std::unordered_set>, nodeHash> +const CXXGraph::Set>, nodeHash> Graph::outNeighbors(shared> node) const { if (cachedAdjMatrix->find(node) == cachedAdjMatrix->end()) { - return std::unordered_set>, nodeHash>(); + return CXXGraph::Set>, nodeHash>(); } auto nodeEdgePairs = cachedAdjMatrix->at(node); - std::unordered_set>, nodeHash> outNeighbors; + CXXGraph::Set>, nodeHash> outNeighbors; for (auto pair : nodeEdgePairs) { if (pair.second->isDirected().has_value() && pair.second->isDirected().value()) { @@ -673,7 +673,7 @@ Graph::outNeighbors(shared> node) const { } template -const std::unordered_set>, nodeHash> +const CXXGraph::Set>, nodeHash> Graph::inOutNeighbors(const Node *node) const { auto node_shared = make_shared>(*node); @@ -681,14 +681,14 @@ Graph::inOutNeighbors(const Node *node) const { } template -const std::unordered_set>, nodeHash> +const CXXGraph::Set>, nodeHash> Graph::inOutNeighbors(shared> node) const { if (cachedAdjMatrix->find(node) == cachedAdjMatrix->end()) { - return std::unordered_set>, nodeHash>(); + return CXXGraph::Set>, nodeHash>(); } auto nodeEdgePairs = cachedAdjMatrix->at(node); - std::unordered_set>, nodeHash> inOutNeighbors; + CXXGraph::Set>, nodeHash> inOutNeighbors; for (auto pair : nodeEdgePairs) { inOutNeighbors.insert(pair.first); } @@ -697,7 +697,7 @@ Graph::inOutNeighbors(shared> node) const { } template -const std::unordered_set>, edgeHash> Graph::outEdges( +const CXXGraph::Set>, edgeHash> Graph::outEdges( const Node *node) const { auto node_shared = make_shared>(*node); @@ -705,14 +705,14 @@ const std::unordered_set>, edgeHash> Graph::outEdges( } template -const std::unordered_set>, edgeHash> Graph::outEdges( +const CXXGraph::Set>, edgeHash> Graph::outEdges( shared> node) const { if (cachedAdjMatrix->find(node) == cachedAdjMatrix->end()) { - return std::unordered_set>, edgeHash>(); + return CXXGraph::Set>, edgeHash>(); } auto nodeEdgePairs = cachedAdjMatrix->at(node); - std::unordered_set>, edgeHash> outEdges; + CXXGraph::Set>, edgeHash> outEdges; for (auto pair : nodeEdgePairs) { if (pair.second->isDirected().has_value() && pair.second->isDirected().value()) { @@ -724,7 +724,7 @@ const std::unordered_set>, edgeHash> Graph::outEdges( } template -const std::unordered_set>, edgeHash> +const CXXGraph::Set>, edgeHash> Graph::inOutEdges(const Node *node) const { auto node_shared = make_shared>(*node); @@ -732,14 +732,14 @@ Graph::inOutEdges(const Node *node) const { } template -const std::unordered_set>, edgeHash> +const CXXGraph::Set>, edgeHash> Graph::inOutEdges(shared> node) const { if (cachedAdjMatrix->find(node) == cachedAdjMatrix->end()) { - return std::unordered_set>, edgeHash>(); + return CXXGraph::Set>, edgeHash>(); } auto nodeEdgePairs = cachedAdjMatrix->at(node); - std::unordered_set>, edgeHash> outEdges; + CXXGraph::Set>, edgeHash> outEdges; for (auto pair : nodeEdgePairs) { outEdges.insert(pair.second); } diff --git a/include/CXXGraph/Graph/IO/InputOperation_impl.hpp b/include/CXXGraph/Graph/IO/InputOperation_impl.hpp index 3d8ee790..53e7e114 100644 --- a/include/CXXGraph/Graph/IO/InputOperation_impl.hpp +++ b/include/CXXGraph/Graph/IO/InputOperation_impl.hpp @@ -165,11 +165,11 @@ template int Graph::readFromMTXFile(const std::string &workingDir, const std::string &fileName) { // Define the edge maps - std::unordered_map> + CXXGraph::Map> edgeMap; - std::unordered_map nodeFeatMap; - std::unordered_map edgeDirectedMap; - std::unordered_map edgeWeightMap; + CXXGraph::Map nodeFeatMap; + CXXGraph::Map edgeDirectedMap; + CXXGraph::Map edgeWeightMap; // Get full path to the file and open it const std::string completePathToFileGraph = @@ -253,11 +253,11 @@ template int Graph::readFromDot(const std::string &workingDir, const std::string &fileName) { // Define the edge maps - std::unordered_map> + CXXGraph::Map> edgeMap; - std::unordered_map nodeFeatMap; - std::unordered_map edgeDirectedMap; - std::unordered_map edgeWeightMap; + CXXGraph::Map nodeFeatMap; + CXXGraph::Map edgeDirectedMap; + CXXGraph::Map edgeWeightMap; // Define the node strings and the "garbage collector" temp string std::string node1; @@ -337,11 +337,11 @@ void Graph::readGraphFromStream(std::istream &iGraph, std::istream &iNodeFeat, std::istream &iEdgeWeight, bool readNodeFeat, bool readEdgeWeight) { - std::unordered_map> + CXXGraph::Map> edgeMap; - std::unordered_map edgeDirectedMap; - std::unordered_map nodeFeatMap; - std::unordered_map edgeWeightMap; + CXXGraph::Map edgeDirectedMap; + CXXGraph::Map nodeFeatMap; + CXXGraph::Map edgeWeightMap; CXXGraph::id_t edgeId; std::string nodeId1; @@ -377,12 +377,12 @@ void Graph::readGraphFromStream(std::istream &iGraph, template void Graph::recreateGraph( - std::unordered_map> + CXXGraph::Map> &edgeMap, - std::unordered_map &edgeDirectedMap, - std::unordered_map &nodeFeatMap, - std::unordered_map &edgeWeightMap) { - std::unordered_map>> nodeMap; + CXXGraph::Map &edgeDirectedMap, + CXXGraph::Map &nodeFeatMap, + CXXGraph::Map &edgeWeightMap) { + CXXGraph::Map>> nodeMap; for (const auto &edgeIt : edgeMap) { shared> node1(nullptr); shared> node2(nullptr); diff --git a/include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp b/include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp index 1cb2ab62..84273c82 100644 --- a/include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp +++ b/include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp @@ -47,7 +47,7 @@ namespace Partitioning { template class CoordinatedPartitionState : public PartitionState { private: - std::map>> record_map; + CXXGraph::OrderedMap>> record_map; std::vector machines_load_edges; std::vector machines_weight_edges; std::vector machines_load_vertices; @@ -72,11 +72,11 @@ class CoordinatedPartitionState : public PartitionState { int getMinLoad() const override; int getMaxLoad() const override; int getMachineWithMinWeight() const override; - int getMachineWithMinWeight(const std::set &partitions) const override; + int getMachineWithMinWeight(const CXXGraph::OrderedSet &partitions) const override; std::vector getMachines_load() const override; size_t getTotalReplicas() const override; size_t getNumVertices() const override; - std::set getVertexIds() const override; + CXXGraph::OrderedSet getVertexIds() const override; void incrementMachineLoadVertices(const int m); std::vector getMachines_loadVertices() const; @@ -194,7 +194,7 @@ int CoordinatedPartitionState::getMachineWithMinWeight() const { } template int CoordinatedPartitionState::getMachineWithMinWeight( - const std::set &partitions) const { + const CXXGraph::OrderedSet &partitions) const { std::lock_guard lock(*machines_weight_edges_mutex); double MIN_LOAD = std::numeric_limits::max(); @@ -239,10 +239,10 @@ size_t CoordinatedPartitionState::getNumVertices() const { return (size_t)record_map.size(); } template -std::set CoordinatedPartitionState::getVertexIds() const { +CXXGraph::OrderedSet CoordinatedPartitionState::getVertexIds() const { std::lock_guard lock(*record_map_mutex); // if (GLOBALS.OUTPUT_FILE_NAME!=null){ out.close(); } - std::set result; + CXXGraph::OrderedSet result; for (const auto &record_map_it : record_map) { result.insert((CXXGraph::id_t)record_map_it.first); } diff --git a/include/CXXGraph/Partitioning/CoordinatedRecord.hpp b/include/CXXGraph/Partitioning/CoordinatedRecord.hpp index 2bf547a8..27139bc0 100644 --- a/include/CXXGraph/Partitioning/CoordinatedRecord.hpp +++ b/include/CXXGraph/Partitioning/CoordinatedRecord.hpp @@ -33,7 +33,7 @@ namespace Partitioning { template class CoordinatedRecord : public Record { private: - std::set partitions = {}; + CXXGraph::OrderedSet partitions = {}; std::mutex *lock = nullptr; int degree = 0; @@ -41,7 +41,7 @@ class CoordinatedRecord : public Record { CoordinatedRecord(); ~CoordinatedRecord(); - const std::set &getPartitions() const override; + const CXXGraph::OrderedSet &getPartitions() const override; void addPartition(const int m) override; bool hasReplicaInPartition(const int m) const override; bool getLock() override; @@ -50,36 +50,36 @@ class CoordinatedRecord : public Record { int getDegree() const override; void incrementDegree() override; - void addAll(const std::set &set); - std::set partition_intersection( + void addAll(const CXXGraph::OrderedSet &set); + CXXGraph::OrderedSet partition_intersection( const std::shared_ptr other) const; - std::set partition_union( + CXXGraph::OrderedSet partition_union( const std::shared_ptr other) const; - std::set partition_difference( + CXXGraph::OrderedSet partition_difference( const std::shared_ptr other) const; }; template -std::set CoordinatedRecord::partition_intersection( +CXXGraph::OrderedSet CoordinatedRecord::partition_intersection( std::shared_ptr other) const { - std::set result; + CXXGraph::OrderedSet result; set_intersection(this->partitions.begin(), this->partitions.end(), other->partitions.begin(), other->partitions.end(), std::inserter(result, result.begin())); return result; } template -std::set CoordinatedRecord::partition_union( +CXXGraph::OrderedSet CoordinatedRecord::partition_union( std::shared_ptr other) const { - std::set result; + CXXGraph::OrderedSet result; set_union(this->partitions.begin(), this->partitions.end(), other->partitions.begin(), other->partitions.end(), std::inserter(result, result.begin())); return result; } template -std::set CoordinatedRecord::partition_difference( +CXXGraph::OrderedSet CoordinatedRecord::partition_difference( std::shared_ptr other) const { - std::set result; + CXXGraph::OrderedSet result; set_difference(this->partitions.begin(), this->partitions.end(), other->partitions.begin(), other->partitions.end(), std::inserter(result, result.begin())); @@ -99,7 +99,7 @@ CoordinatedRecord::~CoordinatedRecord() { } } template -const std::set &CoordinatedRecord::getPartitions() const { +const CXXGraph::OrderedSet &CoordinatedRecord::getPartitions() const { return partitions; } template @@ -136,7 +136,7 @@ void CoordinatedRecord::incrementDegree() { degree++; } template -void CoordinatedRecord::addAll(const std::set &set) { +void CoordinatedRecord::addAll(const CXXGraph::OrderedSet &set) { partitions.insert(set.begin(), set.end()); } } // namespace Partitioning diff --git a/include/CXXGraph/Partitioning/EBV.hpp b/include/CXXGraph/Partitioning/EBV.hpp index eb6d1b01..b257a50d 100644 --- a/include/CXXGraph/Partitioning/EBV.hpp +++ b/include/CXXGraph/Partitioning/EBV.hpp @@ -111,7 +111,7 @@ void EBV::performStep(shared> e, int machine_id = -1; //*** COMPUTE SCORES, FIND MIN SCORE, AND COMPUTE CANDIDATES PARTITIONS - std::map eva; + CXXGraph::OrderedMap eva; auto u_partition = u_record->getPartitions(); auto v_partition = v_record->getPartitions(); auto optimalEdgesNumber = (double)edgeCardinality / (double)P; diff --git a/include/CXXGraph/Partitioning/GreedyVertexCut.hpp b/include/CXXGraph/Partitioning/GreedyVertexCut.hpp index c76dc73a..ba54824e 100644 --- a/include/CXXGraph/Partitioning/GreedyVertexCut.hpp +++ b/include/CXXGraph/Partitioning/GreedyVertexCut.hpp @@ -145,7 +145,7 @@ void GreedyVertexCut::performStep(shared> e, } else if (!u_record->getPartitions().empty() && !v_record->getPartitions().empty()) { // check if have intersection - std::set intersection; + CXXGraph::OrderedSet intersection; std::set_intersection( u_record->getPartitions().begin(), u_record->getPartitions().end(), v_record->getPartitions().begin(), v_record->getPartitions().end(), @@ -163,7 +163,7 @@ void GreedyVertexCut::performStep(shared> e, candidates.push_back(machine_id); } else { // Find the partition with min load in the union of u and v - std::set part_union; + CXXGraph::OrderedSet part_union; std::set_union( u_record->getPartitions().begin(), u_record->getPartitions().end(), v_record->getPartitions().begin(), v_record->getPartitions().end(), diff --git a/include/CXXGraph/Partitioning/Partition.hpp b/include/CXXGraph/Partitioning/Partition.hpp index 9e2d112c..37bc4a65 100644 --- a/include/CXXGraph/Partitioning/Partition.hpp +++ b/include/CXXGraph/Partitioning/Partition.hpp @@ -43,7 +43,7 @@ template class Graph; template -using T_EdgeSet = std::unordered_set>, edgeHash>; +using T_EdgeSet = CXXGraph::Set>, edgeHash>; namespace Partitioning { template std::ostream &operator<<(std::ostream &o, const Partition &partition); @@ -288,10 +288,10 @@ unsigned int getNumberOfEdges(const PartitionMap &partitionMap) { template unsigned int getNumberOfNodes(const PartitionMap &partitionMap) { - std::unordered_set>, nodeHash> nodeSet; + CXXGraph::Set>, nodeHash> nodeSet; for (const auto &it : partitionMap) { - const std::unordered_set>, nodeHash> + const CXXGraph::Set>, nodeHash> partitionNodeSet = it.second->getNodeSet(); for (const auto &it2 : partitionNodeSet) { // if (std::find_if(nodeSet.begin(), nodeSet.end(), [it2](const Node diff --git a/include/CXXGraph/Partitioning/PartitionState.hpp b/include/CXXGraph/Partitioning/PartitionState.hpp index 6138c3ef..ba05ff06 100644 --- a/include/CXXGraph/Partitioning/PartitionState.hpp +++ b/include/CXXGraph/Partitioning/PartitionState.hpp @@ -52,11 +52,11 @@ class PartitionState { virtual int getMaxLoad() const = 0; virtual int getMachineWithMinWeight() const = 0; virtual int getMachineWithMinWeight( - const std::set& partitions) const = 0; + const CXXGraph::OrderedSet& partitions) const = 0; virtual std::vector getMachines_load() const = 0; virtual size_t getTotalReplicas() const = 0; virtual size_t getNumVertices() const = 0; - virtual std::set getVertexIds() const = 0; + virtual CXXGraph::OrderedSet getVertexIds() const = 0; }; } // namespace Partitioning } // namespace CXXGraph diff --git a/include/CXXGraph/Partitioning/Partitioner.hpp b/include/CXXGraph/Partitioning/Partitioner.hpp index e94adbde..dd79cf68 100644 --- a/include/CXXGraph/Partitioning/Partitioner.hpp +++ b/include/CXXGraph/Partitioning/Partitioner.hpp @@ -110,7 +110,7 @@ Partitioner::Partitioner(shared> dataset, Globals &G) (GLOBALS.numberOfPartition == 0) ? 0.0 : lambda * weight_sum / P; // precompute degrees of vertices - std::unordered_map vertices_degrees; + CXXGraph::Map vertices_degrees; for (const auto &edge_it : *(this->dataset)) { auto nodePair = edge_it->getNodePair(); std::size_t u = nodePair.first->getId(); @@ -153,7 +153,7 @@ Partitioner::Partitioner(const Partitioner &other) { (GLOBALS.numberOfPartition == 0) ? 0.0 : lambda * weight_sum / P; // precompute degrees of vertices - std::unordered_map vertices_degrees; + CXXGraph::Map vertices_degrees; for (const auto &edge_it : *(this->dataset)) { auto nodePair = edge_it->getNodePair(); std::size_t u = nodePair.first->getId(); diff --git a/include/CXXGraph/Partitioning/Record.hpp b/include/CXXGraph/Partitioning/Record.hpp index 38711d5e..825ef3d2 100755 --- a/include/CXXGraph/Partitioning/Record.hpp +++ b/include/CXXGraph/Partitioning/Record.hpp @@ -31,7 +31,7 @@ class Record { public: virtual ~Record() = default; - virtual const std::set &getPartitions() const = 0; + virtual const CXXGraph::OrderedSet &getPartitions() const = 0; virtual void addPartition(const int m) = 0; virtual bool hasReplicaInPartition(const int m) const = 0; virtual bool getLock() = 0; diff --git a/include/CXXGraph/Partitioning/WeightBalancedLibra.hpp b/include/CXXGraph/Partitioning/WeightBalancedLibra.hpp index 284454f4..9a36c767 100644 --- a/include/CXXGraph/Partitioning/WeightBalancedLibra.hpp +++ b/include/CXXGraph/Partitioning/WeightBalancedLibra.hpp @@ -42,12 +42,12 @@ class WeightBalancedLibra : public PartitionStrategy { private: Globals GLOBALS; double weight_sum_bound; - std::unordered_map vertices_degrees; + CXXGraph::Map vertices_degrees; public: explicit WeightBalancedLibra( const Globals &G, double _weight_sum_bound, - std::unordered_map &&_vertices_degrees); + CXXGraph::Map &&_vertices_degrees); ~WeightBalancedLibra(); void performStep(shared> e, @@ -56,7 +56,7 @@ class WeightBalancedLibra : public PartitionStrategy { template WeightBalancedLibra::WeightBalancedLibra( const Globals &G, double _weight_sum_bound, - std::unordered_map &&_vertices_degrees) + CXXGraph::Map &&_vertices_degrees) : GLOBALS(G), weight_sum_bound(_weight_sum_bound), vertices_degrees(_vertices_degrees) {} @@ -99,8 +99,8 @@ void WeightBalancedLibra::performStep(shared> e, } //*** LOCK TAKEN int machine_id = -1; - const std::set &u_partition = u_record->getPartitions(); - const std::set &v_partition = v_record->getPartitions(); + const CXXGraph::OrderedSet &u_partition = u_record->getPartitions(); + const CXXGraph::OrderedSet &v_partition = v_record->getPartitions(); // Case 1: no edges of two nodes have been assigned if (u_partition.empty() && v_partition.empty()) { @@ -138,9 +138,9 @@ void WeightBalancedLibra::performStep(shared> e, // according to paper, s refers to node with lower degree, t = {u, v} - // {s} - const std::set &s_partition = + const CXXGraph::OrderedSet &s_partition = (u_degree > v_degree) ? v_partition : u_partition; - const std::set &t_partition = + const CXXGraph::OrderedSet &t_partition = (u_degree > v_degree) ? u_partition : v_partition; machine_id = state->getMachineWithMinWeight(s_partition); diff --git a/include/CXXGraph/Utility/Typedef.hpp b/include/CXXGraph/Utility/Typedef.hpp index d255184a..d2baa8a1 100644 --- a/include/CXXGraph/Utility/Typedef.hpp +++ b/include/CXXGraph/Utility/Typedef.hpp @@ -127,7 +127,7 @@ struct FWResult_struct { bool negativeCycle = false; // TRUE if graph contains a negative cycle, FALSE otherwise std::string errorMessage = ""; // message of error - std::unordered_map, double, pair_hash> + CXXGraph::Map, double, pair_hash> result = {}; }; typedef FWResult_struct FWResult; @@ -150,7 +150,7 @@ struct DialResult_struct { bool success = false; // TRUE if the function does not return error, FALSE otherwise std::string errorMessage = ""; // message of error - std::unordered_map minDistanceMap = + CXXGraph::Map minDistanceMap = {}; // result a map that contains the node id and the minumum distance // from source (valid only if success is TRUE) }; @@ -191,7 +191,7 @@ struct SCCResult_struct { false; // TRUE if the function does not return error, FALSE otherwise std::string errorMessage = ""; // message of error int noOfComponents = 0; - std::unordered_map sccMap; + CXXGraph::Map sccMap; // Components stronglyConnectedComps; }; template @@ -242,7 +242,7 @@ template struct BronKerboschResult_struct { bool success = false; std::string errorMessage = ""; - std::vector>, nodeHash>> + std::vector>, nodeHash>> maximalCliques = {}; }; template @@ -253,30 +253,30 @@ using BronKerboschResult = BronKerboschResult_struct; // /////////////////////////////////////////////////////////////// template -using AdjacencyMatrix = std::unordered_map< +using AdjacencyMatrix = CXXGraph::Map< shared>, std::vector>, shared>>>, nodeHash>; template using DegreeMatrix = - std::unordered_map>, unsigned int, nodeHash>; + CXXGraph::Map>, unsigned int, nodeHash>; template -using LaplacianMatrix = std::unordered_map< +using LaplacianMatrix = CXXGraph::Map< shared>, std::vector>, shared>>>, nodeHash>; template using TransitionMatrix = - std::unordered_map>, + CXXGraph::Map>, std::vector>, double>>, nodeHash>; template using PartitionMap = - std::unordered_map>>; /////////////////////////////////////////////////////////////////////////////////// diff --git a/test/BFSTest.cpp b/test/BFSTest.cpp index 8084a7c3..4b9b679c 100644 --- a/test/BFSTest.cpp +++ b/test/BFSTest.cpp @@ -324,7 +324,7 @@ TEST(BFSTest, test_13) { CXXGraph::Graph graph(edgeSet); auto &result1 = graph.breadth_first_search(*(nodes[0])); - std::set> st1; + CXXGraph::OrderedSet> st1; for (const auto &node : result1) { st1.emplace(node); } diff --git a/test/FWTest.cpp b/test/FWTest.cpp index 13580d59..8d5f2c5d 100644 --- a/test/FWTest.cpp +++ b/test/FWTest.cpp @@ -36,7 +36,7 @@ TEST(FWTest, test_1) { CXXGraph::Graph graph(edgeSet); CXXGraph::FWResult res = graph.floydWarshall(); - std::unordered_map, double, + CXXGraph::Map, double, CXXGraph::pair_hash> pairwise_dist; auto key = std::make_pair(node1.getUserId(), node1.getUserId()); diff --git a/test/KahnTest.cpp b/test/KahnTest.cpp index 4b231971..8bd38313 100644 --- a/test/KahnTest.cpp +++ b/test/KahnTest.cpp @@ -91,7 +91,7 @@ TEST(KahnTest, correct_example_small) { ASSERT_TRUE(res.errorMessage.empty()); ASSERT_EQ(res.nodesInTopoOrder.size(), graph.getNodeSet().size()); - std::unordered_map topOrderNodeIds; + CXXGraph::Map topOrderNodeIds; for (size_t i = 0; i < res.nodesInTopoOrder.size(); ++i) { topOrderNodeIds[res.nodesInTopoOrder[i].getId()] = i; } @@ -160,7 +160,7 @@ TEST(KahnTest, correct_example_big) { ASSERT_TRUE(res.errorMessage.empty()); ASSERT_EQ(res.nodesInTopoOrder.size(), graph.getNodeSet().size()); - std::unordered_map topOrderNodeIds; + CXXGraph::Map topOrderNodeIds; for (size_t i = 0; i < res.nodesInTopoOrder.size(); ++i) { topOrderNodeIds[res.nodesInTopoOrder[i].getId()] = i; } diff --git a/test/NodeTest.cpp b/test/NodeTest.cpp index e2e400f8..4e509152 100644 --- a/test/NodeTest.cpp +++ b/test/NodeTest.cpp @@ -41,7 +41,7 @@ TEST(StringNodeTest, StringConstructor) { char charTest = 'w'; std::string stringTest = "myStr"; std::vector vectorTest = {1, 2, 3, 4}; - std::unordered_map mapTest = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; + CXXGraph::Map mapTest = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; testStruct structTest(42, true, "abc"); CXXGraph::Node intNode("1", intTest); @@ -51,7 +51,7 @@ TEST(StringNodeTest, StringConstructor) { CXXGraph::Node charNode("5", charTest); CXXGraph::Node stringNode("6", stringTest); CXXGraph::Node> vectorNode("7", vectorTest); - CXXGraph::Node> mapNode("8", mapTest); + CXXGraph::Node> mapNode("8", mapTest); CXXGraph::Node structNode("9", structTest); ASSERT_EQ(intNode.getUserId(), "1"); diff --git a/test/RWOutputTest.cpp b/test/RWOutputTest.cpp index ee492d32..4a8cc885 100644 --- a/test/RWOutputTest.cpp +++ b/test/RWOutputTest.cpp @@ -18,9 +18,9 @@ inline bool exists_test(const std::string &name) { return (stat(name.c_str(), &buffer) == 0); } -static std::unordered_map>> +static CXXGraph::Map>> generateRandomNodes(unsigned long numberOfNodes, int MaxValue) { - std::unordered_map>> nodes; + CXXGraph::Map>> nodes; srand(static_cast(time(NULL))); int randomNumber; for (unsigned long index = 0; index < numberOfNodes; ++index) { @@ -33,11 +33,11 @@ generateRandomNodes(unsigned long numberOfNodes, int MaxValue) { return nodes; } -static std::unordered_map>> +static CXXGraph::Map>> generateRandomEdges( unsigned long numberOfEdges, - std::unordered_map>> nodes) { - std::unordered_map>> edges; + CXXGraph::Map>> nodes) { + CXXGraph::Map>> edges; srand(static_cast(time(NULL))); int randomNumber1; int randomNumber2; diff --git a/test/TopologicalSortTest.cpp b/test/TopologicalSortTest.cpp index 4e7192fc..05910d34 100644 --- a/test/TopologicalSortTest.cpp +++ b/test/TopologicalSortTest.cpp @@ -95,7 +95,7 @@ TEST(TopologicalSortTest, test_3) { ASSERT_EQ(res.nodesInTopoOrder.size(), 8); // check topological order of nodes - std::unordered_map nodeToOrder; + CXXGraph::Map nodeToOrder; for (size_t i = 0; i < res.nodesInTopoOrder.size(); ++i) { nodeToOrder[res.nodesInTopoOrder[i].getId()] = i; } diff --git a/test/UnionFindTest.cpp b/test/UnionFindTest.cpp index 53328049..15370177 100644 --- a/test/UnionFindTest.cpp +++ b/test/UnionFindTest.cpp @@ -33,7 +33,7 @@ TEST(UnionFindTest, setFindTest1) { CXXGraph::Graph graph(edgeSet); // every element is a subset of itself - std::unordered_map subset; + CXXGraph::Map subset; // {{0, 0}, {1, 0}, {2, 0}, {3, 0}}; CXXGraph::Subset set1{0, 0}, set2{1, 0}, set3{2, 0}, set4{3, 0}; subset = {{0, set1}, {1, set2}, {2, set3}, {3, set4}}; @@ -53,7 +53,7 @@ TEST(UnionFindTest, setFindTest2) { CXXGraph::Node node3("3", 3); // element 2 & 4 are subset of 0 // element 4 is subset of 1 - std::unordered_map subset; + CXXGraph::Map subset; CXXGraph::Subset set1{0, 0}, set2{0, 0}, set3{0, 0}, set4{1, 0}; subset = {{0, set1}, {1, set2}, {2, set3}, {3, set4}}; @@ -77,7 +77,7 @@ TEST(UnionFindTest, setUnionTest3) { CXXGraph::Node node2("2", 2); CXXGraph::Node node3("3", 3); // union of (node 1 & node3) should increase node0 rank by 1 - std::unordered_map subset; + CXXGraph::Map subset; CXXGraph::Subset set1{0, 0}, set2{0, 0}, set3{0, 0}, set4{1, 0}; subset = {{0, set1}, {1, set2}, {2, set3}, {3, set4}};