Add support for the --disable-boehm-gc flag for systems that lack -lgc.
[fw/sdcc] / src / SDCChasht.h
1 /*-----------------------------------------------------------------
2     SDCChast.h - contains support routines for hashtables/sets .
3
4     Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
5
6     This program is free software; you can redistribute it and/or modify it
7     under the terms of the GNU General Public License as published by the
8     Free Software Foundation; either version 2, or (at your option) any
9     later version.
10     
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15     
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     
20     In other words, you are welcome to use, share and improve this program.
21     You are forbidden to forbid anyone else to use, share and improve
22     what you give them.   Help stamp out software-hoarding!  
23 -------------------------------------------------------------------------*/
24
25
26 #ifndef SDCCHASHT_H
27 #define SDCCHASHT_H
28
29 #include  "SDCCalloc.h"
30
31
32 /* hashtable item */
33 typedef struct hashtItem
34 {
35     int key;
36     /* Pointer to the key that was hashed for key.
37        Used for a hash table with unique keys. */
38     void *pkey;
39     void *item;
40     struct hashtItem *next ;
41 } hashtItem ;
42
43 /* hashtable */
44 typedef struct hTab
45 {
46     int size  ;             /* max number of items */
47     int minKey;             /* minimum key value   */
48     int maxKey ;            /* maximum key value */
49     hashtItem **table ;     /* the actual table  */
50     int currKey  ;          /* used for iteration */
51     hashtItem *currItem ;   /* current item within the list */
52     int nItems ;
53 } hTab ;
54
55 typedef enum {
56     DELETE_CHAIN = 1,
57     DELETE_ITEM 
58 } DELETE_ACTION;
59
60
61 /*-----------------------------------------------------------------*/
62 /*           Forward   definition    for   functions               */
63 /*-----------------------------------------------------------------*/
64
65 /* hashtable related functions */
66 hTab        *newHashTable      (int);
67 void         hTabAddItem (hTab **, int key, void *item);
68 /** Adds a new item to the hash table.
69     @param h            The hash table to add to
70     @param key          A hashed version of pkey
71     @param pkey         A copy of the key.  Owned by the
72                         hash table after this function.
73     @param item         Value for this key.
74 */
75 void         hTabAddItemLong(hTab **h, int key, void *pkey, void *item);
76 /** Finds a item by exact key.
77     Searches all items in the key 'key' for a key that
78     according to 'compare' matches pkey.
79     @param h            The hash table to search
80     @param key          A hashed version of pkey.
81     @param pkey         The key to search for
82     @param compare      Returns 0 if pkey == this
83 */
84 void *       hTabFindByKey(hTab *h, int key, const void *pkey, int (*compare)(const void *, const void *));
85 /** Deletes an item with the exact key 'pkey'
86     @see hTabFindByKey
87 */
88 int          hTabDeleteByKey(hTab **h, int key, const void *pkey, int (*compare)(const void *, const void *));
89
90 void         hTabDeleteItem (hTab **, int key,
91                              const void *item, DELETE_ACTION action,
92                              int (*compareFunc)(const void *,const void *));
93 int          hTabIsInTable (hTab *, int , void * , 
94                                  int (*compareFunc)(void *,void *));
95 void         *hTabFirstItem (hTab *, int *);
96 void         *hTabNextItem (hTab *, int *);
97 hTab         *hTabFromTable (hTab *);
98 int          isHtabsEqual (hTab *,hTab *, int (*compareFunc)(void *,void *));
99 hashtItem    *hTabSearch  (hTab *, int );
100 void         *hTabItemWithKey(hTab *,int );
101 void         hTabAddItemIfNotP(hTab **,int, void *);
102 void         hTabDeleteAll(hTab *);
103 void        *hTabFirstItemWK (hTab *htab, int wk);
104 void        *hTabNextItemWK (hTab *htab );
105 void         hTabClearAll (hTab *htab);
106
107 /** Find the first item that either is 'item' or which
108     according to 'compareFunc' is the same as item.
109     @param compareFunc          strcmp like compare function, may be null.
110 */
111 void *hTabFindItem(hTab *htab, int key, 
112                    void *item, int (*compareFunc)(void *,void *));
113
114 void shash_add(hTab **h, const char *szKey, const char *szValue);
115 const char *shash_find(hTab *h, const char *szKey);
116
117 #endif