Some code clean-up.

This commit is contained in:
LoRd_MuldeR 2022-12-01 16:41:08 +01:00
parent 40b4e2d5af
commit 80d18e0fdb
12 changed files with 38 additions and 99 deletions

View File

@ -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

View File

@ -4,7 +4,7 @@
/******************************************************************************/
#include "tests.h"
#include "random.h"
#include <random_in.h>
#include <stdio.h>
#include <inttypes.h>

View File

@ -39,12 +39,12 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\shared\src\random_in.c" />
<ClCompile Include="src\main.c" />
<ClCompile Include="src\random.c" />
<ClCompile Include="src\tests.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\random.h" />
<ClInclude Include="..\shared\include\random_in.h" />
<ClInclude Include="src\tests.h" />
</ItemGroup>
<ItemGroup>
@ -205,7 +205,7 @@
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -232,7 +232,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@ -265,7 +265,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@ -293,7 +293,7 @@
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -308,7 +308,7 @@
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -332,7 +332,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@ -363,7 +363,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@ -393,7 +393,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@ -430,7 +430,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>

View File

@ -18,18 +18,18 @@
<ClCompile Include="src\main.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\random.c">
<ClCompile Include="src\tests.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\tests.c">
<ClCompile Include="..\shared\src\random_in.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\random.h">
<ClInclude Include="src\tests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\tests.h">
<ClInclude Include="..\shared\include\random_in.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>

View File

@ -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

View File

@ -1,39 +0,0 @@
/******************************************************************************/
/* HashSet for C99, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
#include "random.h"
#include <string.h>
#ifndef _WIN32
# include <unistd.h>
#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++];
}

View File

@ -1,22 +0,0 @@
/******************************************************************************/
/* HashSet for C99, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
#ifndef _TEST_RANDOM_INCLUDED
#define _TEST_RANDOM_INCLUDED
#include <stdlib.h>
#include <stdint.h>
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*/

View File

@ -4,7 +4,7 @@
/******************************************************************************/
#include "tests.h"
#include "random.h"
#include <random_in.h>
#include <stdio.h>
#include <inttypes.h>

View File

@ -39,12 +39,12 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\shared\src\random_in.c" />
<ClCompile Include="src\main.c" />
<ClCompile Include="src\random.c" />
<ClCompile Include="src\tests.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\random.h" />
<ClInclude Include="..\shared\include\random_in.h" />
<ClInclude Include="src\tests.h" />
</ItemGroup>
<ItemGroup>
@ -205,7 +205,7 @@
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -232,7 +232,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@ -265,7 +265,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@ -293,7 +293,7 @@
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -308,7 +308,7 @@
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -332,7 +332,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@ -363,7 +363,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@ -393,7 +393,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@ -430,7 +430,7 @@
<Optimization>MaxSpeed</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)\libhashset\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libhashset\include;$(ProjectDir)..\shared\include</AdditionalIncludeDirectories>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>

View File

@ -18,18 +18,18 @@
<ClCompile Include="src\main.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\random.c">
<ClCompile Include="src\tests.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\tests.c">
<ClCompile Include="..\shared\src\random_in.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\random.h">
<ClInclude Include="src\tests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\tests.h">
<ClInclude Include="..\shared\include\random_in.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>

View File

@ -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 <string.h>
#ifndef _WIN32