Use 'ao-dbg' instead of 's51' to communicate with TeleMetrum
[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   }
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   }
54 hTab;
55
56 typedef enum
57   {
58     DELETE_CHAIN = 1,
59     DELETE_ITEM
60   }
61 DELETE_ACTION;
62
63
64 /*-----------------------------------------------------------------*/
65 /*           Forward   definition    for   functions               */
66 /*-----------------------------------------------------------------*/
67
68 /* hashtable related functions */
69 hTab *newHashTable (int);
70 void hTabAddItem (hTab **, int key, void *item);
71 /** Adds a new item to the hash table.
72     @param h            The hash table to add to
73     @param key          A hashed version of pkey
74     @param pkey         A copy of the key.  Owned by the
75                         hash table after this function.
76     @param item         Value for this key.
77 */
78 void hTabAddItemLong (hTab ** h, int key, void *pkey, void *item);
79 /** Finds a item by exact key.
80     Searches all items in the key 'key' for a key that
81     according to 'compare' matches pkey.
82     @param h            The hash table to search
83     @param key          A hashed version of pkey.
84     @param pkey         The key to search for
85     @param compare      Returns 0 if pkey == this
86 */
87 void *hTabFindByKey (hTab * h, int key, const void *pkey, int (*compare) (const void *, const void *));
88 /** Deletes an item with the exact key 'pkey'
89     @see hTabFindByKey
90 */
91 int hTabDeleteByKey (hTab ** h, int key, const void *pkey, int (*compare) (const void *, const void *));
92
93 void hTabDeleteItem (hTab **, int key,
94                      const void *item, DELETE_ACTION action,
95                      int (*compareFunc) (const void *, const void *));
96 int hTabIsInTable (hTab *, int, void *,
97                    int (*compareFunc) (void *, void *));
98 void *hTabFirstItem (hTab *, int *);
99 void *hTabNextItem (hTab *, int *);
100 hTab *hTabFromTable (hTab *);
101 int isHtabsEqual (hTab *, hTab *, int (*compareFunc) (void *, void *));
102 hashtItem *hTabSearch (hTab *, int);
103 void *hTabItemWithKey (hTab *, int);
104 void hTabAddItemIfNotP (hTab **, int, void *);
105 void hTabDeleteAll (hTab *);
106 void *hTabFirstItemWK (hTab * htab, int wk);
107 void *hTabNextItemWK (hTab * htab);
108 void hTabClearAll (hTab * htab);
109 int hTabMaxKey (hTab *htab);
110
111 /** Find the first item that either is 'item' or which
112     according to 'compareFunc' is the same as item.
113     @param compareFunc          strcmp like compare function, may be null.
114 */
115 void *hTabFindItem (hTab * htab, int key,
116                     void *item, int (*compareFunc) (void *, void *));
117
118 void shash_add (hTab ** h, const char *szKey, const char *szValue);
119 const char *shash_find (hTab * h, const char *szKey);
120
121 #endif