Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  
Public Member Functions | Private Attributes

SgVector< T > Class Template Reference

#include <SgVector.h>

List of all members.

Public Member Functions

 SgVector ()
 Construct empty vector.
T & operator[] (int index)
 Return reference to element.
const T & operator[] (int index) const
 Return const reference to element.
SgVector< T > & operator= (const SgVector< T > &v)
 Assignment operator.
bool operator== (const SgVector< T > &rhs) const
 Compare whether the contents of two vectors are identical.
bool operator!= (const SgVector &rhs) const
 Compare whether the contents of two vectors are not identical.
const T & Back () const
 Returns the last element of the vector.
BackAndPop ()
void Clear ()
 Remove all elements in this vector.
void Concat (SgVector< T > *tail)
 Push all of *tail to the back of this vector, and clear the *tail vector.
bool Contains (const T &elt) const
 Check if element is in vector.
void DeleteAt (int index)
 delete element at specified index
bool Exclude (const T &elt)
 Remove the first occurence of element.
void Exclude (const SgVector< T > &vector)
 Exclude each element of vector from this vector.
const T & Front () const
 Returns the first element of the vector.
int Index (const T &elt) const
 Find position of element.
void Include (const T &elt)
 Push elt to the back of the vector only if it is not included yet.
bool Insert (const T &elt)
 Includes the element in a ascending sorted vector at the right place.
bool IsEmpty () const
 Return whether this vector contains zero elements.
bool IsLength (int length) const
 Test whether a vector is as long as a given length.
bool IsSorted (bool ascending=true) const
 Returns whether the vector is sorted in given order.
bool IsSortedAndUnique (bool ascending=true) const
 Returns whether the vector is sorted and has no duplicates.
int Length () const
 Return the number of elements in this vector.
void LimitListLength (int limit)
 Cut off vector after at most length elements.
bool MaxLength (int length) const
 Test whether a vector is shorter than or equal to a given length.
void Merge (const SgVector< T > &vector)
 Merges two sorted vectors into this.
bool MinLength (int length) const
 Test whether a vector is as long as or longer than a given length.
bool NonEmpty () const
 Return whether this vector contains more than zero elements.
PopFront ()
 Remove element[0] of the vector.
void PopBack ()
 Remove the last element of the vector.
void PushFront (const T &elt)
 Insert element at the beginning of the vector.
void PushBack (const T &elt)
 Add a single element at the end of the vector.
void PushBackList (const SgVector< T > &vector)
 Push all elements from vector to the back of this.
bool RemoveDuplicates ()
 Removes all but the first copy of each element from the vector.
void Reverse ()
void SetTo (const T &elt)
 Clear this vector and set it to contain only elt.
bool SetsAreEqual (const SgVector< T > &other) const
 Do vectors contain the same elements, possibly in different order?
void SetTo (const T *array, int count)
 Clear this vector and set it to contain the count elements from array[0] to array[count - 1].
void Sort ()
void SortedRemoveDuplicates ()
 remove duplicates in a sorted vector
void SwapWith (SgVector< T > *vector)
 Swap the entire contents of this vector with *vector.
const T & TopNth (int index) const
 Returns the Nth-last element of the vector.
void Union (const SgVector< T > &set)
 Include all elements from set into this vector.
bool UniqueElements () const
 Check for duplicate elements.
std::vector< T > & Vector ()
const std::vector< T > & Vector () const

Private Attributes

std::vector< T > m_vec

Detailed Description

template<typename T>
class SgVector< T >

Definition at line 17 of file SgVector.h.


Constructor & Destructor Documentation

template<typename T>
SgVector< T >::SgVector (  ) 

Construct empty vector.

Definition at line 21 of file SgVector.h.


Member Function Documentation

template<typename T>
const T& SgVector< T >::Back (  )  const

Returns the last element of the vector.

Asserts if the vector is empty.

Reimplemented in SgVectorOf< T >, SgVectorOf< SgProp >, and SgVectorOf< std::string >.

Definition at line 58 of file SgVector.h.

