Skip to content

Commit

Permalink
Create clang-format workflow (#390)
Browse files Browse the repository at this point in the history
* Create clang-format workflow

* Fix typo

* Formatting

* Formatting
  • Loading branch information
sbaldu authored Jan 15, 2024
1 parent e319dc5 commit 92a8ea5
Show file tree
Hide file tree
Showing 81 changed files with 483 additions and 409 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/clang_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: clang-format Check

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
strategy:
matrix:
path:
- 'benchmark'
- 'examples'
- 'include/CXXGraph'
- 'test'
steps:
- uses: actions/checkout@v3
- name: Run clang-format style check
uses: jidicula/[email protected]
with:
clang-format-version: '16'
check-path: ${{ matrix.path }}
2 changes: 1 addition & 1 deletion benchmark/BellmanFord_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ static void BellmanFord_FromReadedCitHep(benchmark::State &state) {
}
}

BENCHMARK(BellmanFord_FromReadedCitHep);
BENCHMARK(BellmanFord_FromReadedCitHep);
2 changes: 1 addition & 1 deletion benchmark/Boruvka_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ static void Boruvka_FromReadedCitHep(benchmark::State &state) {
}
}

BENCHMARK(Boruvka_FromReadedCitHep);
BENCHMARK(Boruvka_FromReadedCitHep);
2 changes: 1 addition & 1 deletion benchmark/Connectivity_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ static void StrongConnectivity_FromReadedCitHep(benchmark::State &state) {
}
}

BENCHMARK(StrongConnectivity_FromReadedCitHep);
BENCHMARK(StrongConnectivity_FromReadedCitHep);
2 changes: 1 addition & 1 deletion benchmark/CycleCheck_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ static void CycleCheckDFS_FromReadedCitHep(benchmark::State &state) {
}
}

BENCHMARK(CycleCheckDFS_FromReadedCitHep);
BENCHMARK(CycleCheckDFS_FromReadedCitHep);
2 changes: 1 addition & 1 deletion benchmark/Dial_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ static void Dial_FromReadedCitHep(benchmark::State &state) {
}
}

BENCHMARK(Dial_FromReadedCitHep);
BENCHMARK(Dial_FromReadedCitHep);
2 changes: 1 addition & 1 deletion benchmark/Edge_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ static void NodeGetNodePair(benchmark::State &state) {
e.getNodePair();
}
}
BENCHMARK(NodeGetNodePair);
BENCHMARK(NodeGetNodePair);
1 change: 1 addition & 0 deletions benchmark/FloydWarshall_BM.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <benchmark/benchmark.h>

#include <memory>

#include "CXXGraph/CXXGraph.hpp"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/FordFulkerson_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ static void FordFulkerson_FromReadedCitHep(benchmark::State &state) {
}
}

BENCHMARK(FordFulkerson_FromReadedCitHep);
BENCHMARK(FordFulkerson_FromReadedCitHep);
2 changes: 1 addition & 1 deletion benchmark/Kruskal_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ static void Kruskal_FromReadedCitHep(benchmark::State &state) {
}
}

BENCHMARK(Kruskal_FromReadedCitHep);
BENCHMARK(Kruskal_FromReadedCitHep);
2 changes: 1 addition & 1 deletion benchmark/Node_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ static void NodeGetData(benchmark::State &state) {
n1.getData();
}
}
BENCHMARK(NodeGetData);
BENCHMARK(NodeGetData);
2 changes: 1 addition & 1 deletion benchmark/Partition_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ static void PartitionEBV_FromReadedCitHep(benchmark::State &state) {
}
}

BENCHMARK(PartitionEBV_FromReadedCitHep);
BENCHMARK(PartitionEBV_FromReadedCitHep);
2 changes: 1 addition & 1 deletion benchmark/Prim_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ static void Prim_FromReadedCitHep(benchmark::State &state) {
}
}

BENCHMARK(Prim_FromReadedCitHep);
BENCHMARK(Prim_FromReadedCitHep);
2 changes: 1 addition & 1 deletion benchmark/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <benchmark/benchmark.h>

BENCHMARK_MAIN();
BENCHMARK_MAIN();
2 changes: 1 addition & 1 deletion examples/DialExample/dial_example.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <math.h>
#include <memory>

#include <CXXGraph/CXXGraph.hpp>
#include <memory>

using std::make_shared;

Expand Down
1 change: 0 additions & 1 deletion examples/DijkstraExample/dijkstra_example.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <CXXGraph/CXXGraph.hpp>

#include <memory>

using std::make_shared;
Expand Down
28 changes: 16 additions & 12 deletions examples/NetworkDynamicsExample/network_dynamics_example.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "CXXGraph/CXXGraph.hpp"

#include <memory>

#include "CXXGraph/CXXGraph.hpp"

using std::make_shared;

