Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ example.o
murmur3.o
test.o
tests
.idea
bin
/cmake-build-debug/
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.13)

enable_language(C)

set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})

add_library(murmur3 murmur3.c murmur3.h)

add_executable(example example.c)

target_link_libraries(example murmur3)

add_executable(unit_test test.c)

target_link_libraries(unit_test murmur3)
56 changes: 41 additions & 15 deletions example.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* Murmur3 example: hash the first command line argument. */

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "murmur3.h"
Expand All @@ -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;
}
}