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

Annotation of /lbbs/include/hash_dict.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Sun Nov 16 04:22:30 2025 UTC (4 months ago) by sysadm
Branch: MAIN
Changes since 1.1: +1 -0 lines
Content type: text/x-chdr
Add hash_dict_inc()

1 sysadm 1.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 sysadm 1.2 extern int hash_dict_inc(HASH_DICT *p_dict, uint64_t key, int64_t value_inc);
44 sysadm 1.1 extern int hash_dict_get(HASH_DICT *p_dict, uint64_t key, int64_t *p_value);
45     extern int hash_dict_del(HASH_DICT *p_dict, uint64_t key);
46    
47     inline unsigned int hash_dict_item_count(HASH_DICT *p_dict)
48     {
49     if (p_dict == NULL)
50     {
51     return 0;
52     }
53     return p_dict->item_count;
54     }
55    
56     #endif //_HASH_DICT_H_

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