Referenced by SgVector< T >::Merge(), SgMiaiStrategy::OpenThreatMove(), SgIncrementalStack::PopInt(), SgIncrementalStack::PopPtr(), and SgSearch::PrevMove().

template<typename T>
T SgVector< T >::BackAndPop (  ) 

Definition at line 64 of file SgVector.h.

template<typename T>
void SgVector< T >::Clear (  ) 
template<typename T>
void SgVector< T >::Concat ( SgVector< T > *  tail  ) 

Push all of *tail to the back of this vector, and clear the *tail vector.

Remark: this operation is efficient for lists but not so meaningful for vectors. PushBackList may be more appropriate in most cases.

Definition at line 483 of file SgVector.h.

References SgVector< T >::Clear(), and SgVector< T >::PushBackList().

template<typename T>
bool SgVector< T >::Contains ( const T &  elt  )  const
template<typename T >
void SgVector< T >::DeleteAt ( int  index  ) 

delete element at specified index

Definition at line 498 of file SgVector.h.

References SgVector< T >::Length(), SgVector< T >::m_vec, and SG_ASSERT.

Referenced by SgPropTextList::ClearStringAtPoint().

template<typename T>
bool SgVector< T >::Exclude ( const T &  elt  ) 

Remove the first occurence of element.

If elt is in the vector, remove the first occurence of elt from the vector, and return true. Otherwise do nothing and return false.

Definition at line 506 of file SgVector.h.

References SgVector< T >::m_vec.

Referenced by SgVectorUtil::Difference(), SgVector< T >::Exclude(), and SgMiaiStrategy::ExecuteMove().

template<typename T>
void SgVector< T >::Exclude ( const SgVector< T > &  vector  ) 

Exclude each element of vector from this vector.

Definition at line 519 of file SgVector.h.

References SgVector< T >::Exclude().

template<typename T>
const T& SgVector< T >::Front (  )  const

Returns the first element of the vector.

Asserts if the vector is empty.

Reimplemented in SgVectorOf< T >, SgVectorOf< SgProp >, and SgVectorOf< std::string >.

Definition at line 104 of file SgVector.h.

Referenced by SgVector< T >::Merge(), and SgVector< T >::PopFront().

template<typename T>
void SgVector< T >::Include ( const T &  elt  ) 

Push elt to the back of the vector only if it is not included yet.

Definition at line 118 of file SgVector.h.

Referenced by SgVector< T >::Union().

template<typename T>
int SgVector< T >::Index ( const T &  elt  )  const

Find position of element.

Returns:
The position of elt in the vector, in range 0..length-1. Returns -1 if elt is not in the vector.

Definition at line 526 of file SgVector.h.

References SgVector< T >::m_vec.

Referenced by SgPropTextList::ClearStringAtPoint(), and SgPropTextList::GetStringAtPoint().

template<typename T>
bool SgVector< T >::Insert ( const T &  elt  ) 

Includes the element in a ascending sorted vector at the right place.

Does nothing and returns false if the element is already in the vector; returns true if the element is inserted.

Todo:
made two separate functions for efficiency, should be a template taking a compare template arg. Same for Merge() below.

Definition at line 537 of file SgVector.h.

References SgVector< T >::IsSorted(), SgVector< T >::m_vec, and SG_ASSERT.

template<typename T>
bool SgVector< T >::IsEmpty (  )  const
template<typename T>
bool SgVector< T >::IsLength ( int  length  )  const

Test whether a vector is as long as a given length.

Definition at line 140 of file SgVector.h.

Referenced by SgVector< T >::SetsAreEqual(), SgVector< T >::SetTo(), and SgMiaiStrategy::Status().

template<typename T >
bool SgVector< T >::IsSorted ( bool  ascending = true  )  const

Returns whether the vector is sorted in given order.

Definition at line 556 of file SgVector.h.

References SgVector< T >::m_vec.

Referenced by SgVector< T >::Insert(), SgVector< T >::SortedRemoveDuplicates(), and SgVector< T >::UniqueElements().

template<typename T >
bool SgVector< T >::IsSortedAndUnique ( bool  ascending = true  )  const

Returns whether the vector is sorted and has no duplicates.

