Open
Graph Drawing
Framework

 v.2007.11
 

ogdf::ArrayBuffer< E, INDEX > Class Template Reference

An array that keeps track of the number of inserted elements; also usable as an efficient stack. More...

#include <ArrayBuffer.h>

Inheritance diagram for ogdf::ArrayBuffer< E, INDEX >:

ogdf::Array< E, INDEX >

List of all members.

Public Member Functions

 ArrayBuffer ()
 Constructs an empty ArrayBuffer, without initial memory allocation.
 ArrayBuffer (INDEX size)
 Constructs an empty ArrayBuffer, allocating memory for up to size elements.
void init ()
 Reinitializes the array, clearing it, and without initial memory allocation.
void init (INDEX size)
 Reinitializes the array, clearing it, and allocating memory for up to size elements.
void clear ()
 Clears the buffer.
const E & top () const
 Returns the newest element of the buffer.
E & top ()
 Returns the newest element of the buffer.
void push (E e)
 Puts a new element in the buffer.
void pop ()
 Removes the newest element from the buffer.
popRet ()
 Removes the newest element from the buffer and returns it.
bool empty () const
 Returns true if the buffer is empty, false otherwise.
INDEX size () const
 Returns number of elements in the buffer.
const E & operator[] (INDEX i) const
 Returns a reference to the element at position i.
E & operator[] (INDEX i)
 Returns a reference to the element at position i.
void compactCopy (Array< E, INDEX > &A2) const
 Generates a compact copy holding the current elements.
void compactCpycon (Array< E, INDEX > &A2) const
 Generates a compact copy holding the current elements.
void compactMemcpy (Array< E, INDEX > &A2) const
 Generates a compact copy holding the current elements.
INDEX linearSearch (const E &x) const
 Performs a linear search for element x.
INDEX linearSearch (const E &x, Comparer< E > &comp) const
 Performs a linear search for element x with comparer comp.

Private Attributes

INDEX num
 The number of elements in te buffer.


Detailed Description

template<class E, class INDEX = int>
class ogdf::ArrayBuffer< E, INDEX >

An array that keeps track of the number of inserted elements; also usable as an efficient stack.

This is a growable array (with some initial size s) which starts out being empty. Using stack functions you can put elements into and out of it. The initial array size is automatically expanded if neccessary, but never automatically shrunken. You may also access the elements it contains using the []-operator. Tha valid indices are 0..(s - 1).

Definition at line 69 of file ArrayBuffer.h.


Constructor & Destructor Documentation

template<class E, class INDEX = int>
ogdf::ArrayBuffer< E, INDEX >::ArrayBuffer (  )  [inline]

Constructs an empty ArrayBuffer, without initial memory allocation.

Definition at line 73 of file ArrayBuffer.h.

template<class E, class INDEX = int>
ogdf::ArrayBuffer< E, INDEX >::ArrayBuffer ( INDEX  size  )  [inline, explicit]

Constructs an empty ArrayBuffer, allocating memory for up to size elements.

Definition at line 75 of file ArrayBuffer.h.


Member Function Documentation

template<class E, class INDEX = int>
void ogdf::ArrayBuffer< E, INDEX >::init (  )  [inline]

Reinitializes the array, clearing it, and without initial memory allocation.

Reimplemented from ogdf::Array< E, INDEX >.

Definition at line 78 of file ArrayBuffer.h.

template<class E, class INDEX = int>
void ogdf::ArrayBuffer< E, INDEX >::init ( INDEX  size  )  [inline]

Reinitializes the array, clearing it, and allocating memory for up to size elements.

Reimplemented from ogdf::Array< E, INDEX >.

Definition at line 80 of file ArrayBuffer.h.

template<class E, class INDEX = int>
void ogdf::ArrayBuffer< E, INDEX >::clear (  )  [inline]

Clears the buffer.

Definition at line 83 of file ArrayBuffer.h.

template<class E, class INDEX = int>
const E& ogdf::ArrayBuffer< E, INDEX >::top (  )  const [inline]

Returns the newest element of the buffer.

Definition at line 86 of file ArrayBuffer.h.

template<class E, class INDEX = int>
E& ogdf::ArrayBuffer< E, INDEX >::top (  )  [inline]

Returns the newest element of the buffer.

Definition at line 88 of file ArrayBuffer.h.

template<class E, class INDEX = int>
void ogdf::ArrayBuffer< E, INDEX >::push ( e  )  [inline]

Puts a new element in the buffer.

Definition at line 91 of file ArrayBuffer.h.