int main() {
Expand All @@ -25,23 +25,26 @@ int main() {

auto degreeMatrix = graph.getDegreeMatrix();
for (const auto& nodePair : *degreeMatrix) {
const CXXGraph::shared<const CXXGraph::Node<int>>& node = nodePair.first;
const std::vector<int>& degrees = nodePair.second;
const CXXGraph::shared<const CXXGraph::Node<int>>& node = nodePair.first;
const std::vector<int>& degrees = nodePair.second;

std::cout << "Node: " << node->getId() << ", Degree: " << degrees[0] << "\n";
}
std::cout << "Node: " << node->getId() << ", Degree: " << degrees[0]
<< "\n";
}
auto laplacianMatrix = graph.getLaplacianMatrix();
for (const auto& nodePair : *laplacianMatrix) {
const auto& node = nodePair.first;
const auto& neighbors = nodePair.second;

std::cout << "Node " << node->getId() << " connected to:" << std::endl;
for (const auto& neighbor : neighbors) {
if (neighbor.first == node) {
std::cout << " -> Itself" << std::endl;
} else {
std::cout << " -> Node " << neighbor.first->getId() << " with Edge ID " << (neighbor.second ? neighbor.second->getId() : -1) << std::endl;
}
if (neighbor.first == node) {
std::cout << " -> Itself" << std::endl;
} else {
std::cout << " -> Node " << neighbor.first->getId() << " with Edge ID "
<< (neighbor.second ? neighbor.second->getId() : -1)
<< std::endl;
}
}
std::cout << std::endl;
}
Expand All @@ -53,7 +56,8 @@ int main() {

std::cout << "Transitions from Node " << node->getId() << ":" << std::endl;
for (const auto& transition : transitions) {
std::cout << " -> To Node " << transition.first->getId() << " with Probability " << transition.second << std::endl;
std::cout << " -> To Node " << transition.first->getId()
<< " with Probability " << transition.second << std::endl;
}
std::cout << std::endl;
}
Expand Down
15 changes: 9 additions & 6 deletions examples/PartitionExample/partition_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ int main() {
// std::cout << *cit_graph_ptr << std::endl;
std::cout << cit_graph_ptr->getEdgeSet().size() << std::endl;
std::cout << cit_graph_ptr->getNodeSet().size() << std::endl;
auto partitionedTwo = CXXGraph::Partitioning::Partitioner<int>::partitionGraph( *cit_graph_ptr,
CXXGraph::Partitioning::HDRF_ALG, 2, 1, 1, 1, 4);
auto partitionedTwo =
CXXGraph::Partitioning::Partitioner<int>::partitionGraph(
*cit_graph_ptr, CXXGraph::Partitioning::HDRF_ALG, 2, 1, 1, 1, 4);
std::cout << "end partition two" << std::endl;
auto partitionedFour = CXXGraph::Partitioning::Partitioner<int>::partitionGraph( *cit_graph_ptr,
CXXGraph::Partitioning::HDRF_ALG, 4, 1, 1, 1, 4);
auto partitionedFour =
CXXGraph::Partitioning::Partitioner<int>::partitionGraph(
*cit_graph_ptr, CXXGraph::Partitioning::HDRF_ALG, 4, 1, 1, 1, 4);
std::cout << "end partition four" << std::endl;
auto partitionedEight = CXXGraph::Partitioning::Partitioner<int>::partitionGraph( *cit_graph_ptr,
CXXGraph::Partitioning::HDRF_ALG, 8, 1, 1, 1, 4);
auto partitionedEight =
CXXGraph::Partitioning::Partitioner<int>::partitionGraph(
*cit_graph_ptr, CXXGraph::Partitioning::HDRF_ALG, 8, 1, 1, 1, 4);
std::cout << "end partition eight" << std::endl;
auto statsTwo = CXXGraph::Partitioning::getPartitionStats(partitionedTwo);
auto statsFour = CXXGraph::Partitioning::getPartitionStats(partitionedFour);
Expand Down
7 changes: 4 additions & 3 deletions include/CXXGraph/Edge/DirectedEdge_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace CXXGraph {
template <typename T>
using unique = std::unique_ptr<T>;
template <typename T>
using shared= std::shared_ptr<T>;
using shared = std::shared_ptr<T>;

template <typename T>
class UndirectedEdge;
Expand All @@ -48,8 +48,9 @@ class DirectedEdge : public Edge<T> {
shared<const Node<T>> node2);
DirectedEdge(const CXXGraph::id_t id,
const std::pair<const Node<T> *, const Node<T> *> &nodepair);
DirectedEdge(const CXXGraph::id_t id,
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair);
DirectedEdge(
const CXXGraph::id_t id,
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair);
DirectedEdge(const Edge<T> &edge);
virtual ~DirectedEdge() = default;
const Node<T> &getFrom() const;
Expand Down
10 changes: 6 additions & 4 deletions include/CXXGraph/Edge/DirectedEdge_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@
#include "DirectedEdge_decl.h"

namespace CXXGraph {

using std::make_unique;

using std::make_shared;
using std::make_unique;

template <typename T>
DirectedEdge<T>::DirectedEdge(const CXXGraph::id_t id, const Node<T> &node1,
const Node<T> &node2)
: Edge<T>(id, node1, node2) {}

template <typename T>
DirectedEdge<T>::DirectedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
shared<const Node<T>> node2) : Edge<T>(id, node1, node2) {}
DirectedEdge<T>::DirectedEdge(const CXXGraph::id_t id,
shared<const Node<T>> node1,
shared<const Node<T>> node2)
: Edge<T>(id, node1, node2) {}

template <typename T>
DirectedEdge<T>::DirectedEdge(
Expand Down
2 changes: 1 addition & 1 deletion include/CXXGraph/Edge/DirectedWeightedEdge_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace CXXGraph {
template <typename T>
using unique = std::unique_ptr<T>;
template <typename T>
using shared= std::shared_ptr<T>;
using shared = std::shared_ptr<T>;

// Foward Declaration
template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion include/CXXGraph/Edge/DirectedWeightedEdge_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

namespace CXXGraph {

using std::make_unique;
using std::make_shared;
using std::make_unique;

template <typename T>
DirectedWeightedEdge<T>::DirectedWeightedEdge(const CXXGraph::id_t id,
Expand Down
7 changes: 4 additions & 3 deletions include/CXXGraph/Edge/UndirectedEdge_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace CXXGraph {
template <typename T>
using unique = std::unique_ptr<T>;
template <typename T>
using shared= std::shared_ptr<T>;
using shared = std::shared_ptr<T>;

template <typename T>
class UndirectedEdge;
Expand All @@ -47,8 +47,9 @@ class UndirectedEdge : public Edge<T> {
shared<const Node<T>> node2);
UndirectedEdge(const CXXGraph::id_t id,
const std::pair<const Node<T> *, const Node<T> *> &nodepair);
UndirectedEdge(const CXXGraph::id_t id,
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair);
UndirectedEdge(
const CXXGraph::id_t id,
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair);
UndirectedEdge(const Edge<T> &edge);
virtual ~UndirectedEdge() = default;
const Node<T> &getNode1() const;
Expand Down
5 changes: 3 additions & 2 deletions include/CXXGraph/Edge/UndirectedEdge_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@

namespace CXXGraph {

using std::make_unique;
using std::make_shared;
using std::make_unique;

template <typename T>
UndirectedEdge<T>::UndirectedEdge(const CXXGraph::id_t id, const Node<T> &node1,
const Node<T> &node2)
: Edge<T>(id, node1, node2) {}

template <typename T>
UndirectedEdge<T>::UndirectedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
UndirectedEdge<T>::UndirectedEdge(const CXXGraph::id_t id,
shared<const Node<T>> node1,
shared<const Node<T>> node2)
: Edge<T>(id, node1, node2) {}

Expand Down
2 changes: 1 addition & 1 deletion include/CXXGraph/Edge/UndirectedWeightedEdge_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

namespace CXXGraph {

using std::make_unique;
using std::make_shared;
using std::make_unique;

template <typename T>
UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const CXXGraph::id_t id,
Expand Down
9 changes: 5 additions & 4 deletions include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@

#pragma once

#include "CXXGraph/Graph/Graph_decl.h"
#include <thread>
#include <queue>
#include <mutex>
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <queue>
#include <thread>

#include "CXXGraph/Graph/Graph_decl.h"

namespace CXXGraph {
template <typename T>
Expand Down
5 changes: 3 additions & 2 deletions include/CXXGraph/Graph/Algorithm/Boruvka_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

#pragma once

#include "CXXGraph/Graph/Graph_decl.h"
#include <limits.h>

#include "CXXGraph/Graph/Graph_decl.h"

namespace CXXGraph {

template <typename T>
const MstResult Graph<T>::boruvka() const {
MstResult result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,5 @@ const std::vector<Node<T>> Graph<T>::breadth_first_search(
return visited;
}


} // namespace CXXGraph
#endif // __CXXGRAPH_BREADTHFIRSTSEARCH_IMPL_H__
2 changes: 1 addition & 1 deletion include/CXXGraph/Graph/Algorithm/DepthFirstSearch_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "CXXGraph/Graph/Graph_decl.h"

namespace CXXGraph {

template <typename T>
const std::vector<Node<T>> Graph<T>::depth_first_search(
const Node<T> &start) const {
Expand Down
3 changes: 2 additions & 1 deletion include/CXXGraph/Graph/Algorithm/Kosaraju_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

#pragma once

#include "CXXGraph/Graph/Graph_decl.h"
#include <stack>

#include "CXXGraph/Graph/Graph_decl.h"

namespace CXXGraph {

template <typename T>
Expand Down
Loading

0 comments on commit 92a8ea5

Please sign in to comment.