diff --git a/README.md b/README.md index c1fea62..dd835dd 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/hashset/hashset.vcxproj b/hashset/hashset.vcxproj index 8d9f7a2..112b214 100644 --- a/hashset/hashset.vcxproj +++ b/hashset/hashset.vcxproj @@ -109,33 +109,39 @@ true - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + hashset-test false - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + hashset-test false - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + hashset-test true - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + hashset-test false - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + hashset-test false - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + hashset-test @@ -151,6 +157,7 @@ true 5.1 + @@ -182,6 +189,7 @@ advapi32.dll delayimp.lib;%(AdditionalDependencies) + @@ -213,6 +221,13 @@ advapi32.dll delayimp.lib;%(AdditionalDependencies) + + + copy /B /Y /N "$(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\libhashset-1.dll" "$(TargetDir)libhashset-1.dll" + + + cp "$(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\libhashset-1.dll" -> "$(TargetDir)libhashset-1.dll" + @@ -227,6 +242,7 @@ true 5.2 + @@ -256,6 +272,7 @@ advapi32.dll delayimp.lib;%(AdditionalDependencies) + @@ -285,6 +302,13 @@ advapi32.dll delayimp.lib;%(AdditionalDependencies) + + + copy /B /Y /N "$(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\libhashset-1.dll" "$(TargetDir)libhashset-1.dll" + + + cp "$(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\libhashset-1.dll" -> "$(TargetDir)libhashset-1.dll" + diff --git a/hashset/src/main.c b/hashset/src/main.c index b3cb124..8a28bf8 100644 --- a/hashset/src/main.c +++ b/hashset/src/main.c @@ -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]) { diff --git a/libhashset/include/hash_set.h b/libhashset/include/hash_set.h index e5e8e8e..455c510 100644 --- a/libhashset/include/hash_set.h +++ b/libhashset/include/hash_set.h @@ -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); diff --git a/libhashset/libhashset.vcxproj b/libhashset/libhashset.vcxproj index f5999b7..5ce52fa 100644 --- a/libhashset/libhashset.vcxproj +++ b/libhashset/libhashset.vcxproj @@ -106,39 +106,39 @@ true - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ - libhashset-1.$(PlatformToolset).$(PlatformTarget).debug + $(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + libhashset-1 false - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ - libhashset-1.$(PlatformToolset).$(PlatformTarget) + $(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + libhashset-1 false - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ - libhashset-1.$(PlatformTarget) + $(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + libhashset-1 true - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ - libhashset-1.$(PlatformToolset).$(PlatformTarget).debug + $(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + libhashset-1 false - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ - libhashset-1.$(PlatformToolset).$(PlatformTarget) + $(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + libhashset-1 false - $(SolutionDir)\bin\$(Platform)\$(Configuration)\ - $(ProjectDir)\obj\$(Platform)\$(Configuration)\ - libhashset-1.$(PlatformTarget) + $(SolutionDir)\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + libhashset-1 diff --git a/libhashset/src/hash_set.c b/libhashset/src/hash_set.c index d85b2a5..2cb025c 100644 --- a/libhashset/src/hash_set.c +++ b/libhashset/src/hash_set.c @@ -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; } diff --git a/make.cmd b/make.cmd new file mode 100644 index 0000000..8e713b3 --- /dev/null +++ b/make.cmd @@ -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