Remove all references to the GC library, replacing GC_malloc
[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
30
31 /* hashtable item */
32 typedef struct hashtItem
33 {
34     int key;
35     /* Pointer to the key that was hashed for key.
36        Used for a hash table with unique keys. */
37     void *pkey;
38     void *item;
39     struct hashtItem *next ;
40 } hashtItem ;
41
42 /* hashtable */
43 typedef struct hTab
44 {
45     int size  ;             /* max number of items */
46     int minKey;             /* minimum key value   */
47     int maxKey ;            /* maximum key value */
48     hashtItem **table ;     /* the actual table  */
49     int currKey  ;          /* used for iteration */
50     hashtItem *currItem ;   /* current item within the list */
51     int nItems ;
52 } hTab ;
53
54 typedef enum {
55     DELETE_CHAIN = 1,
56     DELETE_ITEM 
57 } DELETE_ACTION;
58
59
60 /*-----------------------------------------------------------------*/
61 /*           Forward   definition    for   functions               */
62 /*-----------------------------------------------------------------*/
63
64 /* hashtable related functions */
65 hTab        *newHashTable      (int);
66 void         hTabAddItem (hTab **, int key, void *item);
67 /** Adds a new item to the hash table.
68     @param h            The hash table to add to
69     @param key          A hashed version of pkey
70     @param pkey         A copy of the key.  Owned by the
71                         hash table after this function.
72     @param item         Value for this key.
73 */
74 void         hTabAddItemLong(hTab **h, int key, void *pkey, void *item);
75 /** Finds a item by exact key.
76     Searches all items in the key 'key' for a key that
77     according to 'compare' matches pkey.
78     @param h            The hash table to search
79     @param key          A hashed version of pkey.
80     @param pkey         The key to search for
81     @param compare      Returns 0 if pkey == this
82 */
83 void *       hTabFindByKey(hTab *h, int key, const void *pkey, int (*compare)(const void *, const void *));
84 /** Deletes an item with the exact key 'pkey'
85     @see hTabFindByKey
86 */
87 int          hTabDeleteByKey(hTab **h, int key, const void *pkey, int (*compare)(const void *, const void *));
88
89 void         hTabDeleteItem (hTab **, int key,
90                              const void *item, DELETE_ACTION action,
91                              int (*compareFunc)(const void *,const void *));
92 int          hTabIsInTable (hTab *, int , void * , 
93                                  int (*compareFunc)(void *,void *));
94 void         *hTabFirstItem (hTab *, int *);
95 void         *hTabNextItem (hTab *, int *);
96 hTab         *hTabFromTable (hTab *);
97 int          isHtabsEqual (hTab *,hTab *, int (*compareFunc)(void *,void *));
98 hashtItem    *hTabSearch  (hTab *, int );
99 void         *hTabItemWithKey(hTab *,int );
100 void         hTabAddItemIfNotP(hTab **,int, void *);
101 void         hTabDeleteAll(hTab *);
102 void        *hTabFirstItemWK (hTab *htab, int wk);
103 void        *hTabNextItemWK (hTab *htab );
104 void         hTabClearAll (hTab *htab);
105
106 /** Find the first item that either is 'item' or which
107     according to 'compareFunc' is the same as item.
108     @param compareFunc          strcmp like compare function, may be null.
109 */
110 void *hTabFindItem(hTab *htab, int key, 
111                    void *item, int (*compareFunc)(void *,void *));
112
113 void shash_add(hTab **h, const char *szKey, const char *szValue);
114 const char *shash_find(hTab *h, const char *szKey);
115
116 #endif