Update svn merge history.
[sdcc.git] / sdcc / src / SDCChasht.h
blobba7b9cbe871723d0ec8f511975efa5be59df5f5f
1 /*-----------------------------------------------------------------
2 SDCChast.h - contains support routines for hashtables/sets .
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
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.
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.
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.
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 -------------------------------------------------------------------------*/
26 #ifndef SDCCHASHT_H
27 #define SDCCHASHT_H
31 /* hashtable item */
32 typedef struct hashtItem
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;
41 hashtItem;
43 /* hashtable */
44 typedef struct hTab
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;
54 hTab;
56 typedef enum
58 DELETE_CHAIN = 1,
59 DELETE_ITEM
61 DELETE_ACTION;
64 /*-----------------------------------------------------------------*/
65 /* Forward definition for functions */
66 /*-----------------------------------------------------------------*/
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.
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
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
91 int hTabDeleteByKey (hTab ** h, int key, const void *pkey, int (*compare) (const void *, const void *));
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);
104 /* return the first item with the given key */
105 void *hTabItemWithKey (hTab *, int);
107 void hTabAddItemIfNotP (hTab **, int, void *);
108 void hTabDeleteAll (hTab *);
109 void *hTabFirstItemWK (hTab * htab, int wk);
110 void *hTabNextItemWK (hTab * htab);
111 void hTabClearAll (hTab * htab);
112 int hTabMaxKey (hTab *htab);
114 /** Find the first item that either is 'item' or which
115 according to 'compareFunc' is the same as item.
116 @param compareFunc strcmp like compare function, may be null.
118 void *hTabFindItem (hTab * htab, int key,
119 void *item, int (*compareFunc) (void *, void *));
121 void shash_add (hTab ** h, const char *szKey, const char *szValue);
122 const char *shash_find (hTab * h, const char *szKey);
124 #endif