diff --git a/.gitignore b/.gitignore index a5fe045..a8a61ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -/.vs -/*.suo -/*.user +*.suo +*.user /**/bin /**/lib /**/obj +/.vs diff --git a/Makefile b/Makefile index 42b43c8..3aa7dfb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SUBDIRS := libhashset hashset +SUBDIRS := libhashset example test BUILD_ALL := $(patsubst %,build\:%,$(SUBDIRS)) CLEAN_ALL := $(patsubst %,clean\:%,$(SUBDIRS)) diff --git a/README.md b/README.md index e529892..5701aae 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,13 @@ Here is a simple example of how to use LibHashSet in your application: #include #include -int main(int argc, char* argv[]) +int main(void) { uint64_t value; uintptr_t cursor = 0U; /* create new hash set instance */ - hash_set64_t *const hash_set = hash_set_create64(0U, -1.0); + hash_set64_t* const hash_set = hash_set_create64(0U, -1.0); if (!hash_set) { fputs("Allocation has failed!\n", stderr); @@ -31,6 +31,7 @@ int main(int argc, char* argv[]) } /* add a number of items to the hash set, the set will grow as needed */ + puts("Insertign items, please wait..."); while (have_more_items()) { const errno_t error = hash_set_insert64(hash_set, get_next_item()); @@ -40,21 +41,10 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } } - - /* test whether hash set contains a specific item */ - if (hash_set_contains64(hash_set, 42U) == 0) - { - puts("Set contains item!"); - - /* remove the existing item from the hash set */ - if (hash_set_remove64(hash_set, 42U) == 0) - { - puts("Item has been removed!"); - } - } + puts("Done.\n"); /* print total number of items in the hash set*/ - printf("Total number of items: %zu\n", hash_set_size64(hash_set)); + printf("Total number of items: %zu\n\n", hash_set_size64(hash_set)); /* print all items in the set */ while (hash_set_iterate64(hash_set, &cursor, &value) == 0) diff --git a/example/Makefile b/example/Makefile new file mode 100644 index 0000000..bc11336 --- /dev/null +++ b/example/Makefile @@ -0,0 +1,44 @@ +DUMPMACHINE := $(shell $(CC) -dumpmachine) + +ifneq ($(SANITIZE_ADDRESS),1) + XCFLAGS = -Ofast -DNDEBUG -s -static +ifneq ($(firstword $(filter x86_64-%,$(DUMPMACHINE))),) + XCFLAGS += -march=x86-64 -mtune=nocona +else ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),) + XCFLAGS += -march=pentiumpro -mtune=intel +endif +else + XCFLAGS = -fsanitize=address -static-libasan -g +endif + +ifneq ($(firstword $(filter %-mingw32 %-cygwin,$(DUMPMACHINE))),) + EXE_SUFFIX := .exe +ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),) + XCFLAGS += -Wl,--large-address-aware +endif +endif + +CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../libhashset/include $(XCFLAGS) + +SRC_PATH := src +BIN_PATH := bin +ALL_PATH := $(SRC_PATH) $(BIN_PATH) + +BIN_FILE := $(BIN_PATH)/hashset-example$(EXE_SUFFIX) +SRC_FILE := $(SRC_PATH)/main.c +LIB_FILE := ../libhashset/lib/libhashset-1.a + +.PHONY: all build clean + +all: clean build + +build: $(ALL_PATH) $(BIN_FILE) + +$(BIN_FILE): $(SRC_FILE) $(LIB_FILE) + $(CC) $(CFLAGS) -o $@ $^ + +$(ALL_PATH): + mkdir -p $@ + +clean: + rm -f $(BIN_FILE) diff --git a/example/hashset-example.vcxproj b/example/hashset-example.vcxproj new file mode 100644 index 0000000..9a03fa9 --- /dev/null +++ b/example/hashset-example.vcxproj @@ -0,0 +1,438 @@ + + + + + Debug + ARM64 + + + Debug + Win32 + + + Shared + ARM64 + + + Shared + Win32 + + + Shared + x64 + + + Static + ARM64 + + + Static + Win32 + + + Debug + x64 + + + Static + x64 + + + + + + + + {8cf3bd19-28b1-435d-b719-e00b052dfc3a} + + + + 16.0 + Win32Proj + {8FB9B9DE-DC49-4224-892B-589422484766} + hashset-example + 10.0.19041.0 + hashset-example + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + false + v142 + true + Unicode + + + Application + false + v142 + true + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + + + true + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + + + true + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)\obj\$(PlatformToolset)\$(Platform)\$(Configuration)\ + + + + Level3 + false + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)\libhashset\include + + + Console + true + true + 5.1 + + + + + + Level4 + true + true + false + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + AnySuitable + true + MultiThreaded + false + StreamingSIMDExtensions + false + MaxSpeed + Speed + true + $(SolutionDir)\libhashset\include + Fast + + + Console + true + true + false + UseLinkTimeCodeGeneration + 5.1 + true + + + + + + Level4 + true + true + false + WIN32;NDEBUG;_CONSOLE;HASHSET_DLL;%(PreprocessorDefinitions) + true + AnySuitable + true + MultiThreadedDLL + false + StreamingSIMDExtensions + false + MaxSpeed + Speed + true + $(SolutionDir)\libhashset\include + Fast + + + Console + true + true + false + UseLinkTimeCodeGeneration + 5.1 + true + + + + 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" + + + + + Level3 + false + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)\libhashset\include + + + Console + true + 5.2 + + + + + + Level3 + false + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)\libhashset\include + + + Console + true + + + + + + Level4 + true + true + false + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + AnySuitable + true + MultiThreaded + false + false + MaxSpeed + Speed + true + $(SolutionDir)\libhashset\include + Fast + + + Console + true + true + false + UseLinkTimeCodeGeneration + 5.2 + + + + + + Level4 + true + true + false + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + AnySuitable + true + MultiThreaded + false + false + MaxSpeed + Speed + true + $(SolutionDir)\libhashset\include + Fast + + + Console + true + true + false + UseLinkTimeCodeGeneration + + + + + + Level4 + true + true + false + NDEBUG;_CONSOLE;HASHSET_DLL;%(PreprocessorDefinitions) + true + AnySuitable + true + MultiThreadedDLL + false + false + MaxSpeed + Speed + true + $(SolutionDir)\libhashset\include + Fast + + + Console + true + true + false + UseLinkTimeCodeGeneration + 5.2 + + + + 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" + + + + + Level4 + true + true + false + NDEBUG;_CONSOLE;HASHSET_DLL;%(PreprocessorDefinitions) + true + AnySuitable + true + MultiThreadedDLL + false + false + MaxSpeed + Speed + true + $(SolutionDir)\libhashset\include + Fast + + + Console + true + true + false + UseLinkTimeCodeGeneration + + + + 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" + + + + + + \ No newline at end of file diff --git a/example/hashset-example.vcxproj.filters b/example/hashset-example.vcxproj.filters new file mode 100644 index 0000000..0b7f47e --- /dev/null +++ b/example/hashset-example.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/example/src/main.c b/example/src/main.c new file mode 100644 index 0000000..2de1da2 --- /dev/null +++ b/example/src/main.c @@ -0,0 +1,89 @@ +/******************************************************************************/ +/* HashSet for C99, by LoRd_MuldeR */ +/* This work has been released under the CC0 1.0 Universal license! */ +/******************************************************************************/ + +#include +#include +#include + +#define INPUT_COUNT 100U + +/* ========================================================================= */ +/* I/O Functions */ +/* ========================================================================= */ + +static size_t g_offset = 0U; + +static const uint64_t g_input[INPUT_COUNT] = +{ + 0x0005, 0x0007, 0x000B, 0x0017, 0x002F, 0x003B, 0x0053, 0x006B, 0x00A7, 0x00B3, + 0x00E3, 0x0107, 0x015B, 0x0167, 0x017F, 0x01D3, 0x01DF, 0x01F7, 0x0233, 0x024B, + 0x02CF, 0x0347, 0x035F, 0x0377, 0x03D7, 0x03FB, 0x04A3, 0x0503, 0x051B, 0x0527, + 0x0557, 0x059F, 0x05CF, 0x05F3, 0x0653, 0x071F, 0x0773, 0x07EB, 0x07F7, 0x080F, + 0x0833, 0x089F, 0x098F, 0x099B, 0x0A13, 0x0B03, 0x0B3F, 0x0B57, 0x0B93, 0x0BB7, + 0x0BCF, 0x0C2F, 0x0C5F, 0x0C83, 0x0D8B, 0x0E27, 0x0EC3, 0x0EDB, 0x0F17, 0x0F6B, + 0x0FA7, 0x0FEF, 0x101F, 0x102B, 0x10A3, 0x10BB, 0x11C3, 0x1247, 0x125F, 0x12B3, + 0x12BF, 0x1337, 0x13DF, 0x13EB, 0x150B, 0x1517, 0x156B, 0x1583, 0x1607, 0x16AF, + 0x16F7, 0x1727, 0x1733, 0x179F, 0x19C7, 0x1A03, 0x1A3F, 0x1A7B, 0x1AAB, 0x1AF3, + 0x1B47, 0x1BA7, 0x1C13, 0x1C4F, 0x1D63, 0x1D87, 0x1DB7, 0x1DDB, 0x1E17, 0x1E2F +}; + +static int have_more_items(void) +{ + return (g_offset < INPUT_COUNT); +} + +static uint64_t get_next_item(void) +{ + return g_input[g_offset++]; +} + +/* ========================================================================= */ +/* MAIN */ +/* ========================================================================= */ + +int main(void/*int argc, char* argv[]*/) +{ + hash_set64_t *hash_set; + uint64_t value; + uintptr_t cursor = 0U; + + /* print logo */ + printf("LibHashSet Example v%" PRIu16 ".%" PRIu16 ".%" PRIu16 " [%s]\n\n", + HASHSET_VERSION_MAJOR, HASHSET_VERSION_MINOR, HASHSET_VERSION_PATCH, HASHSET_BUILD_DATE); + + /* create new hash set instance */ + hash_set = hash_set_create64(0U, -1.0); + if (!hash_set) + { + fputs("Allocation has failed!\n", stderr); + return EXIT_FAILURE; + } + + /* add a number of items to the hash set, the set will grow as needed */ + puts("Insertign items, please wait..."); + while (have_more_items()) + { + const errno_t error = hash_set_insert64(hash_set, get_next_item()); + if (error) + { + fprintf(stderr, "Insert operation has failed! (error: %d)\n", error); + return EXIT_FAILURE; + } + } + puts("Done.\n"); + + /* print total number of items in the hash set*/ + printf("Total number of items: %zu\n\n", hash_set_size64(hash_set)); + + /* print all items in the set */ + while (hash_set_iterate64(hash_set, &cursor, &value) == 0) + { + printf("Item: %016llX\n", value); + } + + /* destroy the hash set, when it is no longer needed! */ + hash_set_destroy64(hash_set); + return EXIT_SUCCESS; +} diff --git a/hashset.sln b/hashset.sln index 667abb2..72d30b7 100644 --- a/hashset.sln +++ b/hashset.sln @@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hashset-test", "test\hashse EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libhashset", "libhashset\libhashset.vcxproj", "{8CF3BD19-28B1-435D-B719-E00B052DFC3A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hashset-example", "example\hashset-example.vcxproj", "{8FB9B9DE-DC49-4224-892B-589422484766}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -56,6 +58,24 @@ Global {8CF3BD19-28B1-435D-B719-E00B052DFC3A}.Static|x64.Build.0 = Static|x64 {8CF3BD19-28B1-435D-B719-E00B052DFC3A}.Static|x86.ActiveCfg = Static|Win32 {8CF3BD19-28B1-435D-B719-E00B052DFC3A}.Static|x86.Build.0 = Static|Win32 + {8FB9B9DE-DC49-4224-892B-589422484766}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Debug|ARM64.Build.0 = Debug|ARM64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Debug|x64.ActiveCfg = Debug|x64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Debug|x64.Build.0 = Debug|x64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Debug|x86.ActiveCfg = Debug|Win32 + {8FB9B9DE-DC49-4224-892B-589422484766}.Debug|x86.Build.0 = Debug|Win32 + {8FB9B9DE-DC49-4224-892B-589422484766}.Shared|ARM64.ActiveCfg = Shared|ARM64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Shared|ARM64.Build.0 = Shared|ARM64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Shared|x64.ActiveCfg = Shared|x64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Shared|x64.Build.0 = Shared|x64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Shared|x86.ActiveCfg = Shared|Win32 + {8FB9B9DE-DC49-4224-892B-589422484766}.Shared|x86.Build.0 = Shared|Win32 + {8FB9B9DE-DC49-4224-892B-589422484766}.Static|ARM64.ActiveCfg = Static|ARM64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Static|ARM64.Build.0 = Static|ARM64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Static|x64.ActiveCfg = Static|x64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Static|x64.Build.0 = Static|x64 + {8FB9B9DE-DC49-4224-892B-589422484766}.Static|x86.ActiveCfg = Static|Win32 + {8FB9B9DE-DC49-4224-892B-589422484766}.Static|x86.Build.0 = Static|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libhashset/libhashset.vcxproj.user b/libhashset/libhashset.vcxproj.user deleted file mode 100644 index 88a5509..0000000 --- a/libhashset/libhashset.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/test/Makefile b/test/Makefile index db4a5b6..82dc065 100644 --- a/test/Makefile +++ b/test/Makefile @@ -35,7 +35,7 @@ all: clean build build: $(ALL_PATH) $(BIN_FILE) $(BIN_FILE): $(SRC_FILE) $(LIB_FILE) - $(CC) $(CFLAGS) $^ -o $@ + $(CC) $(CFLAGS) -o $@ $^ $(ALL_PATH): mkdir -p $@ diff --git a/test/hashset-test.vcxproj.user b/test/hashset-test.vcxproj.user deleted file mode 100644 index 88a5509..0000000 --- a/test/hashset-test.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file