Compare commits
5 Commits
a90aca8c5b
...
0da832aa8b
Author | SHA1 | Date | |
---|---|---|---|
|
0da832aa8b | ||
|
674c5da3cc | ||
|
a19787f273 | ||
|
1193c504cd | ||
|
ea871e388a |
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@ -0,0 +1,6 @@
|
||||
.ccls-cache
|
||||
.git
|
||||
bin
|
||||
Dockerfile
|
||||
LICENCE
|
||||
README.md
|
@ -1,4 +1,4 @@
|
||||
FROM alpine:3.17.1
|
||||
FROM alpine:3.19.0
|
||||
|
||||
RUN apk add make g++
|
||||
|
||||
@ -17,6 +17,6 @@ RUN chown -R saundersp /home/saundersp/sorting_algorithms
|
||||
|
||||
USER saundersp
|
||||
|
||||
RUN make -j $NPROC
|
||||
RUN make -j $(nproc)
|
||||
|
||||
ENTRYPOINT ["bin/data"]
|
||||
|
52
Makefile
52
Makefile
@ -1,11 +1,9 @@
|
||||
CC := g++ -m64 -std=c++17
|
||||
OBJ_DIR := bin
|
||||
$(shell mkdir -p $(OBJ_DIR))
|
||||
SRC_DIR := .
|
||||
#CFLAGS := -Og -g -Wall -Wextra -Wno-error=unused-function -pedantic -rdynamic
|
||||
#CFLAGS := $(CFLAGS) -pg -ggdb3
|
||||
#CFLAGS := $(CFLAGS) -D__DEBUG
|
||||
CFLAGS := -O4 -Wall -Wextra -Wno-error=unused-function
|
||||
#CFLAGS := -Og -g -rdynamic -pg -ggdb3 -D__DEBUG
|
||||
CFLAGS := -O2
|
||||
CFLAGS := $(CFLAGS) -Wall -Wextra -Wno-error=unused-function -pedantic
|
||||
EXEC := $(OBJ_DIR)/data
|
||||
SRC := $(wildcard $(SRC_DIR)/*.cpp)
|
||||
HEADER := $(wildcard $(SRC_DIR)/*.hpp)
|
||||
@ -16,11 +14,14 @@ ifeq ($(OS), Windows_NT)
|
||||
endif
|
||||
OBJ := $(SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.$(OBJ_EXT))
|
||||
|
||||
.PHONY: all start clean mrproper
|
||||
.PHONY: all start profile debug check r2 clean mrproper
|
||||
|
||||
all: $(EXEC)
|
||||
|
||||
$(OBJ_DIR)/%.$(OBJ_EXT): $(SRC_DIR)/%.cpp $(SRC_DIR)/%.hpp
|
||||
$(OBJ_DIR):
|
||||
@mkdir -v $@
|
||||
|
||||
$(OBJ_DIR)/%.$(OBJ_EXT): $(SRC_DIR)/%.cpp $(SRC_DIR)/%.hpp | $(OBJ_DIR)
|
||||
@echo Compiling $<
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
@ -31,20 +32,43 @@ $(EXEC): $(OBJ)
|
||||
start: $(EXEC)
|
||||
@./$(EXEC)
|
||||
|
||||
profile: start
|
||||
profile: start | check-gprof-works check-gprof2dot-works
|
||||
@gprof $(EXEC) gmon.out | gprof2dot | dot -Tpng -o output.png
|
||||
|
||||
debug: $(EXEC)
|
||||
debug: $(EXEC) | check-gdb-works
|
||||
@gdb -q -tui $(EXEC) -x copies
|
||||
|
||||
check: $(EXEC)
|
||||
check: $(EXEC) | check-valgrind-works
|
||||
@valgrind -q -s --leak-check=full --show-leak-kinds=all $(EXEC)
|
||||
|
||||
r2: $(EXEC)
|
||||
r2: $(EXEC) | check-r2-works
|
||||
@r2 $(EXEC)
|
||||
|
||||
clean:
|
||||
@rm $(EXEC) gmon.out output.png
|
||||
@rm -fv $(EXEC) gmon.out output.png
|
||||
|
||||
mrproper:
|
||||
@rm -r $(OBJ_DIR)
|
||||
mrproper: clean
|
||||
@rm -rv $(OBJ_DIR)
|
||||
|
||||
.PHONY: check-env
|
||||
check-env: check-gprof2dot-works check-gprof-works check-gdb-works check-valgrind-works check-r2-works
|
||||
|
||||
.PHONY: check-gprof2dot-works
|
||||
check-gprof2dot-works:
|
||||
@gprof2dot --help >/dev/null 2>&1 || (echo 'Please install gprof2dot.' && exit 1)
|
||||
|
||||
.PHONY: check-gprof-works
|
||||
check-gprof-works:
|
||||
@gprof --version >/dev/null 2>&1 || (echo 'Please install gprof.' && exit 1)
|
||||
|
||||
.PHONY: check-gdb-works
|
||||
check-gdb-works:
|
||||
@gdb --version >/dev/null 2>&1 || (echo 'Please install gdb.' && exit 1)
|
||||
|
||||
.PHONY: check-valgrind-works
|
||||
check-valgrind-works:
|
||||
@valgrind --version >/dev/null 2>&1 || (echo 'Please install valgrind.' && exit 1)
|
||||
|
||||
.PHONY: check-r2-works
|
||||
check-r2-works:
|
||||
@r2 -v >/dev/null 2>&1 || (echo 'Please install r2.' && exit 1)
|
||||
|
3
data.cpp
3
data.cpp
@ -1,4 +1,3 @@
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
#include <random>
|
||||
#include "toolbox.hpp"
|
||||
@ -61,7 +60,7 @@ static asp::Array<T> create_random_array(const size_t& n) noexcept {
|
||||
return std::move(asp::map(original, [& distrib, & gen](const size_t&, const T&) -> const T { return distrib(gen); }));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int32_t main(int32_t argc, char** argv) {
|
||||
asp::toolbox_unit_test();
|
||||
|
||||
using array_type = uint16_t;
|
||||
|
41
data.hpp
41
data.hpp
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
#ifdef __DEBUG
|
||||
#include <stdexcept>
|
||||
#endif
|
||||
|
||||
namespace asp {
|
||||
template<typename T>
|
||||
@ -44,8 +45,8 @@ namespace asp {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
int print(const Array<T>& a, const char* format) noexcept {
|
||||
int num_written = 0;
|
||||
int32_t print(const Array<T>& a, const char* format) noexcept {
|
||||
int32_t num_written = 0;
|
||||
num_written += printf("[");
|
||||
char formatter[BUFSIZ] = { 0 };
|
||||
sprintf(formatter, "%s,", format);
|
||||
@ -56,24 +57,28 @@ namespace asp {
|
||||
return num_written;
|
||||
}
|
||||
|
||||
int print(const Array<int>& a) noexcept {
|
||||
int32_t print(const Array<uint16_t>& a) noexcept {
|
||||
return print(a, "%b");
|
||||
}
|
||||
|
||||
int32_t print(const Array<int32_t>& a) noexcept {
|
||||
return print(a, "%i");
|
||||
}
|
||||
|
||||
int print(const Array<uint64_t>& a) noexcept {
|
||||
int32_t print(const Array<uint64_t>& a) noexcept {
|
||||
return print(a, "%lu");
|
||||
}
|
||||
|
||||
int print(const Array<int16_t>& a) noexcept {
|
||||
int32_t print(const Array<int16_t>& a) noexcept {
|
||||
//printf("%i\n", a[0]);
|
||||
return print(a, "%i");
|
||||
}
|
||||
|
||||
int print(const std::string& s) noexcept {
|
||||
int32_t print(const std::string& s) noexcept {
|
||||
return printf("%s\n", s.c_str());
|
||||
}
|
||||
|
||||
int print(const char* s) noexcept {
|
||||
int32_t print(const char* s) noexcept {
|
||||
return printf("%s\n", s);
|
||||
}
|
||||
|
||||
@ -385,23 +390,23 @@ namespace asp {
|
||||
return mergesort_arg(a, 0, a.length - 1);
|
||||
}
|
||||
|
||||
//static void count_sort(const Array<int>& a, const int& exp, const int& d) noexcept {
|
||||
// Array<int> output(a.length), count(d);
|
||||
// memset(&count[0], 0, d * sizeof(int));
|
||||
//static void count_sort(const Array<int32_t>& a, const int32_t& exp, const int32_t& d) noexcept {
|
||||
// Array<int32_t> output(a.length), count(d);
|
||||
// memset(&count[0], 0, d * sizeof(int32_t));
|
||||
|
||||
// foreach(a, [count, exp, d](const int&, const int& val) -> void {
|
||||
// foreach(a, [count, exp, d](const int32_t&, const int32_t& val) -> void {
|
||||
// count[(val / exp) % d]++;
|
||||
// });
|
||||
|
||||
// for (int i = 1; i <= d; ++i)
|
||||
// for (int32_t i = 1; i <= d; ++i)
|
||||
// count[i] += count[i - 1];
|
||||
|
||||
// for (int i = a.length - 1; i >= 0; --i) {
|
||||
// for (int32_t i = a.length - 1; i >= 0; --i) {
|
||||
// output[count[(a[i] / exp) % d] - 1] = a[i];
|
||||
// count[(a[i] / exp) % d]--;
|
||||
// }
|
||||
|
||||
// memcpy(&a[0], &output[0], a.length * sizeof(int));
|
||||
// memcpy(&a[0], &output[0], a.length * sizeof(int32_t));
|
||||
//}
|
||||
|
||||
template<typename T>
|
||||
@ -423,7 +428,7 @@ namespace asp {
|
||||
template<typename T>
|
||||
inline void radix_sort_256(T* a, const size_t& n) noexcept {
|
||||
//template<typename T>
|
||||
//void radix_sort(const Array<int>& a) noexcept {
|
||||
//void radix_sort(const Array<int32_t>& a) noexcept {
|
||||
if (n <= 1)
|
||||
//if (a.length <= 1)
|
||||
return;
|
||||
@ -447,7 +452,7 @@ namespace asp {
|
||||
count[i] += count[i - 1];
|
||||
|
||||
// Build the output array
|
||||
for (int i = n - 1; i >= 0; i--) {
|
||||
for (int32_t i = n - 1; i >= 0; i--) {
|
||||
// precalculate the offset as it's a few instructions
|
||||
const size_t idx = (a[i] >> s) & 0xff;
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <array>
|
||||
#include "toolbox.hpp"
|
||||
|
||||
@ -125,8 +124,8 @@ namespace asp {
|
||||
std::string thousand_sep(const uint64_t& k, const char& sep) noexcept {
|
||||
std::string s = "", n = std::to_string(k);
|
||||
|
||||
int c = 0;
|
||||
for (int i = static_cast<int>(n.size()) - 1; i >= 0; --i) {
|
||||
int32_t c = 0;
|
||||
for (int32_t i = static_cast<int32_t>(n.size()) - 1; i >= 0; --i) {
|
||||
c++;
|
||||
s.push_back(n[i]);
|
||||
if (c == 3) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user