mGNCS API Reference  v1.5.0
A new control set and a new framework for MiniGUI apps
hashtable.h
Go to the documentation of this file.
1 //
3 // IMPORTANT NOTICE
4 //
5 // The following open source license statement does not apply to any
6 // entity in the Exception List published by FMSoft.
7 //
8 // For more information, please visit:
9 //
10 // https://www.fmsoft.cn/exception-list
11 //
13 
53 #ifndef HASHTABLE_H
54 #define HASHTABLE_H
55 
56 //typedef unsigned int ht_key_t;
57 
58 #define INVALID_KEY 0u
59 
60 #define HTE_OK 0
61 #define HTE_EXIST 1
62 #define HTE_NOTEXIST 2
63 #define HTE_INVALID_KEY 3
64 
65 typedef unsigned long ht_key_t;
66 
67 typedef struct _HashEntry{
68  ht_key_t key;
69  void *data;
70  struct _HashEntry *next;
71 }HashEntry;
72 
73 typedef void (*freeObj)(void* obj);
74 typedef struct _HashTable{
75  int count;
76  HashEntry ** entries;
77  freeObj free_obj;
78 }HashTable;
79 
80 MGNCS_EXPORT int hash_insert(HashTable* ht,ht_key_t key, void *data);
81 
82 MGNCS_EXPORT int hash_delete(HashTable* ht,ht_key_t key);
83 
84 MGNCS_EXPORT void * hash_get(HashTable* ht,ht_key_t key);
85 
86 MGNCS_EXPORT HashTable * hash_new(int count, freeObj func);
87 
88 MGNCS_EXPORT void hash_free(HashTable *ht);
89 
90 #define HT_FOR_EACH_CONTINUE 0
91 #define HT_FOR_EACH_DELETE 0x1
92 #define HT_FOR_EACH_BREAK 0x02
93 typedef int(*eachObj)(void*, void*);
94 MGNCS_EXPORT void hash_for_each(HashTable *ht, eachObj each, void* user);
95 
96 #endif
97