WvVector< T > Class Template Reference

#include <wvvector.h>

Inheritance 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 253 of file wvvector.h.


Public Types

typedef int(* comparison_type_fn_t )(const T *, const T *)
 Runs the C qsort() routine over the vector, as long as the vector is big enough.

Public Member Functions

 WvVector ()
 Creates an empty vector.
 WvVector (int slots)
 Creates an empty vector, but initialises a new number of default slots.
 ~WvVector ()
 Destroys the vector and all of its contents.
T * operator[] (int slot)
 Dereferences a particular slot of the vector.
const T * operator[] (int slot) const
T * first ()
 Returns the first element.
T * last ()
 Returns the last element.
void remove (int slot, bool destroy=true)
 Removes a particular slot from the vector.
void remove_last (bool destroy=true)
 Removes the last element.
void zap (bool destroy=true)
 Removes all elements from the vector.
void insert (int slot, T *elem, bool autofree)
 Insert an element into a slot, and shifts the others to the right.
void prepend (T *elem, bool autofree)
 Prepends an element to the start of the vector.
void append (T *elem, bool autofree)
 Appends an element to the end of the vector.
void qsort (comparison_type_fn_t comparator)
int count () const
 Returns the number of elements actually stored in the vector.
bool isempty () const
 Returns true if the vector is empty.
int get_capacity () const
 The number of elements that could be stored without resizing.
void set_capacity (int newslots)
 Adjusts the capacity of the vector.
void compact ()
 Compacts the vector to minimize its footprint.

Protected Types

typedef int(* comparison_type_t )(const void *, const void *)

Protected Member Functions

void remove (int slot)
 Removes the element at the specified slot.
void insert (int slot, WvLink *elem)
 Inserts an element at the specified slot.
void prepend (WvLink *elem)
 Prepend an element onto the front of the vector.
void append (WvLink *elem)
 Appends an element onto the tail of the vector.
bool get_autofree (int slot)
 Gets autofree for the specified slot.
void set_autofree (int slot, bool autofree)
 Sets autofree for the specified slot.

Static Protected Member Functions

static int wrapcomparator (const void *_a, const void *_b)

Protected Attributes

WvLink ** xseq
int xcount
int xslots

Static Protected Attributes

static const int DEFAULTSIZE = 4

Friends

class IterBase

Classes

class  Iter
 A simple iterator that walks through all elements in the list. More...

Member Typedef Documentation

template<class T>
typedef int(* WvVector< T >::comparison_type_fn_t)(const T *, const T *)

Runs the C qsort() routine over the vector, as long as the vector is big enough.

It uses comparator like qsort() does to figure out the order of the operators.


Constructor & Destructor Documentation

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

Creates an empty vector.

Definition at line 257 of file wvvector.h.

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

Destroys the vector and all of its contents.

Definition at line 272 of file wvvector.h.


Member Function Documentation

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

Dereferences a particular slot of the vector.

Definition at line 278 of file wvvector.h.

template<class T>
void WvVector< T >::remove ( int  slot,
bool  destroy = true 
) [inline]

Removes a particular slot from the vector.

Definition at line 312 of file wvvector.h.

template<class T>
void WvVector< T >::zap ( bool  destroy = true  )  [inline]

Removes all elements from the vector.

Definition at line 334 of file wvvector.h.

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

template<class T>
void WvVector< T >::insert ( int  slot,
T *  elem,
bool  autofree 
) [inline]

Insert an element into a slot, and shifts the others to the right.

Definition at line 341 of file wvvector.h.

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

Removes the element at the specified slot.

Definition at line 18 of file wvvector.cc.

References WvVectorBase::xcount, and WvVectorBase::xseq.

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

void WvVectorBase::insert ( int  slot,
WvLink elem 
) [protected, inherited]

Inserts an element at the specified slot.

Definition at line 26 of file wvvector.cc.

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

Referenced by WvVector< UniConf >::insert(), and WvVectorBase::prepend().

void WvVectorBase::prepend ( WvLink elem  )  [inline, protected, inherited]

Prepend an element onto the front of the vector.

Definition at line 50 of file wvvector.h.

References WvVectorBase::insert().

Referenced by WvVector< UniConf >::prepend().

void WvVectorBase::append ( WvLink elem  )  [protected, inherited]

Appends an element onto the tail of the vector.

Definition at line 41 of file wvvector.cc.

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

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

bool WvVectorBase::get_autofree ( int  slot  )  [inline, protected, inherited]

Gets autofree for the specified slot.

Definition at line 59 of file wvvector.h.

References WvLink::get_autofree(), WvVectorBase::xcount, and WvVectorBase::xseq.

void WvVectorBase::set_autofree ( int  slot,
bool  autofree 
) [inline, protected, inherited]

Sets autofree for the specified slot.

Definition at line 67 of file wvvector.h.

References WvLink::set_autofree(), WvVectorBase::xcount, and WvVectorBase::xseq.

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

Returns the number of elements actually stored in the vector.

Definition at line 98 of file wvvector.h.

References WvVectorBase::xcount.

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

Returns true if the vector is empty.

Definition at line 104 of file wvvector.h.

References WvVectorBase::xcount.

int WvVectorBase::get_capacity (  )  const [inline, inherited]

The number of elements that could be stored without resizing.

Definition at line 110 of file wvvector.h.

References WvVectorBase::xslots.

void WvVectorBase::set_capacity ( 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 53 of file wvvector.cc.

References WvVectorBase::xcount, WvVectorBase::xseq, and WvVectorBase::xslots.

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

void WvVectorBase::compact (  )  [inline, inherited]

Compacts the vector to minimize its footprint.

Definition at line 124 of file wvvector.h.

References WvVectorBase::set_capacity(), and WvVectorBase::xcount.


Member Data Documentation

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

the minimum number of slots to allocate

Definition at line 26 of file wvvector.h.

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

int WvVectorBase::xcount [protected, inherited]

int WvVectorBase::xslots [protected, inherited]

the capacity of the array

Definition at line 31 of file wvvector.h.

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


The documentation for this class was generated from the following file:

Generated on Sat Feb 7 13:37:25 2009 for WvStreams by  doxygen 1.5.6