-
template
class
PortableQueue<class ItemType>
(Return to index)
-
This class is very similar to an STL vector, Java Vector, or BList,
except that it is implemented in such a way that adding or removing
items from the head or tail of the list is an O(1) operation.
Type:
Include file:
../../queue/PortableQueue.h
Synopsis:
Public methods:
- public bool
AddHead (const ItemType &item)
Puts (item) at the head of the queue. Queue size grows by one.
Returns true on success, false on failure (i.e. out of memory)
- public bool
AddTail (const ItemType &item)
Puts (item) at the end of the queue. Queue size grows by one.
Returns true on success, false on failure (i.e. out of memory)
- public uint32
CountItems () const
Returns the number of items in the queue. (This number
does not include additional pre-allocated space)
- public bool
EnsureSize (uint32 numItems)
Makes sure there is enough space allocated for at least
(numItems) items. Returns true on success, false on
failure (out of memory). You only need to call this if
you wish to minimize the number of data re-allocations done.
- public bool
GetItemAt (uint32 index, ItemType & returnItem) const
Copies the (index)'th item into (returnItem).
Returns true on success, false on failure (e.g. bad index)
- public ItemType *
GetItemPointer (uint32 index) const
Returns a pointer to an item in the array (i.e. no
copying of the item is done). Included for efficiency;
be careful with this, modifying the queue can invalidate
the returned pointer!
- public int32
IndexOf (const ItemType & item) const
Returns the index of the given (item), or -1 if (item) is
not found in the list. O(n) time.
- public bool
IsEmpty () const
Returns true iff the queue is empty.
- public void
MakeEmpty ()
Removes all items from the queue.
- public
PortableQueue (const PortableQueue& copyMe)
- public
PortableQueue (uint32 initialSize = 5)
(initialSize) specifies how many slots to pre-allocate. Defaults to five.
- public bool
RemoveHead ()
Removes the item at the head of the queue.
Returns true on success, false on failure (i.e. queue was empty)
- public bool
RemoveHead (ItemType & returnItem)
Removes the item at the head of the queue and places it into (returnItem).
Returns true on success, false on failure (i.e. queue was empty)
- public bool
RemoveItemAt (uint32 index)
Removes the item at the (index)'th position in the queue.
(index) can range from zero (head of the queue) to
(CountItems()-1) (tail of the queue).
Returns true on success, false on failure (i.e. bad index)
- public bool
RemoveItemAt (uint32 index, ItemType & returnItem)
Removes the item at the (index)'th position in the queue,
and places it into (returnItem).
(index) can range from zero (head of the queue) to
(CountItems()-1) (tail of the queue).
Returns true on success, false on failure (i.e. bad index)
- public bool
RemoveTail ()
Removes the item at the tail of the queue.
Returns true on success, false on failure (i.e. queue was empty)
- public bool
RemoveTail (ItemType & returnItem)
Removes the item at the tail of the queue and places it into (returnItem).
Returns true on success, false on failure (i.e. queue was empty)
- public bool
ReplaceItemAt (uint32 index, const ItemType & newItem)
Replaces the (index)'th item in the queue with (newItem).
Returns true on success, false on failure (e.g. bad index)
- public ItemType &
operator [] (uint32 Index)
Convenient array-style set operator (be sure to only use valid indices!)
- public ItemType
operator [] (uint32 Index) const
Convenient array-style get operator (be sure to only use valid indices!)
- public PortableQueue &
operator= (const PortableQueue &from)
- public virtual
~PortableQueue ()