Definition at line 567 of file SgVector.h.

References SgVector< T >::m_vec.

Referenced by SgVector< T >::Merge(), SgVector< T >::SortedRemoveDuplicates(), and SgVector< T >::UniqueElements().

template<typename T>
int SgVector< T >::Length (  )  const
template<typename T >
void SgVector< T >::LimitListLength ( int  limit  ) 

Cut off vector after at most length elements.

Definition at line 581 of file SgVector.h.

References SgVector< T >::Length(), and SgVector< T >::m_vec.

Referenced by SgVector< T >::SortedRemoveDuplicates().

template<typename T>
bool SgVector< T >::MaxLength ( int  length  )  const

Test whether a vector is shorter than or equal to a given length.

Definition at line 161 of file SgVector.h.

Referenced by SgMiaiStrategy::OpenThreatMove().

template<typename T>
void SgVector< T >::Merge ( const SgVector< T > &  vector  ) 

Merges two sorted vectors into this.

Equivalent to, but faster than:

        for (SgVectorIterator<T> it(vector); it; ++it)
            Insert(*it);
        

Definition at line 588 of file SgVector.h.

References SgVector< T >::Back(), SgVector< T >::Front(), SgVector< T >::IsEmpty(), SgVector< T >::IsSortedAndUnique(), SgVector< T >::Length(), SgVector< T >::m_vec, SgVector< T >::PushBackList(), SG_ASSERT, and SgVector< T >::SortedRemoveDuplicates().

template<typename T>
bool SgVector< T >::MinLength ( int  length  )  const

Test whether a vector is as long as or longer than a given length.

Definition at line 174 of file SgVector.h.

Referenced by SgVector< T >::UniqueElements().

template<typename T>
bool SgVector< T >::NonEmpty (  )  const
template<typename T>
bool SgVector< T >::operator!= ( const SgVector< T > &  rhs  )  const

Compare whether the contents of two vectors are not identical.

Definition at line 51 of file SgVector.h.

template<typename T>
SgVector< T > & SgVector< T >::operator= ( const SgVector< T > &  v  ) 

Assignment operator.

Copy content of other vector.

Definition at line 466 of file SgVector.h.

References SgVector< T >::Clear(), and SgVector< T >::PushBackList().

template<typename T>
bool SgVector< T >::operator== ( const SgVector< T > &  rhs  )  const

Compare whether the contents of two vectors are identical.

Same length, and the same elements in the same sequence.

Definition at line 45 of file SgVector.h.

template<typename T>
const T& SgVector< T >::operator[] ( int  index  )  const

Return const reference to element.

Parameters:
index Position of element in range 0..length-1.

Reimplemented in SgVectorOf< T >, SgVectorOf< SgProp >, and SgVectorOf< std::string >.

Definition at line 34 of file SgVector.h.

template<typename T>
T& SgVector< T >::operator[] ( int  index  ) 

Return reference to element.

Parameters:
index Position of element in range 0..length-1.

Definition at line 27 of file SgVector.h.

template<typename T >
void SgVector< T >::PopBack (  ) 

Remove the last element of the vector.

The vector must not be empty.

Definition at line 617 of file SgVector.h.

References SgVector< T >::m_vec, SgVector< T >::NonEmpty(), and SG_ASSERT.

Referenced by SgVector< void * >::BackAndPop(), SgSearch::CallTakeBack(), SgIncrementalStack::PopInt(), and SgIncrementalStack::PopPtr().

template<typename T >
T SgVector< T >::PopFront (  ) 

Remove element[0] of the vector.

The vector must not be empty.

Returns:
The element[0] of the original vector before removal.
Deprecated:
Don't use this function; it is slow. Only exists for SgList compatibility.

Reimplemented in SgVectorOf< T >, SgVectorOf< SgProp >, and SgVectorOf< std::string >.

Definition at line 608 of file SgVector.h.

References SgVector< T >::Front(), SgVector< T >::m_vec, SgVector< T >::NonEmpty(), and SG_ASSERT.

