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;
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 */
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'
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);
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);
110 /** Find the first item that either is 'item' or which
111 according to 'compareFunc' is the same as item.
112 @param compareFunc strcmp like compare function, may be null.
114 void *hTabFindItem (hTab * htab, int key,
115 void *item, int (*compareFunc) (void *, void *));
117 void shash_add (hTab ** h, const char *szKey, const char *szValue);
118 const char *shash_find (hTab * h, const char *szKey);