Added build script for MSVC.

This commit is contained in:
LoRd_MuldeR 2022-11-25 16:32:58 +01:00
parent 5675964db1
commit bafc46eeed
7 changed files with 110 additions and 44 deletions

View File

@ -19,8 +19,8 @@ Here is a simple example of how to use LibHashSet in your application:
int main(int argc, char* argv[])
{
size_t offset = 0U;
uint64_t value;
uintptr_t cursor = 0U;
/* create new hash set instance */
hash_set_t *const hash_set = hash_set_create(0U, -1.0);
@ -57,7 +57,7 @@ int main(int argc, char* argv[])
printf("Total number of items: %zu\n", hash_set_size(hash_set));
/* print all items in the set */
while (hash_set_iterate(hash_set, &offset, &value) == 0)
while (hash_set_iterate(hash_set, &cursor, &value) == 0)
{
printf("Item: %016llX\n", value);
}
@ -274,7 +274,7 @@ This function returns one value at a time. It should be called repeatedly, until
```C
errno_t hash_set_iterate(
const hash_set_t *const instance,
size_t *const offset,
uintptr_t *const cursor,
uint64_t *const value
);
```
@ -284,9 +284,11 @@ errno_t hash_set_iterate(
* `instance`
A pointer to the hash set instance to be examined, as returned by the [hash_set_create()](#hash_set_create) function.
* `offset`
A pointer to a variable of type `size_t` where the current position in the set is maintained.
This variable **must** be initialized to *zero* before the *first* invocation; it is updated on subsequent invocations.
* `cursor`
A pointer to a variable of type `uintptr_t` where the current iterator state (position) is saved.
This variable **must** be initialized to the value `0U`, by the calling application, prior to the the *first* invocation!
Each invocation will update the value of `*cursor`; the value **shall not** be altered by the application.
* `value`
A pointer to a variable of type `uint64_t` where the next value in the set is stored on success.

View File

@ -109,33 +109,39 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>hashset-test</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Static|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>hashset-test</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Shared|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>hashset-test</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>hashset-test</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Static|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>hashset-test</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Shared|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>hashset-test</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -151,6 +157,7 @@
<LargeAddressAware>true</LargeAddressAware>
<MinimumRequiredVersion>5.1</MinimumRequiredVersion>
</Link>
<PostBuildEvent />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Static|Win32'">
<ClCompile>
@ -182,6 +189,7 @@
<DelayLoadDLLs>advapi32.dll</DelayLoadDLLs>
<AdditionalDependencies>delayimp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Shared|Win32'">
<ClCompile>
@ -213,6 +221,13 @@
<DelayLoadDLLs>advapi32.dll</DelayLoadDLLs>
<AdditionalDependencies>delayimp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent />
<PostBuildEvent>
<Command>copy /B /Y /N "$(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\libhashset-1.dll" "$(TargetDir)libhashset-1.dll"</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>cp "$(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\libhashset-1.dll" -&gt; "$(TargetDir)libhashset-1.dll"</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@ -227,6 +242,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<MinimumRequiredVersion>5.2</MinimumRequiredVersion>
</Link>
<PostBuildEvent />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Static|x64'">
<ClCompile>
@ -256,6 +272,7 @@
<DelayLoadDLLs>advapi32.dll</DelayLoadDLLs>
<AdditionalDependencies>delayimp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Shared|x64'">
<ClCompile>
@ -285,6 +302,13 @@
<DelayLoadDLLs>advapi32.dll</DelayLoadDLLs>
<AdditionalDependencies>delayimp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent />
<PostBuildEvent>
<Command>copy /B /Y /N "$(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\libhashset-1.dll" "$(TargetDir)libhashset-1.dll"</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>cp "$(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\libhashset-1.dll" -&gt; "$(TargetDir)libhashset-1.dll"</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -203,8 +203,9 @@ static int test_function_2(hash_set_t *const hash_set)
memset(test, 0, sizeof(test));
for (size_t r = 0U, offset = 0U; r < 64U; ++r, offset = 0U)
for (size_t r = 0U; r < 64U; ++r)
{
uintptr_t cursor = 0U;
for (size_t j = 0U; j < ARRSIZE / 3U; ++j)
{
size_t rnd;
@ -228,7 +229,7 @@ static int test_function_2(hash_set_t *const hash_set)
PRINT_SET_INFO(2);
}
}
while (!hash_set_iterate(hash_set, &offset, &value))
while (!hash_set_iterate(hash_set, &cursor, &value))
{
if (!test[value])
{

View File

@ -38,7 +38,7 @@ HASHSET_API errno_t hash_set_remove(hash_set_t *const instance, const uint64_t v
HASHSET_API errno_t hash_set_clear(hash_set_t *const instance);
HASHSET_API errno_t hash_set_contains(const hash_set_t *const instance, const uint64_t value);
HASHSET_API errno_t hash_set_iterate(const hash_set_t *const instance, size_t *const offset, uint64_t *const value);
HASHSET_API errno_t hash_set_iterate(const hash_set_t *const instance, uintptr_t *const cursor, uint64_t *const value);
HASHSET_API size_t hash_set_size(const hash_set_t *const instance);
HASHSET_API errno_t hash_set_info(const hash_set_t *const instance, size_t *const capacity, size_t *const valid, size_t *const deleted, size_t *const limit);

View File

@ -106,39 +106,39 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1.$(PlatformToolset).$(PlatformTarget).debug</TargetName>
<OutDir>$(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Static|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1.$(PlatformToolset).$(PlatformTarget)</TargetName>
<OutDir>$(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Shared|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1.$(PlatformTarget)</TargetName>
<OutDir>$(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1.$(PlatformToolset).$(PlatformTarget).debug</TargetName>
<OutDir>$(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Static|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1.$(PlatformToolset).$(PlatformTarget)</TargetName>
<OutDir>$(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Shared|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1.$(PlatformTarget)</TargetName>
<OutDir>$(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\</IntDir>
<TargetName>libhashset-1</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>

View File

@ -457,16 +457,16 @@ errno_t hash_set_clear(hash_set_t *const instance)
return 0;
}
errno_t hash_set_iterate(const hash_set_t *const instance, size_t *const offset, uint64_t *const value)
errno_t hash_set_iterate(const hash_set_t *const instance, uintptr_t *const cursor, uint64_t *const value)
{
size_t index;
if ((!instance) || (!offset) || (!instance->data.values))
if ((!instance) || (!cursor) || (*cursor >= SIZE_MAX) || (!instance->data.values))
{
return EINVAL;
}
for (index = *offset; index < instance->data.capacity; ++index)
for (index = (size_t)(*cursor); index < instance->data.capacity; ++index)
{
if (IS_VALID(instance->data, index))
{
@ -474,12 +474,12 @@ errno_t hash_set_iterate(const hash_set_t *const instance, size_t *const offset,
{
*value = instance->data.values[index];
}
*offset = index + 1U;
*cursor = (uintptr_t)(index + 1U);
return 0;
}
}
*offset = SIZE_MAX;
*cursor = (uintptr_t)SIZE_MAX;
return ENOENT;
}

39
make.cmd Normal file
View File

@ -0,0 +1,39 @@
@echo off
setlocal enabledelayedexpansion
cd /d "%~dp0"
if "%MSVC_PATH%"=="" (
set "MSVC_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC"
)
if not exist "%MSVC_PATH%\Auxiliary\Build\vcvarsall.bat" (
echo MSVC not found. Please check your MSVC_PATH and try again^^!
pause
goto:eof
)
for %%p in (x86,x64) do (
call "%MSVC_PATH%\Auxiliary\Build\vcvarsall.bat" %%p
for %%c in (Static,Shared,Debug) do (
echo.
echo ------------------------------------------------------------------------------
echo %%p %%c
echo ------------------------------------------------------------------------------
for %%t in (Clean,Rebuild,Build) do (
MSBuild.exe /property:Configuration=%%c /property:Platform=%%p /target:%%t /verbosity:normal "%CD%\HashSet.sln"
if not "!ERRORLEVEL!"=="0" goto:BuildFailed
)
)
)
echo.
echo Build completed successfully.
echo.
pause
goto:eof
:BuildFailed
echo.
echo Build has failed ^^!^^!^^!
echo.
pause