#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <amxc/amxc_hash.h>
#include "test_amxc_hash_func.h"
#include <amxc/amxc_macros.h>
Go to the source code of this file.
◆ amxc_hash_BKDR_hashes_check()
void amxc_hash_BKDR_hashes_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 333 of file test_amxc_hash_func.c.
unsigned int amxc_BKDR_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
◆ amxc_hash_distibution_AP_check()
void amxc_hash_distibution_AP_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 316 of file test_amxc_hash_func.c.
318 printf(
"AP hash algorithm\n");
320 for(
int i = 0; i < 2006; i++) {
326 printf(
"First double insertion = %d\n", i);
unsigned int amxc_AP_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
static int amxc_hash_distribution_teardown()
static int amxc_hash_distribution_setup()
static unsigned int array[2006]
static void generate_string(char *str, size_t length)
◆ amxc_hash_distibution_BKDR_check()
void amxc_hash_distibution_BKDR_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 214 of file test_amxc_hash_func.c.
216 printf(
"BKDR hash algorithm\n");
218 for(
int i = 0; i < 2006; i++) {
224 printf(
"First double insertion = %d\n", i);
◆ amxc_hash_distibution_BP_check()
void amxc_hash_distibution_BP_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 282 of file test_amxc_hash_func.c.
284 printf(
"BP hash algorithm\n");
286 for(
int i = 0; i < 2006; i++) {
292 printf(
"First double insertion = %d\n", i);
unsigned int amxc_BP_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
◆ amxc_hash_distibution_DEK_check()
void amxc_hash_distibution_DEK_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 265 of file test_amxc_hash_func.c.
267 printf(
"DEK hash algorithm\n");
269 for(
int i = 0; i < 2006; i++) {
275 printf(
"First double insertion = %d\n", i);
unsigned int amxc_DEK_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
◆ amxc_hash_distibution_DJB_check()
void amxc_hash_distibution_DJB_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 248 of file test_amxc_hash_func.c.
250 printf(
"DJB hash algorithm\n");
252 for(
int i = 0; i < 2006; i++) {
258 printf(
"First double insertion = %d\n", i);
unsigned int amxc_DJB_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
◆ amxc_hash_distibution_ELF_check()
void amxc_hash_distibution_ELF_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 197 of file test_amxc_hash_func.c.
199 printf(
"ELF hash algorithm\n");
201 for(
int i = 0; i < 2006; i++) {
207 printf(
"First double insertion = %d\n", i);
unsigned int amxc_ELF_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
◆ amxc_hash_distibution_FNV_check()
void amxc_hash_distibution_FNV_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 299 of file test_amxc_hash_func.c.
301 printf(
"FNV hash algorithm\n");
303 for(
int i = 0; i < 2006; i++) {
309 printf(
"First double insertion = %d\n", i);
unsigned int amxc_FNV_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
◆ amxc_hash_distibution_JS_check()
void amxc_hash_distibution_JS_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 163 of file test_amxc_hash_func.c.
165 printf(
"JS hash algorithm\n");
167 for(
int i = 0; i < 2006; i++) {
173 printf(
"First double insertion = %d\n", i);
unsigned int amxc_JS_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
◆ amxc_hash_distibution_PJW_check()
void amxc_hash_distibution_PJW_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 180 of file test_amxc_hash_func.c.
182 printf(
"PJW hash algorithm\n");
184 for(
int i = 0; i < 2006; i++) {
190 printf(
"First double insertion = %d\n", i);
unsigned int amxc_PJW_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
◆ amxc_hash_distibution_RS_check()
void amxc_hash_distibution_RS_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 146 of file test_amxc_hash_func.c.
148 printf(
"RS hash algorithm\n");
150 for(
int i = 0; i < 2006; i++) {
156 printf(
"First double insertion = %d\n", i);
unsigned int amxc_RS_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
◆ amxc_hash_distibution_SBDM_check()
void amxc_hash_distibution_SBDM_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 231 of file test_amxc_hash_func.c.
233 printf(
"SBDM hash algorithm\n");
235 for(
int i = 0; i < 2006; i++) {
241 printf(
"First double insertion = %d\n", i);
unsigned int amxc_SDBM_hash(const char *str, const unsigned int len)
Calculate a hash from a string.
◆ amxc_hash_distribution_setup()
static int amxc_hash_distribution_setup |
( |
| ) |
|
|
static |
◆ amxc_hash_distribution_teardown()
static int amxc_hash_distribution_teardown |
( |
| ) |
|
|
static |
Definition at line 114 of file test_amxc_hash_func.c.
115 unsigned int empty_buckets = 0;
116 unsigned int unique_buckets = 0;
117 unsigned int max_chain_length = 0;
118 unsigned int number_of_chains = 0;
119 unsigned int total_chain_lengths = 0;
120 for(
int i = 0; i < 2006; i++) {
124 if(
array[i] > max_chain_length) {
125 max_chain_length =
array[i];
129 total_chain_lengths +=
array[i];
135 printf(
"Nr. of empty buckets = %d\n", empty_buckets);
136 printf(
"Nr. of chained buckets = %d\n", number_of_chains);
137 printf(
"Nr. of uinque buckets = %d\n", unique_buckets);
138 printf(
"Total buckets = %d\n", empty_buckets + number_of_chains + unique_buckets);
139 printf(
"max chain length = %d\n", max_chain_length);
140 printf(
"average chain length = %f\n", (
double) (total_chain_lengths / number_of_chains));
141 printf(
"===========================================\n");
◆ amxc_hash_generation_check()
void amxc_hash_generation_check |
( |
UNUSED void ** |
state | ) |
|
Definition at line 73 of file test_amxc_hash_func.c.
74 char* key[] = {
"abcdefghijklmnopqrstuvwxyz1234567890",
75 "0987654321zyxwvutsrqponmlkjihgfedcba",
81 "abcdefghijklmnopqrstuvwxyz",
86 for(
int i = 0; key[i]; i++) {
87 printf(
"Key: %s\n", key[i]);
88 printf(
" 1. RS-Hash Function Value: %u\n",
amxc_RS_hash(key[i], strlen(key[i])));
89 printf(
" 2. JS-Hash Function Value: %u\n",
amxc_JS_hash(key[i], strlen(key[i])));
90 printf(
" 3. PJW-Hash Function Value: %u\n",
amxc_PJW_hash(key[i], strlen(key[i])));
91 printf(
" 4. ELF-Hash Function Value: %u\n",
amxc_ELF_hash(key[i], strlen(key[i])));
92 printf(
" 5. BKDR-Hash Function Value: %u\n",
amxc_BKDR_hash(key[i], strlen(key[i])));
93 printf(
" 6. SDBM-Hash Function Value: %u\n",
amxc_SDBM_hash(key[i], strlen(key[i])));
94 printf(
" 7. DJB-Hash Function Value: %u\n",
amxc_DJB_hash(key[i], strlen(key[i])));
95 printf(
" 8. DEK-Hash Function Value: %u\n",
amxc_DEK_hash(key[i], strlen(key[i])));
96 printf(
" 9. BP-Hash Function Value: %u\n",
amxc_BP_hash(key[i], strlen(key[i])));
97 printf(
"10. FNV-Hash Function Value: %u\n",
amxc_FNV_hash(key[i], strlen(key[i])));
98 printf(
"11. AP-Hash Function Value: %u\n",
amxc_AP_hash(key[i], strlen(key[i])));
◆ generate_string()
static void generate_string |
( |
char * |
str, |
|
|
size_t |
length |
|
) |
| |
|
static |
Definition at line 65 of file test_amxc_hash_func.c.
66 const char* base =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
67 size_t len = strlen(base);
68 for(
unsigned int i = 0; i < length; i++) {
69 str[i] = base[rand() % len];
◆ array
◆ first_double
bool first_double = false |
|
static |