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
/
memslc.3
/
pqueue.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-08-01
|
12KB
|
388 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;
WBPQUEUE *pqueue;
WBTrcEntry(0,"Test1",(""));
if ((pqueue = WBPQueueOpen(NULL, 100, 0)) != NULL)
{
WBPQueueDuplicates(pqueue,1);
#ifdef FUNCTCAST
WBPQueuePriorityF(pqueue,NULL,(int (*)(void *, void *, void *))Priority1);
WBPQueueCompareF(pqueue,NULL,(int (*)(void *, void *, void *))Compare);
WBPQueueDeleteF(pqueue,NULL,(void (*)(void *, void *))Delete);
WBPQueueExecuteF(pqueue,NULL,(void (*)(void *, void *))Execute);
#else
WBPQueuePriorityF(pqueue,NULL,(int (*)())Priority1);
WBPQueueCompareF(pqueue,NULL,(int (*)())Compare);
WBPQueueDeleteF(pqueue,NULL,(void (*)())Delete);
WBPQueueExecuteF(pqueue,NULL,(void (*)())Execute);
#endif
printf("Numitems = %d\n",WBPQueueNumItems(pqueue));
printf("Is Empty = %s\n",WBPQueueIsEmpty(pqueue) ? "Yes" : "No");
printf("Add = %d\n",WBPQueueAdd(pqueue, &item0));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item1));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item2));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item3));
printf("Numitems = %d\n",WBPQueueNumItems(pqueue));
printf("Is Empty = %s\n",WBPQueueIsEmpty(pqueue) ? "Yes" : "No");
WBPQueueClear(pqueue);
printf("Numitems = %d\n",WBPQueueNumItems(pqueue));
printf("Is Empty = %s\n",WBPQueueIsEmpty(pqueue) ? "Yes" : "No");
printf("Add = %d\n",WBPQueueAdd(pqueue, &item4));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item5));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item6));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item7));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item8));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item9));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item0));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item1));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item2));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item3));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item4));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item5));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item6));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item7));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item8));
printf("Add = %d\n",WBPQueueAdd(pqueue, &item9));
printf("Numitems = %d\n",WBPQueueNumItems(pqueue));
printf("Is Empty = %s\n",WBPQueueIsEmpty(pqueue) ? "Yes" : "No");
printf("Delete = %d\n",WBPQueueDelete(pqueue, &item2));
printf("Delete = %d\n",WBPQueueDelete(pqueue, &item2));
printf("Delete = %d\n",WBPQueueDelete(pqueue, &item4));
printf("Delete = %d\n",WBPQueueDelete(pqueue, &item4));
printf("Delete = %d\n",WBPQueueDelete(pqueue, &item6));
printf("Delete = %d\n",WBPQueueDelete(pqueue, &item8));
printf("Delete = %d\n",WBPQueueDelete(pqueue, &item8));
printf("Numitems = %d\n",WBPQueueNumItems(pqueue));
printf("Is Empty = %s\n",WBPQueueIsEmpty(pqueue) ? "Yes" : "No");
printf("Search for %s = %s\n",item9.item,((struct priority_item *)WBPQueueSearch(pqueue, &item9))->item);
WBPQueueExecute(pqueue);
while ((itemptr = WBPQueueGet(pqueue)) != NULL)
printf("%d %s\n",itemptr->priority,itemptr->item);
printf("Numitems = %d\n",WBPQueueNumItems(pqueue));
printf("Is Empty = %s\n",WBPQueueIsEmpty(pqueue) ? "Yes" : "No");
WBPQueueClose(pqueue);
}
WBTrcVReturn(0,(""));
}
#ifdef WBSTDC
void Test2(void)
#else
void Test2()
#endif
{
struct priority_item *itemptr;
WBPQUEUE *pqueue;
char itemstr[10],