From 80d18e0fdb4380c4355097dc07351159af011443 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Thu, 1 Dec 2022 16:41:08 +0100 Subject: [PATCH] Some code clean-up. --- test/hash-map/Makefile | 6 +-- test/hash-map/src/tests.c | 2 +- test/hash-map/test-hash-map.vcxproj | 22 +++++------ test/hash-map/test-hash-map.vcxproj.filters | 8 ++-- test/hash-set/Makefile | 4 +- test/hash-set/src/random.c | 39 ------------------- test/hash-set/src/random.h | 22 ----------- test/hash-set/src/tests.c | 2 +- test/hash-set/test-hash-set.vcxproj | 22 +++++------ test/hash-set/test-hash-set.vcxproj.filters | 8 ++-- .../random.h => shared/include/random_in.h} | 0 .../src/random.c => shared/src/random_in.c} | 2 +- 12 files changed, 38 insertions(+), 99 deletions(-) delete mode 100644 test/hash-set/src/random.c delete mode 100644 test/hash-set/src/random.h rename test/{hash-map/src/random.h => shared/include/random_in.h} (100%) rename test/{hash-map/src/random.c => shared/src/random_in.c} (96%) diff --git a/test/hash-map/Makefile b/test/hash-map/Makefile index c4ffd7a..0aa5fab 100644 --- a/test/hash-map/Makefile +++ b/test/hash-map/Makefile @@ -1,14 +1,14 @@ include ../../config.mk -CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../../libhashset/include $(XCFLAGS) +CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../../libhashset/include -I../shared/include $(XCFLAGS) LDFLAGS = -L../../libhashset/lib -lhashset-1 $(XLDFLAGS) SRC_PATH := src BIN_PATH := bin ALL_PATH := $(SRC_PATH) $(BIN_PATH) -BIN_FILE := $(BIN_PATH)/test-hash-set$(EXE_SUFFIX) -SRC_FILE := $(wildcard $(SRC_PATH)/*.c) +BIN_FILE := $(BIN_PATH)/test-hash-map$(EXE_SUFFIX) +SRC_FILE := $(wildcard $(SRC_PATH)/*.c) $(wildcard ../shared/src/*.c) .PHONY: all clean test diff --git a/test/hash-map/src/tests.c b/test/hash-map/src/tests.c index 1362809..21d81c1 100644 --- a/test/hash-map/src/tests.c +++ b/test/hash-map/src/tests.c @@ -4,7 +4,7 @@ /******************************************************************************/ #include "tests.h" -#include "random.h" +#include #include #include diff --git a/test/hash-map/test-hash-map.vcxproj b/test/hash-map/test-hash-map.vcxproj index 5b0a80e..759c685 100644 --- a/test/hash-map/test-hash-map.vcxproj +++ b/test/hash-map/test-hash-map.vcxproj @@ -39,12 +39,12 @@ + - - + @@ -205,7 +205,7 @@ false WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Console @@ -232,7 +232,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast @@ -265,7 +265,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast @@ -293,7 +293,7 @@ false _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Console @@ -308,7 +308,7 @@ false _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Console @@ -332,7 +332,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast @@ -363,7 +363,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast @@ -393,7 +393,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast @@ -430,7 +430,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast diff --git a/test/hash-map/test-hash-map.vcxproj.filters b/test/hash-map/test-hash-map.vcxproj.filters index 100d11c..df46186 100644 --- a/test/hash-map/test-hash-map.vcxproj.filters +++ b/test/hash-map/test-hash-map.vcxproj.filters @@ -18,18 +18,18 @@ Source Files - + Source Files - + Source Files - + Header Files - + Header Files diff --git a/test/hash-set/Makefile b/test/hash-set/Makefile index c4ffd7a..8340a45 100644 --- a/test/hash-set/Makefile +++ b/test/hash-set/Makefile @@ -1,6 +1,6 @@ include ../../config.mk -CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../../libhashset/include $(XCFLAGS) +CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../../libhashset/include -I../shared/include $(XCFLAGS) LDFLAGS = -L../../libhashset/lib -lhashset-1 $(XLDFLAGS) SRC_PATH := src @@ -8,7 +8,7 @@ BIN_PATH := bin ALL_PATH := $(SRC_PATH) $(BIN_PATH) BIN_FILE := $(BIN_PATH)/test-hash-set$(EXE_SUFFIX) -SRC_FILE := $(wildcard $(SRC_PATH)/*.c) +SRC_FILE := $(wildcard $(SRC_PATH)/*.c) $(wildcard ../shared/src/*.c) .PHONY: all clean test diff --git a/test/hash-set/src/random.c b/test/hash-set/src/random.c deleted file mode 100644 index bd13c50..0000000 --- a/test/hash-set/src/random.c +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************/ -/* HashSet for C99, by LoRd_MuldeR */ -/* This work has been released under the CC0 1.0 Universal license! */ -/******************************************************************************/ - -#include "random.h" -#include - -#ifndef _WIN32 -# include -#endif - -#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0U])) - -#ifdef _WIN32 -#define RtlGenRandom SystemFunction036 -#define getentropy(X,Y) (RtlGenRandom((X),(uint32_t)(Y)) ? 0 : (-1)) -unsigned char __stdcall RtlGenRandom(void* buffer, uint32_t length); -#endif - -void random_init(random_t *const rnd) -{ - memset(rnd, 0, sizeof(random_t)); - rnd->offset = SIZE_MAX; -} - -uint64_t random_next(random_t *const rnd) -{ - if (rnd->offset >= ARRAY_SIZE(rnd->buffer)) - { - rnd->offset = 0U; - if (getentropy(rnd->buffer, sizeof(rnd->buffer)) < 0) - { - abort(); - } - } - - return rnd->buffer[rnd->offset++]; -} diff --git a/test/hash-set/src/random.h b/test/hash-set/src/random.h deleted file mode 100644 index f7b698b..0000000 --- a/test/hash-set/src/random.h +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************/ -/* HashSet for C99, by LoRd_MuldeR */ -/* This work has been released under the CC0 1.0 Universal license! */ -/******************************************************************************/ - -#ifndef _TEST_RANDOM_INCLUDED -#define _TEST_RANDOM_INCLUDED - -#include -#include - -typedef struct -{ - size_t offset; - uint64_t buffer[16U]; -} -random_t; - -void random_init(random_t *const rnd); -uint64_t random_next(random_t *const rnd); - -#endif /*_TEST_RANDOM_INCLUDED*/ diff --git a/test/hash-set/src/tests.c b/test/hash-set/src/tests.c index 5144284..28950e3 100644 --- a/test/hash-set/src/tests.c +++ b/test/hash-set/src/tests.c @@ -4,7 +4,7 @@ /******************************************************************************/ #include "tests.h" -#include "random.h" +#include #include #include diff --git a/test/hash-set/test-hash-set.vcxproj b/test/hash-set/test-hash-set.vcxproj index 6ad33b7..dfb13e1 100644 --- a/test/hash-set/test-hash-set.vcxproj +++ b/test/hash-set/test-hash-set.vcxproj @@ -39,12 +39,12 @@ + - - + @@ -205,7 +205,7 @@ false WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Console @@ -232,7 +232,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast @@ -265,7 +265,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast @@ -293,7 +293,7 @@ false _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Console @@ -308,7 +308,7 @@ false _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Console @@ -332,7 +332,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast @@ -363,7 +363,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast @@ -393,7 +393,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast @@ -430,7 +430,7 @@ MaxSpeed Speed true - $(SolutionDir)\libhashset\include + $(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include Fast diff --git a/test/hash-set/test-hash-set.vcxproj.filters b/test/hash-set/test-hash-set.vcxproj.filters index 100d11c..df46186 100644 --- a/test/hash-set/test-hash-set.vcxproj.filters +++ b/test/hash-set/test-hash-set.vcxproj.filters @@ -18,18 +18,18 @@ Source Files - + Source Files - + Source Files - + Header Files - + Header Files diff --git a/test/hash-map/src/random.h b/test/shared/include/random_in.h similarity index 100% rename from test/hash-map/src/random.h rename to test/shared/include/random_in.h diff --git a/test/hash-map/src/random.c b/test/shared/src/random_in.c similarity index 96% rename from test/hash-map/src/random.c rename to test/shared/src/random_in.c index bd13c50..c26ff96 100644 --- a/test/hash-map/src/random.c +++ b/test/shared/src/random_in.c @@ -3,7 +3,7 @@ /* This work has been released under the CC0 1.0 Universal license! */ /******************************************************************************/ -#include "random.h" +#include "../include/random_in.h" #include #ifndef _WIN32