-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hash.c
92 lines (69 loc) · 1.67 KB
/
test_hash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
$Id$
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "nhash.h"
#define TEST_HASH 0
void hash_map_func(const char *key, void *data)
{
char *k = (char *) key;
char *d = (char *) data;
printf("'%s' = '%s'\n", k, d);
}
void test_hash(void)
{
int i, nn = 400000;
tn_hash *h;
if ((h = n_hash_new(1000000, NULL)) == NULL)
exit(1);
//n_hash_ctl(h, TN_HASH_REHASH);
for (i = 0; i < nn; i++) {
char str[40];
sprintf(str, "key%d", i);
if (i % 10000 == 0)
printf("%s\n", str);
n_hash_insert(h, str, "ma kota i psa");
if (!n_hash_exists(h, str))
printf("ERROR %s not exists\n", str);
}
for (i = 0; i < nn; i++) {
char str[40];
sprintf(str, "key%d", i);
if (i % 10000 == 0)
printf("get %s\n", str);
if (!n_hash_exists(h, str))
printf("ERROR %s not exists\n", str);
}
n_hash_stats(h);
n_hash_free(h);
}
void test_hash_rpmqal(void)
{
tn_hash *h;
char buf[1024];
FILE *f;
if ((h = n_hash_new(300000, NULL)) == NULL)
exit(1);
//n_hash_ctl(h, TN_HASH_REHASH);
f = popen("rpm -qal | sort -u", "r");
while (fgets(buf, sizeof(buf), f)) {
buf[sizeof(buf) - 1] = '\0';
n_hash_insert(h, buf, "ma kota i psa");
if (!n_hash_exists(h, buf))
printf("ERROR %s not exists\n", buf);
}
pclose(f);
// sleep(5);
// n_hash_map(h, hash_map_func);
n_hash_stats(h);
n_hash_free(h);
}
int main()
{
test_hash_rpmqal();
test_hash();
return 0;
}