Skip to content

Commit

Permalink
Fixed some whitespace issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanG077 committed Nov 12, 2018
1 parent 87a475b commit cbec14a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 59 deletions.
2 changes: 1 addition & 1 deletion clang_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EINTERNAL=2
EINVAL=3

# variables
PATTERN_DEFAULT='{src,include,test}/**/*.{c,h,cpp,hpp}'
PATTERN_DEFAULT='{src,include,test}/**/*.{c,h,cpp,hpp,ipp}'
declare -a PATTERNS
unset ACTION
unset CLANG_FORMAT_PATH
Expand Down
4 changes: 2 additions & 2 deletions include/BoxNesting/Algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Algorithm
* @brief Run the kuhn algorithm. It's based on the DFS and will try to find
* chains of maximum length.
*
* @param vertex The index of the vertex in the left part of the
* Bipartite graph to start running the algorithm from
* @param vertex The index of the vertex in the left part of the
* Bipartite graph to start running the algorithm from
*
* @return Whether a chain could be made
*/
Expand Down
41 changes: 21 additions & 20 deletions include/Graph/AdjacencyMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace Graph
{
/**
* @brief Class that can be used to store a 2d array continously in memory
* @brief Class that can be used to store an AdjacencyMatrix continously in memory
*
* @tparam T The type to store in the array
* @tparam T The type to store in the matrix
*/
template<class T> class AdjacencyMatrix
{
Expand All @@ -30,20 +30,21 @@ template<class T> class AdjacencyMatrix
* @param r The amount of right vertices
*/
AdjacencyMatrix(size_t l, size_t r) : data(l * r), leftCount(l), rightCount(r)
{
}
{

}

/**
* @brief Get element at specified indices
*
* @param l The left vertex index
* @param r The right vertex index
*
* @throws std::out_of_range if index is out of range
*
* @return Value at that index
*/
[[nodiscard]] T& at(size_t l, size_t r)
/**
* @brief Get element at specified indices
*
* @param l The left vertex index
* @param r The right vertex index
*
* @throws std::out_of_range if index is out of range
*
* @return Value at that index
*/
[[nodiscard]] T& at(size_t l, size_t r)
{
return this->data.at(l * this->rightCount + r);
}
Expand All @@ -60,11 +61,11 @@ template<class T> class AdjacencyMatrix
*/
[[nodiscard]] const T& at(size_t l, size_t r) const { return this->data.at(l * this->rightCount + r); }

private:
/**
* @brief Contains the data of the adjacencyMatrix
*/
std::vector<T> data;
private:
/**
* @brief Contains the data of the adjacencyMatrix
*/
std::vector<T> data;

/**
* @brief Contains the amount of left vertices
Expand Down
3 changes: 2 additions & 1 deletion include/Graph/BipartiteGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ template<class T> class BipartiteGraph
* @return The left vertices of the bipartite graph
*/
[[nodiscard]] const std::vector<Vertex<T>>& getLeftVertices() const noexcept;

/**
* @brief Get the rigt Vertices of the bipartite graph
*
Expand All @@ -86,7 +87,7 @@ template<class T> class BipartiteGraph

/**
* @brief Contains the edges between the left and right vertices
* The vector specialization of bool is broken so we use uint8_t instead of bool
* The vector specialization of bool is broken so we use uint8_t instead of bool
*/
AdjacencyMatrix<uint8_t> adjacencyMatrix;
};
Expand Down
24 changes: 8 additions & 16 deletions include/Graph/BipartiteGraph.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,34 @@

namespace Graph
{

template <class T>
BipartiteGraph<T>::BipartiteGraph(std::vector<Vertex<T>> leftVertices, std::vector<Vertex<T>> rightVertices)
: leftVertices(std::move(leftVertices)),
rightVertices(std::move(rightVertices)),
template<class T>
BipartiteGraph<T>::BipartiteGraph(std::vector<Vertex<T>> leftVertices, std::vector<Vertex<T>> rightVertices) :
leftVertices(std::move(leftVertices)), rightVertices(std::move(rightVertices)),
adjacencyMatrix(AdjacencyMatrix<uint8_t>(this->leftVertices.size(), this->rightVertices.size()))
{

}

template <class T>
void BipartiteGraph<T>::addEdge(uint16_t v1, uint16_t v2)
template<class T> void BipartiteGraph<T>::addEdge(uint16_t v1, uint16_t v2)
{
this->adjacencyMatrix.at(v1, v2) = true;
}

template <class T>
bool BipartiteGraph<T>::isEdgeBetween(uint16_t v1, uint16_t v2) const
template<class T> bool BipartiteGraph<T>::isEdgeBetween(uint16_t v1, uint16_t v2) const
{
return this->adjacencyMatrix.at(v1, v2);
}

template <class T>
const AdjacencyMatrix<uint8_t>& BipartiteGraph<T>::getAdjacencyMatrix() const noexcept
template<class T> const AdjacencyMatrix<uint8_t>& BipartiteGraph<T>::getAdjacencyMatrix() const noexcept
{
return this->adjacencyMatrix;
}

template <class T>
const std::vector<Vertex<T>>& BipartiteGraph<T>::getLeftVertices() const noexcept
template<class T> const std::vector<Vertex<T>>& BipartiteGraph<T>::getLeftVertices() const noexcept
{
return this->leftVertices;
}

template <class T>
const std::vector<Vertex<T>>& BipartiteGraph<T>::getRightVertices() const noexcept
template<class T> const std::vector<Vertex<T>>& BipartiteGraph<T>::getRightVertices() const noexcept
{
return this->rightVertices;
}
Expand Down
12 changes: 12 additions & 0 deletions include/Graph/Vertex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,20 @@ template<class T> class Vertex
[[nodiscard]] uint16_t getId() const;

private:
/**
* @brief Static counter that is used to create new id
* everytime a new vertex is constructed
*/
static uint16_t idCounter;

/**
* @brief The id of the vertex
*/
const uint16_t id;

/**
* @brief The content of the vertex
*/
const T content;
};

Expand Down
24 changes: 9 additions & 15 deletions include/Graph/Vertex.ipp
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
namespace Graph
{
template<class T> uint16_t Vertex<T>::idCounter = 0;

template <class T>
uint16_t Vertex<T>::idCounter = 0;

template <class T>
Vertex<T>::Vertex(T con): id(++idCounter), content(std::move(con))
template<class T> Vertex<T>::Vertex(T con) : id(++idCounter), content(std::move(con))
{
}

template <class T>
bool Vertex<T>::operator==(const Vertex<T>& rhs) const
template<class T> bool Vertex<T>::operator==(const Vertex<T>& rhs) const
{
return this->id == rhs.getId();
return this->id == rhs.getId();
}

template <class T>
const T& Vertex<T>::getContent() const
template<class T> const T& Vertex<T>::getContent() const
{
return this->content;
return this->content;
}

template <class T>
uint16_t Vertex<T>::getId() const
template<class T> uint16_t Vertex<T>::getId() const
{
return this->id;
return this->id;
}

} //namespace Graph
} // namespace Graph
3 changes: 3 additions & 0 deletions src/Box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace BoxNesting
{
Box::Box(const std::array<float, 3>& sideLengths) : sideLengths(sideLengths)
{
// Sice we only care whether a box can nest inside another box
// We can optimize this check by always just sorting the lengths
// so we don't have to check the permutations of the sidelengths
std::sort(this->sideLengths.begin(), this->sideLengths.end());

for (auto l : this->sideLengths) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void printHelp(const std::string& progName)
}

int main(int argc, char** argv)
{
{
// Because ptr arithmatic is not allowed but we need it here
// to access program arguments we exclude no lint here
std::vector<std::string> arguments(argv, argv + argc); // NOLINT
Expand Down
9 changes: 6 additions & 3 deletions test/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ SCENARIO("Running the 'graph creation from a set of boxes' function")

GIVEN("A set of boxes where every box except for one can nest inside another")
{
std::vector<BoxNesting::Box> boxes{BoxNesting::Box({0.9f, 0.9f, 0.9f}), BoxNesting::Box({0.8f, 0.8f, 0.8f}),
BoxNesting::Box({0.7f, 0.7f, 0.7f}), BoxNesting::Box({0.6f, 0.6f, 0.6f})};
std::vector<BoxNesting::Box> boxes{BoxNesting::Box({0.9f, 0.9f, 0.9f}),
BoxNesting::Box({0.8f, 0.8f, 0.8f}),
BoxNesting::Box({0.7f, 0.7f, 0.7f}),
BoxNesting::Box({0.6f, 0.6f, 0.6f})};

THEN("Only one visible box remains after nesting")
{
Expand All @@ -51,7 +53,8 @@ SCENARIO("Running the 'graph creation from a set of boxes' function")

GIVEN("A set of boxes where only one box can nest inside another")
{
std::vector<BoxNesting::Box> boxes1{BoxNesting::Box({0.6f, 0.6f, 0.6f}), BoxNesting::Box({0.75f, 0.75f, 0.75f}),
std::vector<BoxNesting::Box> boxes1{BoxNesting::Box({0.6f, 0.6f, 0.6f}),
BoxNesting::Box({0.75f, 0.75f, 0.75f}),
BoxNesting::Box({0.9f, 0.7f, 0.7f})};

std::vector<BoxNesting::Box> boxes2{BoxNesting::Box({0.75f, 0.75f, 0.75f}),
Expand Down

0 comments on commit cbec14a

Please sign in to comment.