/[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.4 - (hide annotations)
Sat Jan 3 10:27:14 2026 UTC (2 months, 1 week ago) by sysadm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -1 lines
Content type: text/x-chdr
Update copyright info

1 sysadm 1.1 /* SPDX-License-Identifier: GPL-3.0-or-later */
2     /*
3     * hash_dict
4     * - hash-map based dict feature
5     *
6 sysadm 1.4 * Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com>
7 sysadm 1.1 */
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 sysadm 1.3 // Return 1 if existing key updated, 0 if new key added, -1 on error
43 sysadm 1.1 extern int hash_dict_set(HASH_DICT *p_dict, uint64_t key, int64_t value);
44 sysadm 1.3
45     // Return 1 if existing key updated, 0 if key not exist, -1 on error
46 sysadm 1.2 extern int hash_dict_inc(HASH_DICT *p_dict, uint64_t key, int64_t value_inc);
47 sysadm 1.3
48     // Return 1 if key found, 0 if key not exist, -1 on error
49 sysadm 1.1 extern int hash_dict_get(HASH_DICT *p_dict, uint64_t key, int64_t *p_value);
50 sysadm 1.3
51     // Return 1 if key deleted, 0 if key not exist, -1 on error
52 sysadm 1.1 extern int hash_dict_del(HASH_DICT *p_dict, uint64_t key);
53    
54     inline unsigned int hash_dict_item_count(HASH_DICT *p_dict)
55     {
56     if (p_dict == NULL)
57     {
58     return 0;
59     }
60     return p_dict->item_count;
61     }
62    
63     #endif //_HASH_DICT_H_

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