|
|
1.1 ! root 1: /* ! 2: * File: queue.h ! 3: * Author: Robert I. Pitts <[email protected]> ! 4: * Last Modified: March 9, 2000 ! 5: * Topic: Queue - Array Implementation ! 6: * ---------------------------------------------------------------- ! 7: */ ! 8: ! 9: #ifndef _QUEUE_H ! 10: #define _QUEUE_H ! 11: ! 12: /* ! 13: * Constants ! 14: * --------- ! 15: * ERROR_* These signal error conditions in queue functions ! 16: * and are used as exit codes for the program. ! 17: */ ! 18: #define ERROR_QUEUE 2 ! 19: #define ERROR_MEMORY 3 ! 20: ! 21: /* ! 22: * Type: queueElementT ! 23: * ------------------- ! 24: * This is the type of objects held in the queue. ! 25: */ ! 26: ! 27: /*typedef char queueElementT; ! 28: typedef unsigned char *queueElementT; ! 29: */ ! 30: ! 31: struct queuepacket { ! 32: int len; ! 33: unsigned char data[4096]; ! 34: }; ! 35: typedef struct queuepacket *queueElementT; ! 36: ! 37: /* ! 38: * Type: queueADT ! 39: * -------------- ! 40: * The actual implementation of a queue is completely ! 41: * hidden. Client will work with queueADT which is a ! 42: * pointer to underlying queueCDT. ! 43: */ ! 44: ! 45: /* ! 46: * NOTE: need word struct below so that the compiler ! 47: * knows at least that a queueCDT will be some sort ! 48: * of struct. ! 49: */ ! 50: ! 51: typedef struct queueCDT *queueADT; ! 52: ! 53: /* ! 54: * Function: QueueCreate ! 55: * Usage: queue = QueueCreate(); ! 56: * ------------------------- ! 57: * A new empty queue is created and returned. ! 58: */ ! 59: ! 60: queueADT QueueCreate(void); ! 61: ! 62: /* Function: QueueDestroy ! 63: * Usage: QueueDestroy(queue); ! 64: * ----------------------- ! 65: * This function frees all memory associated with ! 66: * the queue. "queue" may not be used again unless ! 67: * queue = QueueCreate() is called first. ! 68: */ ! 69: ! 70: void QueueDestroy(queueADT queue); ! 71: ! 72: /* ! 73: * Functions: QueueEnter, QueueDelete ! 74: * Usage: QueueEnter(queue, element); ! 75: * element = QueueDelete(queue); ! 76: * -------------------------------------------- ! 77: * These are the fundamental queue operations that enter ! 78: * elements in and delete elements from the queue. A call ! 79: * to QueueDelete() on an empty queue or to QueueEnter() ! 80: * on a full queue is an error. Make use of QueueIsFull() ! 81: * and QueueIsEmpty() (see below) to avoid these errors. ! 82: */ ! 83: ! 84: void QueueEnter(queueADT queue, queueElementT element); ! 85: queueElementT QueueDelete(queueADT queue); ! 86: ! 87: ! 88: /* ! 89: * Functions: QueueIsEmpty, QueueIsFull ! 90: * Usage: if (QueueIsEmpty(queue)) ... ! 91: * ----------------------------------- ! 92: * These return a true/false value based on whether ! 93: * the queue is empty or full, respectively. ! 94: */ ! 95: ! 96: int QueueIsEmpty(queueADT queue); ! 97: int QueueIsFull(queueADT queue); ! 98: ! 99: ! 100: /* ! 101: * Function: QueuePeek ! 102: * Usage: qeuesize = QueuePeek(queue) ... ! 103: * ----------------------------------- ! 104: * This returns the number of elements currently ! 105: * stored in the queue. ! 106: */ ! 107: int QueuePeek(queueADT queue); ! 108: ! 109: #endif /* not defined _QUEUE_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.