Format source files
This commit is contained in:
8
makefile
8
makefile
@@ -4,7 +4,7 @@ CFLAGS = -std=c++17 -Wall -g -Wextra
|
|||||||
CPPS = $(wildcard test/*.cpp)
|
CPPS = $(wildcard test/*.cpp)
|
||||||
EXES = $(patsubst %.cpp, %.out, $(CPPS))
|
EXES = $(patsubst %.cpp, %.out, $(CPPS))
|
||||||
|
|
||||||
.PHONY: all clean rebuild check
|
.PHONY: all clean rebuild check format
|
||||||
|
|
||||||
all: $(EXES)
|
all: $(EXES)
|
||||||
|
|
||||||
@@ -19,5 +19,11 @@ EXESQUOTED = $(patsubst %, "%", $(EXES))
|
|||||||
check: all
|
check: all
|
||||||
./execute-all.sh
|
./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
|
%.out: %.cpp
|
||||||
$(CC) $(CFLAGS) $< -o $@
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
@@ -5,21 +5,15 @@
|
|||||||
namespace List
|
namespace List
|
||||||
{
|
{
|
||||||
|
|
||||||
template<class T>
|
template<class T> struct Node
|
||||||
struct Node
|
|
||||||
{
|
{
|
||||||
T value;
|
T value;
|
||||||
std::unique_ptr<Node<T>> next;
|
std::unique_ptr<Node<T>> next;
|
||||||
|
|
||||||
Node(T const & _value)
|
Node(T const & _value) : value(_value), next(nullptr) { }
|
||||||
: value(_value),
|
|
||||||
next(nullptr)
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T> class List {
|
||||||
class List
|
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Node<T>> root;
|
std::unique_ptr<Node<T>> root;
|
||||||
Node<T> * tailPtr;
|
Node<T> * tailPtr;
|
||||||
@@ -177,15 +171,8 @@ public:
|
|||||||
return currentNode->value;
|
return currentNode->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t GetSize() const
|
std::size_t GetSize() const { return size; }
|
||||||
{
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
List()
|
List() : root(nullptr), tailPtr(nullptr), size(0) { }
|
||||||
: root(nullptr),
|
|
||||||
tailPtr(nullptr),
|
|
||||||
size(0)
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "vector.hpp"
|
#include "vector.hpp"
|
||||||
|
|
||||||
template<class T>
|
template<class T> class RingBuffer {
|
||||||
class RingBuffer
|
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
Vector<T> data;
|
Vector<T> data;
|
||||||
std::size_t head, tail;
|
std::size_t head, tail;
|
||||||
@@ -61,16 +59,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsEmpty() const
|
bool IsEmpty() const { return head == tail; }
|
||||||
{
|
|
||||||
return head == tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
RingBuffer(std::size_t const size)
|
RingBuffer(std::size_t const size) : data(), head(0), tail(0) { data.Resize(size + 1ul); }
|
||||||
: data(),
|
|
||||||
head(0),
|
|
||||||
tail(0)
|
|
||||||
{
|
|
||||||
data.Resize(size + 1ul);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "vector.hpp"
|
#include "vector.hpp"
|
||||||
|
|
||||||
template<class T>
|
template<class T> class Stack {
|
||||||
class Stack
|
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
Vector<T> data;
|
Vector<T> data;
|
||||||
std::size_t actualSize;
|
std::size_t actualSize;
|
||||||
@@ -34,13 +32,7 @@ public:
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t GetSize() const
|
std::size_t GetSize() const { return actualSize; }
|
||||||
{
|
|
||||||
return actualSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
Stack()
|
Stack() : actualSize(0) { }
|
||||||
: actualSize(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
@@ -2,9 +2,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
template<class T>
|
template<class T> class Vector {
|
||||||
class Vector
|
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
T * data;
|
T * data;
|
||||||
std::size_t reserveSize;
|
std::size_t reserveSize;
|
||||||
@@ -68,19 +66,9 @@ public:
|
|||||||
return data[index];
|
return data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t GetSize() const
|
std::size_t GetSize() const { return size; }
|
||||||
{
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t GetReserveSize() const
|
std::size_t GetReserveSize() const { return reserveSize; }
|
||||||
{
|
|
||||||
return reserveSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector()
|
Vector() : data(nullptr), reserveSize(0ul), size(0ul) { }
|
||||||
: data(nullptr),
|
|
||||||
reserveSize(0ul),
|
|
||||||
size(0ul)
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
@@ -3,35 +3,21 @@
|
|||||||
|
|
||||||
namespace BinaryTree
|
namespace BinaryTree
|
||||||
{
|
{
|
||||||
template <class T>
|
template<class T> struct Node
|
||||||
struct Node
|
|
||||||
{
|
{
|
||||||
T value;
|
T value;
|
||||||
|
|
||||||
std::unique_ptr<Node<T>> left;
|
std::unique_ptr<Node<T>> left;
|
||||||
std::unique_ptr<Node<T>> right;
|
std::unique_ptr<Node<T>> right;
|
||||||
|
|
||||||
bool HasChildren() const
|
bool HasChildren() const { return static_cast<bool>(left) || static_cast<bool>(right); }
|
||||||
{
|
|
||||||
return static_cast<bool>(left) || static_cast<bool>(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsLeaf() const
|
bool IsLeaf() const { return !HasChildren(); }
|
||||||
{
|
|
||||||
return !HasChildren();
|
|
||||||
}
|
|
||||||
|
|
||||||
Node(T const &_value)
|
Node(T const & _value) : value(_value), left(nullptr), right(nullptr) { }
|
||||||
: value(_value),
|
|
||||||
left(nullptr),
|
|
||||||
right(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template<class T> class Tree {
|
||||||
class Tree
|
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Node<T>> root;
|
std::unique_ptr<Node<T>> root;
|
||||||
|
|
||||||
@@ -129,10 +115,7 @@ public:
|
|||||||
toInsertIn = std::make_unique<Node<T>>(value);
|
toInsertIn = std::make_unique<Node<T>>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Contains(T const & value)
|
bool Contains(T const & value) { return static_cast<bool>(FindNode(value)); }
|
||||||
{
|
|
||||||
return static_cast<bool>(FindNode(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Delete(T const & value)
|
void Delete(T const & value)
|
||||||
{
|
{
|
||||||
@@ -140,8 +123,6 @@ public:
|
|||||||
DeleteNode(node);
|
DeleteNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tree()
|
Tree() : root(nullptr) { }
|
||||||
: root(nullptr)
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
} // namespace BinaryTree
|
} // namespace BinaryTree
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
#include "../src/tree/binarytree.hpp"
|
#include "../src/tree/binarytree.hpp"
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
#include <vector>
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
void FillWithUniqueRandomNumbers(BinaryTree::Tree<unsigned> & tree,
|
void FillWithUniqueRandomNumbers(
|
||||||
|
BinaryTree::Tree<unsigned> & tree,
|
||||||
std::unordered_set<unsigned> & control,
|
std::unordered_set<unsigned> & control,
|
||||||
unsigned const count = 10000u)
|
unsigned const count = 10000u)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#include "../src/sequential/vector.hpp"
|
#include "../src/sequential/vector.hpp"
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
|
||||||
void FillWithSequentialNumbers(Vector<unsigned> & vector,
|
void FillWithSequentialNumbers(Vector<unsigned> & vector, unsigned const count = 1024u)
|
||||||
unsigned const count = 1024u)
|
|
||||||
{
|
{
|
||||||
for(unsigned i = 0; i < count; ++i)
|
for(unsigned i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user