Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

WvVector< T > Class Template Reference

#include <wvvector.h>

Inherits WvVectorBase.

Collaboration diagram for WvVector< T >:

[legend]
List of all members.

Detailed Description

template<class T>
class WvVector< T >

A dynamic array data structure with constant time lookup, linear time insertion / removal, and expected logarithmic time append.

Definition at line 83 of file wvvector.h.

Public Member Functions

 WvVector (bool _auto_free)
 Creates an empty vector.
 ~WvVector ()
 Destroys the vector and all of its contents.
Toperator[] (int slot)
 Dereferences a particular slot of the vector.
void zap ()
 Removes all elements from the vector.
void remove (int slot, bool never_delete=false)
void remove_last ()
 Removes the last element.
Tlast ()
void insert (int slot, T *elem)
void append (T *elem)
T ** ptr ()
int count () const
 Returns the number of elements actually stored in the vector.
bool isempty () const
 Returns true if the vector is empty.
int capacity () const
 The number of elements that could be stored without resizing.
void setcapacity (int newslots)
 Adjusts the capacity of the vector.
void compact ()
 Compacts the vector to minimize its footprint.

Protected Member Functions

int growcapacity (int minslots)
 Computes the number of slots needed to grow to at least minslots.
int shrinkcapacity (int maxslots)
 Computes the number of slots needed to shrink down to maxslots.
void moveelems (void *dst, void *src, int nelems)
 A shorthand for memmove() with size adjustment.
void remove (int slot)
 Removes the element at the specified slot.
void insert (int slot, void *elem)
 Inserts an element at the specified slot.
void append (void *elem)
 Appends an element onto the tail of the vector.

Protected Attributes

void ** xseq
int xcount
int xslots
bool auto_free

Static Protected Attributes

const int MINALLOC = 4


Constructor & Destructor Documentation

template<class T>
WvVector< T >::WvVector bool  _auto_free  )  [inline]
 

Creates an empty vector.

Definition at line 87 of file wvvector.h.

template<class T>
WvVector< T >::~WvVector  )  [inline]
 

Destroys the vector and all of its contents.

Definition at line 91 of file wvvector.h.

References WvVector< T >::zap().


Member Function Documentation

void WvVectorBase::append void *  elem  )  [protected, inherited]
 

Appends an element onto the tail of the vector.

Definition at line 56 of file wvvector.cc.

References WvVectorBase::growcapacity(), WvVectorBase::setcapacity(), WvVectorBase::xcount, and WvVectorBase::xseq.

Referenced by WvVector< T >::append().

template<class T>
void WvVector< T >::append T elem  )  [inline]
 

Definition at line 133 of file wvvector.h.

References WvVectorBase::append().

int WvVectorBase::capacity  )  const [inline, inherited]
 

The number of elements that could be stored without resizing.

Definition at line 60 of file wvvector.h.

void WvVectorBase::compact  )  [inline, inherited]
 

Compacts the vector to minimize its footprint.

Definition at line 72 of file wvvector.h.

int WvVectorBase::count  )  const [inline, inherited]
 

Returns the number of elements actually stored in the vector.

Definition at line 52 of file wvvector.h.

Referenced by WvVector< T >::Iter::cur().

int WvVectorBase::growcapacity int  minslots  )  [protected, inherited]
 

Computes the number of slots needed to grow to at least minslots.

Definition at line 19 of file wvvector.cc.

References WvVectorBase::xslots.

Referenced by WvVectorBase::append(), and WvVectorBase::insert().

void WvVectorBase::insert int  slot,
void *  elem
[protected, inherited]
 

Inserts an element at the specified slot.

Definition at line 47 of file wvvector.cc.

References WvVectorBase::growcapacity(), WvVectorBase::moveelems(), WvVectorBase::setcapacity(), WvVectorBase::xcount, and WvVectorBase::xseq.

Referenced by WvVector< T >::insert().

template<class T>
void WvVector< T >::insert int  slot,
T elem
[inline]
 

Definition at line 130 of file wvvector.h.

References WvVectorBase::insert().

bool WvVectorBase::isempty  )  const [inline, inherited]
 

