我正在研究开源散列函数,以观察源代码和散列算法如何处理散列冲突。我目前对低位散列函数很感兴趣,我通过这个 other 发现了 FNV帖子了解了 FNV
但是,有谁知道我如何实际测试这个特定的源代码?我曾尝试编译一些 C 文件,但我不断收到来自 gcc 的错误:
hb2@hb1:~/Desktop/fnv$ gcc test_fnv.c
test_fnv.c: In function ‘unknown_hash_type’:
test_fnv.c:2183:5: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
test_fnv.c: In function ‘print_fnv32’:
test_fnv.c:2200:2: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘Fnv32_t’ [-Wformat]
test_fnv.c:2202:2: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘Fnv32_t’ [-Wformat]
test_fnv.c: In function ‘print_fnv64’:
test_fnv.c:2221:2: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘Fnv64_t’ [-Wformat]
test_fnv.c:2223:2: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘Fnv64_t’ [-Wformat]
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
hb2@hb1:~/Desktop/fnv$
关于我必须专门编译哪些文件才能运行和测试程序的任何想法?
提前感谢您的帮助
运行 make check 后,我得到以下信息:
hb2@hb1:~/Desktop/fnv$ make check
forming longlong.h
longlong.h formed
cc -O3 -g3 fnv32.c -c
fnv32.c: In function ‘test_fnv32’:
fnv32.c:156:11: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘Fnv32_t’ [-Wformat]
fnv32.c:169:8: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘Fnv32_t’ [-Wformat]
fnv32.c:169:8: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘Fnv32_t’ [-Wformat]
fnv32.c:183:8: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘Fnv32_t’ [-Wformat]
fnv32.c:183:8: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘Fnv32_t’ [-Wformat]
fnv32.c:197:8: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘Fnv32_t’ [-Wformat]
fnv32.c:197:8: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘Fnv32_t’ [-Wformat]
cc -O3 -g3 hash_32.c -c
cc -O3 -g3 hash_64.c -c
cc -O3 -g3 hash_32a.c -c
cc -O3 -g3 hash_64a.c -c
cc -O3 -g3 test_fnv.c -c
test_fnv.c: In function ‘unknown_hash_type’:
test_fnv.c:2183:5: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
test_fnv.c: In function ‘print_fnv32’:
test_fnv.c:2200:2: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘Fnv32_t’ [-Wformat]
test_fnv.c:2202:2: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘Fnv32_t’ [-Wformat]
test_fnv.c: In function ‘print_fnv64’:
test_fnv.c:2221:2: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘Fnv64_t’ [-Wformat]
test_fnv.c:2223:2: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘Fnv64_t’ [-Wformat]
rm -f libfnv.a
ar rv libfnv.a hash_32.o hash_64.o hash_32a.o hash_64a.o test_fnv.o
ar: creating libfnv.a
a - hash_32.o
a - hash_64.o
a - hash_32a.o
a - hash_64a.o
a - test_fnv.o
: libfnv.a
cc fnv32.o libfnv.a -o fnv032
cc -O3 -g3 fnv64.c -c
fnv64.c: In function ‘test_fnv64’:
fnv64.c:160:10: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘Fnv64_t’ [-Wformat]
fnv64.c:175:8: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘Fnv64_t’ [-Wformat]
fnv64.c:175:8: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 5 has type ‘Fnv64_t’ [-Wformat]
fnv64.c:190:8: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘Fnv64_t’ [-Wformat]
fnv64.c:190:8: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 5 has type ‘Fnv64_t’ [-Wformat]
fnv64.c:205:8: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘Fnv64_t’ [-Wformat]
fnv64.c:205:8: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 5 has type ‘Fnv64_t’ [-Wformat]
cc fnv64.o libfnv.a -o fnv064
rm -f fnv132
cp -f fnv032 fnv132
rm -f fnv164
cp -f fnv064 fnv164
rm -f fnv1a32
cp -f fnv032 fnv1a32
rm -f fnv1a64
cp -f fnv064 fnv1a64
FNV-0 32 bit tests: passed
FNV-1 32 bit tests: passed
FNV-1a 32 bit tests: passed
FNV-0 64 bit tests: passed
FNV-1 64 bit tests: passed
FNV-1a 64 bit tests: passed
hb2@hb1:~/Desktop/fnv$
也许这就是我应该得到的,我会更彻底地阅读 FNV 以了解如何实际运行测试,但我第一次没有看到