/[LeafOK_CVS]/lbbs/src/test_hash_dict.c
ViewVC logotype

Annotation of /lbbs/src/test_hash_dict.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Nov 14 06:38:54 2025 UTC (4 months ago) by sysadm
Branch: MAIN
Content type: text/x-csrc
Add hash_dict

1 sysadm 1.1 /* SPDX-License-Identifier: GPL-3.0-or-later */
2     /*
3     * test_hash_dict
4     * - tester for hash dict
5     *
6     * Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com>
7     */
8    
9     #ifdef HAVE_CONFIG_H
10     #include "config.h"
11     #endif
12    
13     #include "hash_dict.h"
14     #include "log.h"
15     #include <errno.h>
16     #include <stdio.h>
17     #include <unistd.h>
18    
19     int main(int argc, char *argv[])
20     {
21     HASH_DICT *p_dict;
22     uint64_t key;
23     int64_t value;
24     unsigned int i;
25     int ret;
26     const int dict_item_count = 10000 * 10000;
27    
28     if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
29     {
30     printf("Open log error\n");
31     return -1;
32     }
33    
34     log_common_redir(STDOUT_FILENO);
35     log_error_redir(STDERR_FILENO);
36    
37     p_dict = hash_dict_create(dict_item_count);
38     if (p_dict == NULL)
39     {
40     printf("hash_dict_create() error\n");
41     return -2;
42     }
43    
44     for (i = 0; i < dict_item_count; i++)
45     {
46     key = i * 37 + 13;
47     ret = hash_dict_get(p_dict, key, &value);
48     if (ret != 0)
49     {
50     printf("hash_dict_get(%lu) ret=%d error\n", key, ret);
51     break;
52     }
53     }
54    
55     for (i = 0; i < dict_item_count; i++)
56     {
57     key = i * 37 + 13;
58     if (hash_dict_set(p_dict, key, i * 3 + 7) != 0)
59     {
60     printf("hash_dict_set(%lu) error\n", key);
61     break;
62     }
63     }
64    
65     ret = (int)hash_dict_item_count(p_dict);
66     if (ret != dict_item_count)
67     {
68     printf("hash_dict_item_count()=%d error\n", ret);
69     }
70    
71     for (i = 0; i < dict_item_count; i++)
72     {
73     key = i * 37 + 13;
74     ret = hash_dict_get(p_dict, key, &value);
75     if (ret != 1)
76     {
77     printf("hash_dict_get(%lu) ret=%d error\n", key, ret);
78     break;
79     }
80     if (value != i * 3 + 7)
81     {
82     printf("hash_dict_get(%lu) value=%ld error\n", key, value);
83     break;
84     }
85     }
86    
87     for (i = 0; i < dict_item_count; i++)
88     {
89     key = i * 37 + 13;
90     if (hash_dict_set(p_dict, key, i * 3 + 7) != 0)
91     {
92     printf("hash_dict_set(%lu) error\n", key);
93     break;
94     }
95     }
96    
97     for (i = 0; i < dict_item_count; i++)
98     {
99     key = i * 37 + 13;
100     ret = hash_dict_get(p_dict, key, &value);
101     if (ret != 1)
102     {
103     printf("hash_dict_get(%lu) ret=%d error\n", key, ret);
104     break;
105     }
106     if (value != i * 3 + 7)
107     {
108     printf("hash_dict_get(%lu) value=%ld error\n", key, value);
109     break;
110     }
111     }
112    
113     ret = (int)hash_dict_item_count(p_dict);
114     if (ret != dict_item_count)
115     {
116     printf("hash_dict_item_count()=%d error\n", ret);
117     }
118    
119     for (i = 0; i < dict_item_count; i++)
120     {
121     key = i * 37 + 13;
122     if (hash_dict_del(p_dict, key) != 1)
123     {
124     printf("hash_dict_del(%lu) error\n", key);
125     break;
126     }
127     }
128    
129     ret = (int)hash_dict_item_count(p_dict);
130     if (ret != 0)
131     {
132     printf("hash_dict_item_count()=%d error\n", ret);
133     }
134    
135     for (i = 0; i < dict_item_count; i++)
136     {
137     key = i * 37 + 13;
138     ret = hash_dict_get(p_dict, key, &value);
139     if (ret != 0)
140     {
141     printf("hash_dict_get(%lu) ret=%d error\n", key, ret);
142     break;
143     }
144     }
145    
146     for (i = 0; i < dict_item_count; i++)
147     {
148     key = i * 37 + 13;
149     if (hash_dict_del(p_dict, key) != 0)
150     {
151     printf("hash_dict_del(%lu) error\n", key);
152     break;
153     }
154     }
155    
156     hash_dict_destroy(p_dict);
157    
158     log_end();
159    
160     return 0;
161     }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1