dlvhex  2.5.0
Set< T > Class Template Reference

Data structure for storing sets based on a sorted array. More...

#include <include/dlvhex2/Set.h>

Inheritance diagram for Set< T >:
Collaboration diagram for Set< T >:

Public Types

typedef set_iterator< T > iterator
typedef const_set_iterator< T > const_iterator
typedef T value_type
typedef const T & const_reference

Public Member Functions

 Set (int initialSize=0, int inc=10)
 Constructor.
 Set (const Set< T > &s2)
 Copy-constructor.
virtual ~Set ()
 Destructor.
bool contains (T e) const
 Checks if an element is contained in the set.
int count (T e) const
 Retrieves the size of the Set.
void insert (T e)
 Adds an element to the Set.
template<typename _Iter >
void insert (_Iter begin, _Iter end)
 Inserts a range of elements given by a pair of begin and end iterator.
void erase (T e)
 Removes an element from the Set if contained.
set_iterator< T > find (T e)
 Searches for an element in the Set.
const_set_iterator< T > find (T e) const
 Searches for an element in the Set.
bool empty () const
 Checks if the Set is empty.
void clear ()
 Empties the Set.
set_iterator< T > begin ()
 Retruns the begin iterator of the Set.
set_iterator< T > end ()
 Retruns the end iterator of the Set.
const_set_iterator< T > begin () const
 Retruns the const begin iterator of the Set.
const_set_iterator< T > end () const
 Retruns the const end iterator of the Set.
T & operator[] (int i)
 Accesses an element given by its index.
const T & operator[] (int i) const
 Accesses an element given by its index.
int size () const
 Retrieves the size of the Set.
T * getData ()
 Retrieves the internal data (array).
const T * getData () const
 Retrieves the internal data (array).
Set< T > & operator= (const Set< T > &s2)
 Assigns another Set to this one.

Private Member Functions

void grow ()
 Grows Set::data such that it covers Set::allocSize.
void grow (int minSize)
 Grows Set::data such that it covers a given minimum size.
int binarySearch (T e) const
 Implements binary search for the set.

Private Attributes

T * data
int allocSize
int rsize
int increase

Detailed Description

template<typename T>
class Set< T >

Data structure for storing sets based on a sorted array.

Definition at line 237 of file Set.h.


Member Typedef Documentation

template<typename T>
typedef const_set_iterator<T> Set< T >::const_iterator

Definition at line 300 of file Set.h.

template<typename T>
typedef const T& Set< T >::const_reference

Definition at line 302 of file Set.h.

template<typename T>
typedef set_iterator<T> Set< T >::iterator

Definition at line 299 of file Set.h.

template<typename T>
typedef T Set< T >::value_type

Definition at line 301 of file Set.h.


Constructor & Destructor Documentation

template<typename T>
Set< T >::Set ( int  initialSize = 0,
int  inc = 10 
) [inline]

Constructor.

Parameters:
initialSizeInternal size of the internal array.
incNumber of elements to add when the internal array needs to be resized.

Definition at line 307 of file Set.h.

template<typename T>
Set< T >::Set ( const Set< T > &  s2) [inline]

Copy-constructor.

Parameters:
s2Second set.

Definition at line 319 of file Set.h.

template<typename T>
virtual Set< T >::~Set ( ) [inline, virtual]

Destructor.

Definition at line 328 of file Set.h.


Member Function Documentation

template<typename T>
const_set_iterator<T> Set< T >::begin ( ) const [inline]

Retruns the const begin iterator of the Set.

Returns:
Const begin iterator of the Set.

Definition at line 451 of file Set.h.

template<typename T>
int Set< T >::binarySearch ( e) const [inline, private]

Implements binary search for the set.

Parameters:
eElement to search for.
Returns:
Index of e in the Set or 0 if it is not contained.

Definition at line 265 of file Set.h.

Referenced by Set< IDAddress >::contains(), Set< IDAddress >::erase(), Set< IDAddress >::find(), and Set< IDAddress >::insert().

template<typename T>
bool Set< T >::contains ( e) const [inline]

Checks if an element is contained in the set.

Parameters:
eElement to search for.
Returns:
True if e is contained in the Set and false otherwise.

Definition at line 336 of file Set.h.

Referenced by CDNLSolver::addNogoodAndUpdateWatchingStructures(), Set< IDAddress >::count(), ExternalLearningHelper::learnFromInputOutputBehavior(), and InternalGroundASPSolver::restartWithAssumptions().

template<typename T>
bool Set< T >::empty ( ) const [inline]

Checks if the Set is empty.

Returns:
True if the Set is empty and false otherwise.

Definition at line 427 of file Set.h.

template<typename T>
const_set_iterator<T> Set< T >::end ( ) const [inline]

Retruns the const end iterator of the Set.

Returns:
Const end iterator of the Set.

Definition at line 458 of file Set.h.

template<typename T>
set_iterator<T> Set< T >::find ( e) [inline]

Searches for an element in the Set.

Parameters:
eElement to search for.
Returns:
Iterator pointing to e if contained and the end() iterator otherwise.

Definition at line 401 of file Set.h.

template<typename T>
const_set_iterator<T> Set< T >::find ( e) const [inline]

Searches for an element in the Set.

Parameters:
eElement to search for.
Returns:
Const iterator pointing to e if contained and the end() iterator otherwise.

Definition at line 414 of file Set.h.

template<typename T>
T* Set< T >::getData ( ) [inline]

Retrieves the internal data (array).

Returns:
Pointer to the begin of the internal array.

Definition at line 489 of file Set.h.

template<typename T>
const T* Set< T >::getData ( ) const [inline]

Retrieves the internal data (array).

Returns:
Pointer to the begin of the internal array.

Definition at line 495 of file Set.h.

template<typename T>
void Set< T >::grow ( ) [inline, private]

Grows Set::data such that it covers Set::allocSize.

Definition at line 247 of file Set.h.

Referenced by Set< IDAddress >::insert(), and Set< IDAddress >::operator=().

template<typename T>
void Set< T >::grow ( int  minSize) [inline, private]

Grows Set::data such that it covers a given minimum size.

Parameters:
minSizeMinimum size of the Set after this method retuns.

Definition at line 255 of file Set.h.

template<typename T>
template<typename _Iter >
void Set< T >::insert ( _Iter  begin,
_Iter  end 
) [inline]

Inserts a range of elements given by a pair of begin and end iterator.

Parameters:
beginBegin iterator.
endEnd iterator.

Definition at line 375 of file Set.h.

template<typename T>
Set<T>& Set< T >::operator= ( const Set< T > &  s2) [inline]

Assigns another Set to this one.

Parameters:
s2Second Set.
Returns:
Reference to this Set.

Definition at line 503 of file Set.h.

template<typename T>
T& Set< T >::operator[] ( int  i) [inline]

Accesses an element given by its index.

Parameters:
iIndex of the element to access.
Returns:
Reference to element i in the Set.

Definition at line 466 of file Set.h.

template<typename T>
const T& Set< T >::operator[] ( int  i) const [inline]

Accesses an element given by its index.

Parameters:
iIndex of the element to access.
Returns:
Reference to element i in the Set.

Definition at line 473 of file Set.h.


Field Documentation

template<typename T>
int Set< T >::allocSize [private]

Definition at line 242 of file Set.h.

Referenced by Set< IDAddress >::grow(), Set< IDAddress >::insert(), and Set< IDAddress >::Set().

template<typename T>
int Set< T >::increase [private]

Definition at line 244 of file Set.h.

Referenced by Set< IDAddress >::grow(), and Set< IDAddress >::Set().


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