Update to version p5.9.20211031.0 of ctags
[geany-mirror.git] / ctags / main / htable.h
blob7e148743850047f6a988e052d30ed3bcd50c61a4
1 /*
3 * Copyright (c) 2014, Red Hat, Inc.
4 * Copyright (c) 2014, Masatake YAMATO
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License version 2 or (at your option) any later version.
9 * Defines hashtable
11 #ifndef CTAGS_MAIN_HTABLE_H
12 #define CTAGS_MAIN_HTABLE_H
14 #include "general.h"
15 #include <stdint.h>
17 /* This hashtable allows adding multiple items for the same key.
19 * hashTablePutItem() adds a key/item pair to the htable even if the
20 * htable has an item for the key already.
22 * hashTableGetItem() returns the first occurrence item for the given
23 * key.
25 * hashTableDeleteItem() deletes the first occurrence item for the given
26 * key.
28 * Use hashTableForeachItemOnChain () to process all items for the same key.
30 typedef struct sHashTable hashTable;
31 typedef unsigned int (* hashTableHashFunc) (const void * const key);
32 typedef bool (* hashTableEqualFunc) (const void* a, const void* b);
33 typedef void (* hashTableDeleteFunc) (void * ptr);
35 /* To continue interation, return true.
36 * To break interation, return false. */
37 typedef bool (* hashTableForeachFunc) (const void *key, void *value, void *user_data);
39 unsigned int hashPtrhash (const void * x);
40 bool hashPtreq (const void * a, const void * constb);
42 unsigned int hashCstrhash (const void * x);
43 bool hashCstreq (const void * a, const void * b);
45 unsigned int hashCstrcasehash (const void * x);
46 bool hashCstrcaseeq (const void * a, const void * b);
48 unsigned int hashInthash (const void * x);
49 bool hashInteq (const void * a, const void * b);
51 extern hashTable* hashTableNew (unsigned int size,
52 hashTableHashFunc hashfn,
53 hashTableEqualFunc equalfn,
54 hashTableDeleteFunc keyfreefn,
55 hashTableDeleteFunc valfreefn);
57 /* By default, hashTableGetItem() returns NULL for a unknown key.
58 * It means you cannot store NULL as a value for a key.
59 * With hashTableSetValueForUnknownKey(), you can specific
60 * an alternative address representing the value for for unknown
61 * keys.
63 extern void hashTableSetValueForUnknownKey (hashTable *htable,
64 void *val,
65 hashTableDeleteFunc valfreefn);
67 extern void hashTableDelete (hashTable *htable);
68 extern void hashTableClear (hashTable *htable);
69 extern void hashTablePutItem (hashTable *htable, void *key, void *value);
70 extern void* hashTableGetItem (hashTable *htable, const void * key);
71 extern bool hashTableHasItem (hashTable * htable, const void * key);
72 extern bool hashTableDeleteItem (hashTable *htable, const void *key);
73 extern bool hashTableUpdateItem (hashTable *htable, void *key, void *value);
75 /* Return true if proc never returns false; proc returns true for all
76 * the items, or htable holds no item.
78 * Return false if htable holds at least one item and proc returns false
79 * for one of the items. */
80 extern bool hashTableForeachItem (hashTable *htable, hashTableForeachFunc proc, void *user_data);
82 /* This function is useful for htable having multiple items for a key.
83 * By giving a key, you can traverse all the items associated with the
84 * key via proc. * "Chain" means group of items associated with a
85 * key. */
86 extern bool hashTableForeachItemOnChain (hashTable *htable, const void *key, hashTableForeachFunc proc, void *user_data);
88 extern unsigned int hashTableCountItem (hashTable *htable);
90 #define HT_PTR_TO_INT(P) ((int)(intptr_t)(P))
91 #define HT_INT_TO_PTR(P) ((void*)(intptr_t)(P))
92 #define HT_PTR_TO_UINT(P) ((unsigned int)(uintptr_t)(P))
93 #define HT_UINT_TO_PTR(P) ((void*)(uintptr_t)(P))
95 #endif /* CTAGS_MAIN_HTABLE_H */