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
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 -------------------------------------------------------------------------*/
32 typedef struct hashtItem
35 /* Pointer to the key that was hashed for key.
36 Used for a hash table with unique keys. */
39 struct hashtItem *next ;
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 */
60 /*-----------------------------------------------------------------*/
61 /* Forward definition for functions */
62 /*-----------------------------------------------------------------*/
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.
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
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'
87 int hTabDeleteByKey(hTab **h, int key, const void *pkey, int (*compare)(const void *, const void *));
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);
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.
110 void *hTabFindItem(hTab *htab, int key,
111 void *item, int (*compareFunc)(void *,void *));
113 void shash_add(hTab **h, const char *szKey, const char *szValue);
114 const char *shash_find(hTab *h, const char *szKey);