home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ User's Journal & Wi…eveloper's Journal Tools
/
C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso
/
windbase
/
windbase.exe
/
MEMSLC.3
/
HASH.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-30
|
5KB
|
160 lines
/*****************************************************************************\
** **
** WW WW IIIIIIII NNN NN DDDDDDD BBBBBBB AA SSSSSS EEEEEEEE **
** WW W WW II NNNN NN DD DD BB BB AA AA SS EE **
** WW W WW II NN NN NN DD DD BBBBBBB AAAAAAAA SSSSSS EEEEEE **
** WW W WW II NN NNNN DD DD BB BB AA AA SS EE **
** WWWWW IIIIIIII NN NNN DDDDDDD BBBBBBB AA AA SSSSSS EEEEEEEE **
** **
** SSSSSS OOOOOO FFFFFFFF TTTTTTTT WW WW AA RRRRRRR EEEEEEEE **
** SS OO OO FF TT WW W WW AA AA RR RR EE **
** SSSSS OO OO FFFFF TT WW W WW AAAAAAAA RRRRRRR EEEEEE **
** SS OO OO FF TT WW W WW AA AA RR RR EE **
** SSSSSS OOOOOO FF TT WWWWW AA AA RR RR EEEEEEEE **
** **
*********** NOTICE ************************************************************
** This file contains valuable trade secrets and proprietary **
** assets of Windbase Software Inc. Embodying substantial **
** creative efforts and confidential information. Unauthorized **
** use, copying, decompiling, translating, disclosure or **
** transfer, of any kind, is strictly prohibited. **
** **
** COPYRIGHT (C) 1992, 1993, 1994. Windbase Software Inc. **
** ALL RIGHTS RESERVED. **
\*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "../memsl.h"
WBHASH *hash;
char strarray[200][21];
int numexe = 0;
#ifdef WBSTDC
int Compare(void *nullitem, char *item1, char *item2)
#else
int Compare(nullitem, item1, item2)
void *nullitem;
char *item1,
*item2;
#endif
{
WBTrcEntry(0,"Compare",("%p, %s, %s",nullitem,item1?item1:"NULL",item2?item2:"NULL"));
nullitem = nullitem;
WBTrcReturn(0,strcmp(item1,item2),("%d",strcmp(item1,item2)));
}
#ifdef WBSTDC
void Execute(void *nullitem, char *item)
#else
void Execute(nullitem, item)
void *nullitem;
char *item;
#endif
{
WBTrcEntry(0,"Execute",("%p, %s",nullitem,item?item:"NULL"));
nullitem = nullitem;
numexe++;
printf("%d %s\n",numexe,item);
WBTrcVReturn(0,(""));
}
#if defined(WBTRC_LEVEL1) || defined(WBTRC_LEVEL2)
#ifdef WBSTDC
int main(int argc, char **argv)
#else
int main(argc, argv)
int argc;
char **argv;
#endif
#else
#ifdef WBSTDC
int main(void)
#else
int main()
#endif
#endif
{
FILE *file;
int i = 0, i2;
WBTrcMainEntry();
memset(strarray,0,sizeof(strarray));
if ((hash = WBHashOpen(NULL,50)) != NULL)
{
WBHashHashingF(hash,NULL,WBHashFunct);
#ifdef FUNCTCAST
WBHashCompareF(hash,NULL,(int (*)(void *, void *, void *))Compare);
WBHashExecuteF(hash,NULL,(void (*)(void *, void *))Execute);
#else
WBHashCompareF(hash,NULL,(int (*)())Compare);
WBHashExecuteF(hash,NULL,(void (*)())Execute);
#endif
WBHashStats(hash,"hash.sta");
if (WBHashIsEmpty(hash))
printf("Hash table is empty.\n");
else
printf("Hash table is NOT empty.\n");
if ((file = fopen("data.dat","r")) != NULL)
{
while (i < 200 && fgets(strarray[i],20,file))
{
if (strarray[i][strlen(strarray[i])-1] == '\n')
strarray[i][strlen(strarray[i])-1] = 0;
WBHashAdd(hash,strarray[i]);
i++;
}
fclose(file);
printf("Hash statistics can be found in \"hash.sta\"\n");
WBHashStats(hash,"hash.sta");
if (WBHashIsEmpty(hash))
printf("Hash table is empty.\n");
else
printf("Hash table is NOT empty.\n");
printf("Hash Table contains %ld items.\n",WBHashNumItems(hash));
WBHashExecute(hash);
for (i2 = 0; i2 < i; i2++)
{
if (WBHashSearch(hash,strarray[i2]))
printf("WBHashSearch(): Found %s\n",strarray[i2]);
else
printf("WBHashSearch(): %s was not found\n",strarray[i2]);
}
printf("i2 = %d\n",i2);
/*
** No deletion function is defined, so the items
** will not be freed. Only the cells holding
** the items will be freed.
*/
for (i2 = 0; i2 < i; i2++)
{
if (WBHashDelete(hash,strarray[i2]))
printf("WBHashDelete(): Deleted %s\n",strarray[i2]);
else
printf("WBHashDelete(): %s was not found\n",strarray[i2]);
}
printf("i2 = %d\n",i2);
}
WBHashClose(hash);
}
WBTrcReturn(0,0,("0"));
}