From e9cda05a5b197e65eceb2b7711e4ede01744b95c Mon Sep 17 00:00:00 2001 From: Long Nguyen Date: Fri, 8 Mar 2019 21:47:44 +0100 Subject: [PATCH 1/4] Murmurhash --- .gitignore | 2 ++ CMakeLists.txt | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index 52bc176..3a58fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ example.o murmur3.o test.o tests +.idea +/cmake-build-debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f063629 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.13) + +add_library(murmur3 murmur3.c murmur3.h) + +add_executable(example example.c) + +target_link_libraries(example murmur3) + +add_executable(test test.c) + +target_link_libraries(test murmur3) \ No newline at end of file From 7f6de646ddc44e11a77c7a62f3576994a577a4e8 Mon Sep 17 00:00:00 2001 From: Long Nguyen Date: Fri, 8 Mar 2019 21:51:08 +0100 Subject: [PATCH 2/4] test is preversed --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f063629..b366978 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,6 @@ add_executable(example example.c) target_link_libraries(example murmur3) -add_executable(test test.c) +add_executable(unit_test test.c) -target_link_libraries(test murmur3) \ No newline at end of file +target_link_libraries(unit_test murmur3) \ No newline at end of file From e13ade816df909f14278a69d044c812400bd15b8 Mon Sep 17 00:00:00 2001 From: Long Nguyen Date: Fri, 8 Mar 2019 22:03:46 +0100 Subject: [PATCH 3/4] change binary directory --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b366978..6b2d970 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.13) +set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}) + add_library(murmur3 murmur3.c murmur3.h) add_executable(example example.c) From 40a8be5c41aee52d31bdbcb625d5bacb40bdacba Mon Sep 17 00:00:00 2001 From: Long Nguyen Date: Fri, 8 Mar 2019 22:11:57 +0100 Subject: [PATCH 4/4] Added cmake_build --- .gitignore | 1 + CMakeLists.txt | 4 +++- example.c | 56 ++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 3a58fd0..7a38332 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ murmur3.o test.o tests .idea +bin /cmake-build-debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b2d970..83040df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,9 @@ cmake_minimum_required(VERSION 3.13) +enable_language(C) + set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) -set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}) +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) add_library(murmur3 murmur3.c murmur3.h) diff --git a/example.c b/example.c index 8c9c9fe..4831f27 100644 --- a/example.c +++ b/example.c @@ -1,7 +1,6 @@ /* Murmur3 example: hash the first command line argument. */ #include -#include #include #include #include "murmur3.h" @@ -10,23 +9,50 @@ int main(int argc, char **argv) { uint32_t hash[4]; /* Output for the hash */ uint32_t seed = 42; /* Seed value for hash */ - if (argc != 2) { - printf("usage: %s \"string to hash\"\n", argv[0]); - exit(1); + /* + * Use custom input + */ + if (argc == 2) { + printf("\nInput: \"%s\"\n\n", argv[1]); + + MurmurHash3_x86_32(argv[1], strlen(argv[1]), seed, hash); + printf("x86_32 hex: %08x\n", hash[0]); + printf("x86_32 dec: %d\n\n", hash[0]); + + MurmurHash3_x86_128(argv[1], strlen(argv[1]), seed, hash); + printf("x86_128 hex: %08x %08x %08x %08x\n", + hash[0], hash[1], hash[2], hash[3]); + printf("x86_128 dec: %d %d %d %d\n\n", + hash[0], hash[1], hash[2], hash[3]); + + MurmurHash3_x64_128(argv[1], strlen(argv[1]), seed, hash); + printf("x64_128 hex: %08x %08x %08x %08x\n", hash[0], hash[1], hash[2], hash[3]); + printf("x64_128 dec: %d %d %d %d\n\n", hash[0], hash[1], hash[2], hash[3]); + + return 0; } + /* + * Use hello world example + */ + else { + char *input = "Hello world"; + + printf("\nInput: \"%s\"\n\n", input); - printf("Input: \"%s\"\n", argv[1]); - - MurmurHash3_x86_32(argv[1], strlen(argv[1]), seed, hash); - printf("x86_32: %08x\n", hash[0]); + MurmurHash3_x86_32(input, strlen(input), seed, hash); + printf("x86_32 hex: %08x\n", hash[0]); + printf("x86_32 dec: %d\n\n", hash[0]); - MurmurHash3_x86_128(argv[1], strlen(argv[1]), seed, hash); - printf("x86_128: %08x %08x %08x %08x\n", - hash[0], hash[1], hash[2], hash[3]); + MurmurHash3_x86_128(input, strlen(input), seed, hash); + printf("x86_128 hex: %08x %08x %08x %08x\n", + hash[0], hash[1], hash[2], hash[3]); + printf("x86_128 dec: %d %d %d %d\n\n", + hash[0], hash[1], hash[2], hash[3]); - MurmurHash3_x64_128(argv[1], strlen(argv[1]), seed, hash); - printf("x64_128: %08x %08x %08x %08x\n", - hash[0], hash[1], hash[2], hash[3]); + MurmurHash3_x64_128(input, strlen(input), seed, hash); + printf("x64_128 hex: %08x %08x %08x %08x\n", hash[0], hash[1], hash[2], hash[3]); + printf("x64_128 dec: %d %d %d %d\n\n", hash[0], hash[1], hash[2], hash[3]); - return 0; + return 0; + } }