template<class E, class INDEX = int>
void ogdf::ArrayBuffer< E, INDEX >::pop (  )  [inline]

Removes the newest element from the buffer.

Definition at line 98 of file ArrayBuffer.h.

template<class E, class INDEX = int>
E ogdf::ArrayBuffer< E, INDEX >::popRet (  )  [inline]

Removes the newest element from the buffer and returns it.

Definition at line 100 of file ArrayBuffer.h.

template<class E, class INDEX = int>
bool ogdf::ArrayBuffer< E, INDEX >::empty (  )  const [inline]

Returns true if the buffer is empty, false otherwise.

Definition at line 103 of file ArrayBuffer.h.

template<class E, class INDEX = int>
INDEX ogdf::ArrayBuffer< E, INDEX >::size (  )  const [inline]

Returns number of elements in the buffer.

Reimplemented from ogdf::Array< E, INDEX >.

Definition at line 106 of file ArrayBuffer.h.

template<class E, class INDEX = int>
const E& ogdf::ArrayBuffer< E, INDEX >::operator[] ( INDEX  i  )  const [inline]

Returns a reference to the element at position i.

Reimplemented from ogdf::Array< E, INDEX >.

Definition at line 109 of file ArrayBuffer.h.

template<class E, class INDEX = int>
E& ogdf::ArrayBuffer< E, INDEX >::operator[] ( INDEX  i  )  [inline]

Returns a reference to the element at position i.

Reimplemented from ogdf::Array< E, INDEX >.

Definition at line 114 of file ArrayBuffer.h.

template<class E, class INDEX = int>
void ogdf::ArrayBuffer< E, INDEX >::compactCopy ( Array< E, INDEX > &  A2  )  const [inline]

Generates a compact copy holding the current elements.

Creates a copy of the ArrayBuffer and stores it into the given Array A. A has exactly the neccessary size to hold all elements in the buffer.

This method uses an elementwise operator=. If you need a bitcopy of the buffer, use compactMemcpy instead; if you need a traditional array copy (using the Array's copy-constructor) use compactCpyCon instead.

Definition at line 131 of file ArrayBuffer.h.

template<class E, class INDEX = int>
void ogdf::ArrayBuffer< E, INDEX >::compactCpycon ( Array< E, INDEX > &  A2  )  const [inline]

Generates a compact copy holding the current elements.

Creates a copy of the ArrayBuffer and stores it into the given Array A. A has exactly the neccessary size to hold all elements in the buffer.

This method uses the Array's copy constructur. If you need a bitcopy of the buffer, use compactMemcpy instead; if you neeed a elementwise operator=-copy, use compactCopy instead.

Definition at line 153 of file ArrayBuffer.h.

template<class E, class INDEX = int>
void ogdf::ArrayBuffer< E, INDEX >::compactMemcpy ( Array< E, INDEX > &  A2  )  const [inline]

Generates a compact copy holding the current elements.

Creates a copy of the ArrayBuffer and stores it into the given Array A. A has exactly the neccessary size to hold all elements in the buffer.

This method uses memcpy. If you need a traditional arraycopy using a copy constructur, use compactCopy instead; if you neeed a elementwise operator=-copy, use compactCopy instead.

Definition at line 176 of file ArrayBuffer.h.

template<class E, class INDEX = int>
INDEX ogdf::ArrayBuffer< E, INDEX >::linearSearch ( const E &  x  )  const [inline]

Performs a linear search for element x.

Warning: linear running time! Note that the linear search runs from back to front.

Returns:
the index of the found element, and low()-1 if not found.

Reimplemented from ogdf::Array< E, INDEX >.

Definition at line 191 of file ArrayBuffer.h.

template<class E, class INDEX = int>
INDEX ogdf::ArrayBuffer< E, INDEX >::linearSearch ( const E &  x,
Comparer< E > &  comp 
) const [inline]

Performs a linear search for element x with comparer comp.

Warning: linear running time! Note that the linear search runs from back to front.

Returns:
the index of the found element, and low()-1 if not found.

Reimplemented from ogdf::Array< E, INDEX >.

Definition at line 205 of file ArrayBuffer.h.


Member Data Documentation

template<class E, class INDEX = int>
INDEX ogdf::ArrayBuffer< E, INDEX >::num [private]

The number of elements in te buffer.

Definition at line 70 of file ArrayBuffer.h.


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

© 1999-2007 by oreas GmbH, © 2005-2007 by University Dortmund and University Cologne.

Generated on Thu Nov 22 19:40:07 2007 by doxygen 1.5.4.