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
/
PHEAP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-08-01
|
12KB
|
387 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>
#ifdef HAS_UNISTD_H
# include <unistd.h>
#else
# include <stdlib.h>
#endif
#include <string.h>
#include <malloc.h>
#include "../memsl.h"
/*************************************************************************\
\*************************************************************************/
#define LARGETEST 1000
struct priority_item
{
char *item;
int priority;
};
struct priority_item item0 = { "Item0", 0 }, item1 = { "Item1", 10 },
item2 = { "Item2", 20 }, item3 = { "Item3", 30 },
item4 = { "Item4", 40 }, item5 = { "Item5", 50 },
item6 = { "Item6", 60 }, item7 = { "Item7", 70 },
item8 = { "Item8", 80 }, item9 = { "Item9", 90 };
#ifdef WBSTDC
int Priority1(void *nullitem, struct priority_item *item1, struct priority_item *item2)
#else
int Priority1(nullitem, item1, item2)
void *nullitem;
struct priority_item *item1,
*item2;
#endif
{
WBTrcEntry(0,"Priority1",("p1 = %d, p2 = %d",item1->priority,item2->priority));
nullitem = nullitem;
WBTrcReturn(0,item2->priority - item1->priority,("%d",item2->priority - item1->priority));
}
#ifdef WBSTDC
int Priority2(void *nullitem, struct priority_item *item1, struct priority_item *item2)
#else
int Priority2(nullitem, item1, item2)
void *nullitem;
struct priority_item *item1,
*item2;
#endif
{
WBTrcEntry(0,"Priority2",("p1 = %d, p2 = %d",item1->priority,item2->priority));
nullitem = nullitem;
WBTrcReturn(0,item1->priority - item2->priority,("%d",item1->priority - item2->priority));
}
#ifdef WBSTDC
int Compare(void *nullitem, struct priority_item *item1, struct priority_item *item2)
#else
int Compare(nullitem, item1, item2)
void *nullitem;
struct priority_item *item1,
*item2;
#endif
{
WBTrcEntry(0,"Compare",("p1 = %s, p2 = %s",item1->item,item2->item));
nullitem = nullitem;
WBTrcReturn(0,strcmp(item1->item,item2->item),("%d",strcmp(item1->item,item2->item)));
}
#ifdef WBSTDC
void Execute(void *nullitem, struct priority_item *item)
#else
void Execute(nullitem, item)
void *nullitem;
struct priority_item *item;
#endif
{
WBTrcEntry(0,"Execute",("p1 = %s",item->item));
nullitem = nullitem;
printf("%d, %s\n",item->priority,item->item);
WBTrcVReturn(0,(""));
}
#ifdef WBSTDC
void Delete(void *nullitem, struct priority_item *item)
#else
void Delete(nullitem, item)
void *nullitem;
struct priority_item *item;
#endif
{
WBTrcEntry(0,"Delete",("p1 = %s",item->item));
nullitem = nullitem;
printf("Deleting %s\n",item->item);
WBTrcVReturn(0,(""));
}
#ifdef WBSTDC
void Test1(void)
#else
void Test1()
#endif
{
struct priority_item *itemptr;
WBPHEAP *pheap;
WBTrcEntry(0,"Test1",(""));
if ((pheap = WBPHeapOpen(NULL, 100)) != NULL)
{
WBPHeapDuplicates(pheap,1);
#ifdef FUNCTCAST
WBPHeapPriorityF(pheap,NULL,(int (*)(void *, void *, void *))Priority1);
WBPHeapCompareF(pheap,NULL,(int (*)(void *, void *, void *))Compare);
WBPHeapDeleteF(pheap,NULL,(void (*)(void *, void *))Delete);
WBPHeapExecuteF(pheap,NULL,(void (*)(void *, void *))Execute);
#else
WBPHeapPriorityF(pheap,NULL,(int (*)())Priority1);
WBPHeapCompareF(pheap,NULL,(int (*)())Compare);
WBPHeapDeleteF(pheap,NULL,(void (*)())Delete);
WBPHeapExecuteF(pheap,NULL,(void (*)())Execute);
#endif
printf("Numitems = %d\n",WBPHeapNumItems(pheap));
printf("Is Empty = %s\n",WBPHeapIsEmpty(pheap) ? "Yes" : "No");
printf("Add = %d\n",WBPHeapAdd(pheap, &item0));
printf("Add = %d\n",WBPHeapAdd(pheap, &item1));
printf("Add = %d\n",WBPHeapAdd(pheap, &item2));
printf("Add = %d\n",WBPHeapAdd(pheap, &item3));
printf("Numitems = %d\n",WBPHeapNumItems(pheap));
printf("Is Empty = %s\n",WBPHeapIsEmpty(pheap) ? "Yes" : "No");
WBPHeapClear(pheap);
printf("Numitems = %d\n",WBPHeapNumItems(pheap));
printf("Is Empty = %s\n",WBPHeapIsEmpty(pheap) ? "Yes" : "No");
printf("Add = %d\n",WBPHeapAdd(pheap, &item4));
printf("Add = %d\n",WBPHeapAdd(pheap, &item5));
printf("Add = %d\n",WBPHeapAdd(pheap, &item6));
printf("Add = %d\n",WBPHeapAdd(pheap, &item7));
printf("Add = %d\n",WBPHeapAdd(pheap, &item8));
printf("Add = %d\n",WBPHeapAdd(pheap, &item9));
printf("Add = %d\n",WBPHeapAdd(pheap, &item0));
printf("Add = %d\n",WBPHeapAdd(pheap, &item1));
printf("Add = %d\n",WBPHeapAdd(pheap, &item2));
printf("Add = %d\n",WBPHeapAdd(pheap, &item3));
printf("Add = %d\n",WBPHeapAdd(pheap, &item4));
printf("Add = %d\n",WBPHeapAdd(pheap, &item5));
printf("Add = %d\n",WBPHeapAdd(pheap, &item6));
printf("Add = %d\n",WBPHeapAdd(pheap, &item7));
printf("Add = %d\n",WBPHeapAdd(pheap, &item8));
printf("Add = %d\n",WBPHeapAdd(pheap, &item9));
printf("Numitems = %d\n",WBPHeapNumItems(pheap));
printf("Is Empty = %s\n",WBPHeapIsEmpty(pheap) ? "Yes" : "No");
printf("Delete = %d\n",WBPHeapDelete(pheap, &item2));
printf("Delete = %d\n",WBPHeapDelete(pheap, &item2));
printf("Delete = %d\n",WBPHeapDelete(pheap, &item4));
printf("Delete = %d\n",WBPHeapDelete(pheap, &item4));
printf("Delete = %d\n",WBPHeapDelete(pheap, &item6));
printf("Delete = %d\n",WBPHeapDelete(pheap, &item8));
printf("Delete = %d\n",WBPHeapDelete(pheap, &item8));
printf("Numitems = %d\n",WBPHeapNumItems(pheap));
printf("Is Empty = %s\n",WBPHeapIsEmpty(pheap) ? "Yes" : "No");
printf("Search for %s = %s\n",item9.item,((struct priority_item *)WBPHeapSearch(pheap, &item9))->item);
WBPHeapExecute(pheap);
while ((itemptr = WBPHeapGet(pheap)) != NULL)
printf("%d %s\n",itemptr->priority,itemptr->item);
printf("Numitems = %d\n",WBPHeapNumItems(pheap));
printf("Is Empty = %s\n",WBPHeapIsEmpty(pheap) ? "Yes" : "No");
WBPHeapClose(pheap);
}
WBTrcVReturn(0,(""));
}
#ifdef WBSTDC
void Test2(void)
#else
void Test2()
#endif
{
struct priority_item *itemptr;
WBPHEAP *pheap;
char itemstr[10], *tmpstr;
int i, randval;
WBTrcEntry(0,"Test2",(""));
if ((pheap = WBPHeapOpen(NULL, LARGETEST))