Welcome to mirror list, hosted at ThFree Co, Russian Federation.

uhtbl-test.c « examples - git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d8f2f32436036c59bb4fcce0de39dfc27ac5fd9d (plain)
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
93
94
95
96
97
98
99
#include "../hash.h"
#include "../uhtbl.h"
#include <stdio.h>
#include <string.h>

struct mybucket {
	uhtbl_head_t __head;
	long double mydata;
};

int main() {
	printf("%i\n", (int)sizeof(struct mybucket));

	uhtbl_t tbl;
	uhtbl_init(&tbl, sizeof(struct mybucket), 16, hash_murmur2, NULL);
	struct mybucket *bucket;

	const char *t[] = {"null", "eins", "zwei", "drei", "vier", "fünf", "sechs",
			"sieben", "acht", "neun", "zehn", "elf", "zwölf", "dreizehn",
			"vierzehn", "fünfzehn", "sechzehn", "siebzehn", "achtzehn",
			"neunzehn", "zwanzig", "einundzwanzig", "zweiundzwanzig",
			"dreiundzwanzig", "virundzwanzig", "fünfundzwanzig", "sechsundzwanzig",
			"siebenundzwanzig", "achtundzwanzig", "neunundzwanzig", "dreißig",
			"einunddreißig", "zweiunddreißig"};
	for (int i = 0; i < 33; i++) {
		bucket = (struct mybucket*)uhtbl_set(&tbl, t[i], strlen(t[i]));
		bucket->mydata = i;
	}

	uint32_t iter = 0;
	while ((bucket = (struct mybucket*)uhtbl_next(&tbl, &iter))) {
		printf("%i\t", (int)bucket->mydata);
	}
	printf("\nSize: %i, Used: %i\n\n", tbl.size, tbl.used);

	for (int i = 0; i < 33; i++) {
		bucket = (struct mybucket*)uhtbl_set(&tbl, 0, i);
		bucket->mydata = i;
	}

	iter = 0;
	while ((bucket = (struct mybucket*)uhtbl_next(&tbl, &iter))) {
		printf("%i\t", (int)bucket->mydata);
	}
	printf("\nSize: %i, Used: %i\n\n", tbl.size, tbl.used);

	for (int i = 0; i < 33; i++) {
		if (uhtbl_unset(&tbl, 0, i)) {
			printf("Unset failed %i\n", i);
		}
		if (uhtbl_unset(&tbl, t[i], strlen(t[i]))) {
			printf("Unset failed %s\n", t[i]);
		}
	}

	iter = 0;
	while ((bucket = (struct mybucket*)uhtbl_next(&tbl, &iter))) {
		printf("%i\t", (int)bucket->mydata);
	}
	printf("\nSize: %i, Used: %i\n\n", tbl.size, tbl.used);

	for (int i = 0; i < 33; i++) {
		bucket = (struct mybucket*)uhtbl_set(&tbl, t[i], strlen(t[i]));
		bucket->mydata = i;
	}

	for (int i = 0; i < 33; i++) {
		bucket =(struct mybucket*) uhtbl_set(&tbl, 0, i);
		bucket->mydata = i;
	}

	for (int i = 0; i < 33; i++) {
		bucket = (struct mybucket*)uhtbl_set(&tbl, t[i], strlen(t[i]));
		bucket->mydata = i;
	}

	for (int i = 0; i < 33; i++) {
		bucket = (struct mybucket*)uhtbl_set(&tbl, 0, i);
		bucket->mydata = i;
	}

	iter = 0;
	while ((bucket = (struct mybucket*)uhtbl_next(&tbl, &iter))) {
		printf("%i\t", (int)bucket->mydata);
	}
	printf("\nSize: %i, Used: %i\n\n", tbl.size, tbl.used);

	for (int i = 0; i < 33; i++) {
		bucket = (struct mybucket*)uhtbl_get(&tbl, t[i], strlen(t[i]));
		printf("%i\t", (int)bucket->mydata);
		bucket = (struct mybucket*)uhtbl_get(&tbl, 0, i);
		printf("%i\t", (int)bucket->mydata);
	}
	printf("\nSize: %i, Used: %i\n\n", tbl.size, tbl.used);

	uhtbl_finalize(&tbl);

	return 0;
}