mirror of
https://gitee.com/Lamdonn/varch.git
synced 2025-12-08 01:36:42 +08:00
83 lines
1.9 KiB
C
83 lines
1.9 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <float.h>
|
|
#include <math.h>
|
|
#if defined(TEST_TARGET_hash)
|
|
#include <varch/command.h>
|
|
#include <varch/hash.h>
|
|
#else
|
|
#include "init.h"
|
|
#include "command.h"
|
|
#include "hash.h"
|
|
#endif
|
|
|
|
static void usage(void)
|
|
{
|
|
printf(
|
|
"Usage: hash [opt] [arg]\n"
|
|
"\n"
|
|
"options:\n"
|
|
" -h Print help\n"
|
|
" -v Print version\n"
|
|
"\n"
|
|
"argument:\n"
|
|
" <read> Test default read function\n"
|
|
" <write> Test default write function\n"
|
|
);
|
|
}
|
|
|
|
static int test(int argc, char *argv[])
|
|
{
|
|
/* reset getopt */
|
|
command_opt_init();
|
|
|
|
while (1)
|
|
{
|
|
int opt = command_getopt(argc, argv, "hv");
|
|
if (opt == -1) break;
|
|
|
|
switch (opt)
|
|
{
|
|
case 'v' :
|
|
printf("hash version %d.%d.%d\r\n", HASH_V_MAJOR, HASH_V_MINOR, HASH_V_PATCH);
|
|
return 0;
|
|
case '?':
|
|
printf("Unknown option `%c`\r\n", command_optopt);
|
|
return -1;
|
|
case 'h' :
|
|
default:
|
|
usage();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
printf("hash_bkdr 0x%X\r\n", hash_bkdr("Hello", 5));
|
|
printf("hash_ap 0x%X\r\n", hash_ap("Hello", 5));
|
|
printf("hash_djb 0x%X\r\n", hash_djb("Hello", 5));
|
|
printf("hash_js 0x%X\r\n", hash_js("Hello", 5));
|
|
printf("hash_rs 0x%X\r\n", hash_rs("Hello", 5));
|
|
printf("hash_sdbm 0x%X\r\n", hash_sdbm("Hello", 5));
|
|
printf("hash_pjw 0x%X\r\n", hash_pjw("Hello", 5));
|
|
printf("hash_elf 0x%X\r\n", hash_elf("Hello", 5));
|
|
printf("hash_dek 0x%X\r\n", hash_dek("Hello", 5));
|
|
printf("hash_bp 0x%X\r\n", hash_bp("Hello", 5));
|
|
printf("hash_fnv 0x%X\r\n", hash_fnv("Hello", 5));
|
|
printf("hash_jdk6 0x%X\r\n", hash_jdk6("Hello", 5));
|
|
|
|
return 0;
|
|
}
|
|
|
|
#if defined(TEST_TARGET_hash)
|
|
int main(int argc, char *argv[])
|
|
{
|
|
return test(argc, argv);
|
|
}
|
|
#else
|
|
void test_hash(void)
|
|
{
|
|
command_export("hash", test);
|
|
}
|
|
init_export_app(test_hash);
|
|
#endif
|