Format source files

This commit is contained in:
2023-02-18 10:37:38 +01:00
parent 76d93bb1cf
commit d09d4d3d92
12 changed files with 793 additions and 850 deletions

View File

@@ -4,7 +4,7 @@ CFLAGS = -std=c++17 -Wall -g -Wextra
CPPS = $(wildcard test/*.cpp)
EXES = $(patsubst %.cpp, %.out, $(CPPS))
.PHONY: all clean rebuild check
.PHONY: all clean rebuild check format
all: $(EXES)
@@ -19,5 +19,11 @@ EXESQUOTED = $(patsubst %, "%", $(EXES))
check: all
./execute-all.sh
format:
find src/ -name *.cpp -exec clang-format -i {} \;
find src/ -name *.hpp -exec clang-format -i {} \;
find test/ -name *.cpp -exec clang-format -i {} \;
find test/ -name *.hpp -exec clang-format -i {} \;
%.out: %.cpp
$(CC) $(CFLAGS) $< -o $@

View File

@@ -5,21 +5,15 @@
namespace List
{
template<class T>
struct Node
template<class T> struct Node
{
T value;
std::unique_ptr<Node<T>> next;
Node(T const & _value)
: value(_value),
next(nullptr)
{}
Node(T const & _value) : value(_value), next(nullptr) { }
};
template<class T>
class List
{
template<class T> class List {
private:
std::unique_ptr<Node<T>> root;
Node<T> * tailPtr;
@@ -177,15 +171,8 @@ public:
return currentNode->value;
}
std::size_t GetSize() const
{
return size;
}
std::size_t GetSize() const { return size; }
List()
: root(nullptr),
tailPtr(nullptr),
size(0)
{}
List() : root(nullptr), tailPtr(nullptr), size(0) { }
};
}

View File

@@ -1,9 +1,7 @@
#pragma once
#include "vector.hpp"
template<class T>
class RingBuffer
{
template<class T> class RingBuffer {
private:
Vector<T> data;
std::size_t head, tail;
@@ -61,16 +59,7 @@ public:
}
}
bool IsEmpty() const
{
return head == tail;
}
bool IsEmpty() const { return head == tail; }
RingBuffer(std::size_t const size)
: data(),
head(0),
tail(0)
{
data.Resize(size + 1ul);
}
RingBuffer(std::size_t const size) : data(), head(0), tail(0) { data.Resize(size + 1ul); }
};

View File

@@ -1,9 +1,7 @@
#pragma once
#include "vector.hpp"
template<class T>
class Stack
{
template<class T> class Stack {
private:
Vector<T> data;
std::size_t actualSize;
@@ -34,13 +32,7 @@ public:
return retval;
}
std::size_t GetSize() const
{
return actualSize;
}
std::size_t GetSize() const { return actualSize; }
Stack()
: actualSize(0)
{
}
Stack() : actualSize(0) { }
};

View File

@@ -2,9 +2,7 @@
#include <cstdlib>
#include <stdexcept>
template<class T>
class Vector
{
template<class T> class Vector {
private:
T * data;
std::size_t reserveSize;
@@ -68,19 +66,9 @@ public:
return data[index];
}
std::size_t GetSize() const
{
return size;
}
std::size_t GetSize() const { return size; }
std::size_t GetReserveSize() const
{
return reserveSize;
}
std::size_t GetReserveSize() const { return reserveSize; }
Vector()
: data(nullptr),
reserveSize(0ul),
size(0ul)
{}
Vector() : data(nullptr), reserveSize(0ul), size(0ul) { }
};

View File

@@ -3,35 +3,21 @@
namespace BinaryTree
{
template <class T>
struct Node
template<class T> struct Node
{
T value;
std::unique_ptr<Node<T>> left;
std::unique_ptr<Node<T>> right;
bool HasChildren() const
{
return static_cast<bool>(left) || static_cast<bool>(right);
}
bool HasChildren() const { return static_cast<bool>(left) || static_cast<bool>(right); }
bool IsLeaf() const
{
return !HasChildren();
}
bool IsLeaf() const { return !HasChildren(); }
Node(T const &_value)
: value(_value),
left(nullptr),
right(nullptr)
{
}
Node(T const & _value) : value(_value), left(nullptr), right(nullptr) { }
};
template <class T>
class Tree
{
template<class T> class Tree {
private:
std::unique_ptr<Node<T>> root;
@@ -129,10 +115,7 @@ public:
toInsertIn = std::make_unique<Node<T>>(value);
}
bool Contains(T const & value)
{
return static_cast<bool>(FindNode(value));
}
bool Contains(T const & value) { return static_cast<bool>(FindNode(value)); }
void Delete(T const & value)
{
@@ -140,8 +123,6 @@ public:
DeleteNode(node);
}
Tree()
: root(nullptr)
{}
Tree() : root(nullptr) { }
};
} // namespace BinaryTree

View File

@@ -1,9 +1,10 @@
#include "../src/tree/binarytree.hpp"
#include "testutil.hpp"
#include <vector>
#include <unordered_set>
#include <vector>
void FillWithUniqueRandomNumbers(BinaryTree::Tree<unsigned> & tree,
void FillWithUniqueRandomNumbers(
BinaryTree::Tree<unsigned> & tree,
std::unordered_set<unsigned> & control,
unsigned const count = 10000u)
{

View File

@@ -1,8 +1,7 @@
#include "../src/sequential/vector.hpp"
#include "testutil.hpp"
void FillWithSequentialNumbers(Vector<unsigned> & vector,
unsigned const count = 1024u)
void FillWithSequentialNumbers(Vector<unsigned> & vector, unsigned const count = 1024u)
{
for(unsigned i = 0; i < count; ++i)
{