template<typename T>
void SgVector< T >::PushBack ( const T &  elt  ) 
template<typename T>
void SgVector< T >::PushBackList ( const SgVector< T > &  vector  ) 

Push all elements from vector to the back of this.

Definition at line 477 of file SgVector.h.

References SgVector< T >::m_vec.

Referenced by SgVector< T >::Concat(), SgVector< T >::Merge(), and SgVector< T >::operator=().

template<typename T>
void SgVector< T >::PushFront ( const T &  elt  ) 

Insert element at the beginning of the vector.

Deprecated:
Don't use this function; it is slow. Only exists for SgList compatibility.

Definition at line 624 of file SgVector.h.

References SgVector< T >::m_vec.

template<typename T >
bool SgVector< T >::RemoveDuplicates (  ) 

Removes all but the first copy of each element from the vector.

After calling RemoveDuplicates(), UniqueElements() is true.

Returns:
true, if at least one duplicate was removed

Definition at line 669 of file SgVector.h.

References SgVector< T >::Contains(), SgVector< T >::Length(), SgVector< T >::PushBack(), SG_ASSERT, SgVector< T >::SwapWith(), and SgVector< T >::UniqueElements().

template<typename T>
void SgVector< T >::Reverse (  ) 

Definition at line 217 of file SgVector.h.

template<typename T>
bool SgVector< T >::SetsAreEqual ( const SgVector< T > &  other  )  const

Do vectors contain the same elements, possibly in different order?

Definition at line 630 of file SgVector.h.

References SgVector< T >::Contains(), SgVector< T >::IsLength(), and SgVector< T >::Length().

template<typename T>
void SgVector< T >::SetTo ( const T &  elt  ) 

Clear this vector and set it to contain only elt.

Definition at line 223 of file SgVector.h.

Referenced by SgSortedArray< T, K, size >::GetElements(), and SgSortedArray< T, K, size >::GetKeys().

template<typename T>
void SgVector< T >::SetTo ( const T *  array,
int  count 
)

Clear this vector and set it to contain the count elements from array[0] to array[count - 1].

If count is zero, the vector is just cleared.

Definition at line 649 of file SgVector.h.

References SgVector< T >::IsLength(), SgVector< T >::m_vec, and SG_ASSERT.

template<typename T >
void SgVector< T >::Sort (  ) 

Definition at line 656 of file SgVector.h.

References SgVector< T >::m_vec.

template<typename T >
void SgVector< T >::SortedRemoveDuplicates (  ) 
template<typename T>
void SgVector< T >::SwapWith ( SgVector< T > *  vector  ) 

Swap the entire contents of this vector with *vector.

Definition at line 244 of file SgVector.h.

Referenced by SgVectorUtil::Intersection(), and SgVector< T >::RemoveDuplicates().

template<typename T>
const T& SgVector< T >::TopNth ( int  index  )  const

Returns the Nth-last element of the vector.

It must exist.

Definition at line 250 of file SgVector.h.

Referenced by SgSearch::PrevMove2().

template<typename T>
void SgVector< T >::Union ( const SgVector< T > &  set  ) 

Include all elements from set into this vector.

Appends new elements at the end of this vector.

Definition at line 662 of file SgVector.h.

References SgVector< T >::Include().

template<typename T >
bool SgVector< T >::UniqueElements (  )  const

Check for duplicate elements.

Returns:
true if there are no duplicate elements in the vector. Useful for debugging.
Todo:
speed it up

Definition at line 705 of file SgVector.h.

References SgVector< T >::IsSorted(), SgVector< T >::IsSortedAndUnique(), SgVector< T >::Length(), SgVector< T >::m_vec, and SgVector< T >::MinLength().

Referenced by SgVector< T >::RemoveDuplicates().

template<typename T>
std::vector<T>& SgVector< T >::Vector (  ) 

Definition at line 269 of file SgVector.h.

template<typename T>
const std::vector<T>& SgVector< T >::Vector (  )  const

Definition at line 274 of file SgVector.h.


Member Data Documentation

template<typename T>
std::vector<T> SgVector< T >::m_vec [private]

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


Sun Mar 13 2011 Doxygen 1.7.1