/[LeafOK_CVS]/lbbs/include/hash_dict.h
ViewVC logotype

Contents of /lbbs/include/hash_dict.h

Parent Directory Parent Directory | Revision Log Revision Log


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

1 /* SPDX-License-Identifier: GPL-3.0-or-later */
2 /*
3 * hash_dict
4 * - hash-map based dict feature
5 *
6 * Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com>
7 */
8
9 #ifndef _HASH_DICT_H_
10 #define _HASH_DICT_H_
11
12 #include "memory_pool.h"
13 #include <stdint.h>
14
15 enum hash_dict_constant_t
16 {
17 HASH_DICT_BUCKET_SIZE = 65536,
18 HASH_DICT_BUCKET_MAX_COUNT = 1024,
19 };
20
21 struct hash_item_t
22 {
23 uint64_t key;
24 int64_t value;
25 struct hash_item_t *p_next;
26 };
27 typedef struct hash_item_t HASH_ITEM;
28
29 struct hash_dict_t
30 {
31 HASH_ITEM **buckets[HASH_DICT_BUCKET_MAX_COUNT];
32 unsigned int bucket_count;
33 unsigned int prime_index;
34 MEMORY_POOL *p_item_pool;
35 unsigned int item_count;
36 };
37 typedef struct hash_dict_t HASH_DICT;
38
39 extern HASH_DICT *hash_dict_create(int item_count_limit);
40 extern void hash_dict_destroy(HASH_DICT *p_dict);
41
42 extern int hash_dict_set(HASH_DICT *p_dict, uint64_t key, int64_t value);
43 extern int hash_dict_get(HASH_DICT *p_dict, uint64_t key, int64_t *p_value);
44 extern int hash_dict_del(HASH_DICT *p_dict, uint64_t key);
45
46 inline unsigned int hash_dict_item_count(HASH_DICT *p_dict)
47 {
48 if (p_dict == NULL)
49 {
50 return 0;
51 }
52 return p_dict->item_count;
53 }
54
55 #endif //_HASH_DICT_H_

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