Returns true if the vector is empty.

Definition at line 56 of file wvvector.h.

template<class T>
T* WvVector< T >::last  )  [inline]
 

Definition at line 127 of file wvvector.h.

void WvVectorBase::moveelems void *  dst,
void *  src,
int  nelems
[inline, protected, inherited]
 

A shorthand for memmove() with size adjustment.

Definition at line 38 of file wvvector.h.

Referenced by WvVectorBase::insert(), WvVectorBase::remove(), and WvVectorBase::setcapacity().

template<class T>
T* WvVector< T >::operator[] int  slot  )  [inline]
 

Dereferences a particular slot of the vector.

Definition at line 95 of file wvvector.h.

References WvVector< T >::ptr().

template<class T>
T** WvVector< T >::ptr  )  [inline]
 

Definition at line 137 of file wvvector.h.

Referenced by WvVector< T >::operator[](), and WvVector< T >::zap().

void WvVectorBase::remove int  slot  )  [protected, inherited]
 

Removes the element at the specified slot.

Definition at line 39 of file wvvector.cc.

References WvVectorBase::moveelems(), WvVectorBase::setcapacity(), WvVectorBase::shrinkcapacity(), WvVectorBase::xcount, and WvVectorBase::xseq.

Referenced by WvVector< T >::remove().

template<class T>
void WvVector< T >::remove int  slot,
bool  never_delete = false
[inline]
 

Definition at line 115 of file wvvector.h.

References WvVectorBase::remove().

Referenced by WvVector< T >::remove_last().

template<class T>
void WvVector< T >::remove_last  )  [inline]
 

Removes the last element.

Definition at line 124 of file wvvector.h.

References WvVector< T >::remove().

void WvVectorBase::setcapacity int  newslots  )  [inherited]
 

Adjusts the capacity of the vector.

If the new capacity is greater than the old one, extends the array size without actually filling in any elements.

Definition at line 64 of file wvvector.cc.

References WvVectorBase::moveelems(), WvVectorBase::xcount, WvVectorBase::xseq, and WvVectorBase::xslots.

Referenced by WvVectorBase::append(), WvVectorBase::insert(), and WvVectorBase::remove().

int WvVectorBase::shrinkcapacity int  maxslots  )  [protected, inherited]
 

Computes the number of slots needed to shrink down to maxslots.

Definition at line 29 of file wvvector.cc.

Referenced by WvVectorBase::remove().

template<class T>
void WvVector< T >::zap  )  [inline]
 

Removes all elements from the vector.

Definition at line 99 of file wvvector.h.

References WvVector< T >::ptr().

Referenced by WvVector< T >::~WvVector().


Member Data Documentation

bool WvVectorBase::auto_free [protected, inherited]
 

whether to auto-delete the elements when removed

Definition at line 26 of file wvvector.h.

Referenced by WvVectorBase::WvVectorBase().

const int WvVectorBase::MINALLOC = 4 [static, protected, inherited]
 

the minimum number of slots to allocate

Definition at line 20 of file wvvector.h.

int WvVectorBase::xcount [protected, inherited]
 

the number of elements in the sequence

Definition at line 24 of file wvvector.h.

Referenced by WvVectorBase::append(), WvVectorBase::insert(), WvVectorBase::remove(), WvVectorBase::setcapacity(), and WvVectorBase::WvVectorBase().

void** WvVectorBase::xseq [protected, inherited]
 

the controlled sequence

Definition at line 23 of file wvvector.h.

Referenced by WvVectorBase::append(), WvVectorBase::insert(), WvVectorBase::remove(), WvVectorBase::setcapacity(), and WvVectorBase::WvVectorBase().

int WvVectorBase::xslots [protected, inherited]
 

the capacity of the array

Definition at line 25 of file wvvector.h.

Referenced by WvVectorBase::growcapacity(), WvVectorBase::setcapacity(), and WvVectorBase::WvVectorBase().


The documentation for this class was generated from the following file:
Generated on Wed Dec 15 15:08:27 2004 for WvStreams by  doxygen 1.3.9.1