Changeset 265 for trunk/archive/pslib/src/Utils/hash.c
- Timestamp:
- Mar 19, 2004, 9:14:22 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/archive/pslib/src/Utils/hash.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/pslib/src/Utils/hash.c
r173 r265 224 224 return doHashWork(table, key, NULL, 1, NULL); 225 225 } 226 227 /*****************************************************************************/228 #if 0 // testing229 230 typedef struct { char *name; } ID;231 static ID *IdAlloc(const char *name)232 {233 ID *id = psAlloc(sizeof(ID));234 id->name = psStringCopy(name);235 236 return id;237 }238 239 static void IdFree(ID *id)240 {241 if (psMemGetRefCounter(id) > 1) {242 psMemDecrRefCounter(id);243 return;244 }245 246 psFree(id->name);247 psFree(id);248 }249 250 int main(void)251 {252 psSetTraceLevel("utils.hash", 3);253 long memId0 = psMemGetId();254 255 psHash *hash = psHashAlloc(16);256 257 psHashInsert(hash, "Lynda", IdAlloc("Lee"), (void (*)(void *))IdFree);258 psHashInsert(hash, "Lynda", IdAlloc("Lee"), (void (*)(void *))IdFree);259 psHashInsert(hash, "Robert", IdAlloc("Lupton"), (void (*)(void *))IdFree);260 psHashInsert(hash, "Robert", IdAlloc("the Good"), (void (*)(void *))IdFree);261 262 char *names[] = {"Robert", "Lynda", "Rowan", NULL};263 for (char **name = names; *name != NULL; name++) {264 ID *id = psHashLookup(hash, *name);265 printf("%s's surname is:\t%s\n", *name,266 ((id == NULL) ? "(unknown)" : id->name));267 }268 269 psHashFree(hash, (void (*)(void *))IdFree);270 /*271 * Check for memory leaks272 */273 fprintf(stderr,"Checking for memory leaks:\n");274 psMemCheckLeaks(memId0, NULL, stderr);275 276 return 0;277 }278 279 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
