#ifndef __QUEUE_H__ #define __QUEUE_H__ /* =============================================================================== Queue template =============================================================================== */ template< class type, int nextOffset > class idQueueTemplate { public: idQueueTemplate( void ); void Add( type *element ); type * Get( void ); private: type * first; type * last; }; #define QUEUE_NEXT_PTR( element ) (*((type**)(((byte*)element)+nextOffset))) template< class type, int nextOffset > idQueueTemplate::idQueueTemplate( void ) { first = last = NULL; } template< class type, int nextOffset > void idQueueTemplate::Add( type *element ) { QUEUE_NEXT_PTR(element) = NULL; if ( last ) { QUEUE_NEXT_PTR(last) = element; } else { first = element; } last = element; } template< class type, int nextOffset > type *idQueueTemplate::Get( void ) { type *element; element = first; if ( element ) { first = QUEUE_NEXT_PTR(first); if ( last == element ) { last = NULL; } QUEUE_NEXT_PTR(element) = NULL; } return element; } /* =============================================================================== Raven Queue template =============================================================================== */ template class rvQueue { TYPE mData[CAPACITY]; // Total capacity of the queue int mNewest; // Head int mOldest; // Tail int mSize; // Size... yes, this could be calculated... public: rvQueue() {clear();} int size() {return mSize;} bool empty() {return mSize==0;} bool full() {return mSize>=CAPACITY;} int begin() {return (full())?(mOldest+1):(mOldest);} int end() {return mNewest-1;} void clear() {mNewest = mOldest = mSize = 0;} bool valid(int i) {return ((mNewest>=mOldest)?(i>=mOldest && i=mNewest && i=(CAPACITY-1))?(0):(i+1);} TYPE& first() {assert(!empty()); return mData[mOldest];} TYPE& last() {assert(!empty()); return mData[mNewest-1];} TYPE& operator[] (int i) {assert(valid(i)); return mData[i];} int push(const TYPE& value) {assert(!full()); mData[mNewest]=value; inc(mNewest); return (mSize++);} int pop() {assert(!empty()); inc(mOldest); return (mSize--);} }; /* =============================================================================== Raven Bit Vector Template =============================================================================== */ template class rvBits { enum { BITS_SHIFT = 5, // 5. Such A Nice Number BITS_INT_SIZE = 32, // Size Of A Single Word BITS_AND = (BITS_INT_SIZE - 1), // Used For And Operation ARRAY_SIZE = ((CAPACITY + BITS_AND)/(BITS_INT_SIZE)), // Num Words Used DATA_BYTE_SIZE = (ARRAY_SIZE*sizeof(unsigned int)), // Num Bytes Used }; unsigned int mData[ARRAY_SIZE]; public: rvBits() {clear();} void clear() {memset(mData, 0, (size_t)(ARRAY_SIZE * sizeof( unsigned int )));} bool valid(const int i) {return (i>=0 && i>BITS_SHIFT] &= ~(1<<(i&BITS_AND));} void set(const int i) {assert(valid(i)); mData[i>>BITS_SHIFT] |= (1<<(i&BITS_AND));} bool operator[](const int i) {assert(valid(i)); return (mData[i>>BITS_SHIFT] & (1<<(i&BITS_AND)))!=0;} }; /* =============================================================================== Raven Pool =============================================================================== */ template class rvPool { TYPE mData[CAPACITY]; TYPE* mFree[CAPACITY]; int mSize; public: rvPool() {clear();} int size() {return mSize;} bool empty() {return mSize==0;} bool full() {return mSize>=CAPACITY;} void clear() {mSize=0; for (int i=0; i class rvIndexPool { TYPE mData[CAPACITY]; TYPE* mFree[CAPACITY]; TYPE* mIndx[INDEXNUM]; int mSize; public: rvIndexPool() {clear();} int size() {return mSize;} bool empty() {return mSize==0;} bool full() {return mSize>=CAPACITY;} void clear() {mSize=0; for (int i=0; i=0 && i