#include <SgVector.h>
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. | |
T | 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. | |
T | 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 |
Definition at line 17 of file SgVector.h.
Construct empty vector.
Definition at line 21 of file SgVector.h.
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().
T SgVector< T >::BackAndPop | ( | ) |
Definition at line 64 of file SgVector.h.
void SgVector< T >::Clear | ( | ) |
Remove all elements in this vector.
Definition at line 73 of file SgVector.h.
Referenced by SgEvaluatedMoves::AddMove(), SgEvaluatedMovesArray::BestMoves(), SgPropList::Clear(), SgMiaiStrategy::Clear(), SgIncrementalStack::Clear(), SgEvaluatedMoves::Clear(), SgVector< T >::Concat(), SgSearch::InitSearch(), SgSearch::IteratedSearch(), SgVector< T >::operator=(), SgVector< void * >::SetTo(), SgMiaiStrategy::StrategyFailed(), and SgPointSet::ToVector().
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().
bool SgVector< T >::Contains | ( | const T & | elt | ) | const |
Check if element is in vector.
true
if elt
is included in this vector, false
if not. Definition at line 490 of file SgVector.h.
References SgVector< T >::m_vec.
Referenced by SgEvaluatedMoves::GetEvaluation(), SgVector< void * >::Include(), SgVectorUtil::Intersection(), SgVector< T >::RemoveDuplicates(), SgSearch::SearchEngine(), SgEvaluatedMovesArray::SelectNextBest(), SgVector< T >::SetsAreEqual(), SgSearch::TryMove(), and SgSearch::TrySpecialMove().
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().
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().
Exclude each element of vector
from this vector.
Definition at line 519 of file SgVector.h.
References SgVector< T >::Exclude().
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().
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().
int SgVector< T >::Index | ( | const T & | elt | ) | const |
Find position of element.
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().
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.
Merge()
below. Definition at line 537 of file SgVector.h.
References SgVector< T >::IsSorted(), SgVector< T >::m_vec, and SG_ASSERT.
bool SgVector< T >::IsEmpty | ( | ) | const |
Return whether this vector contains zero elements.
Definition at line 134 of file SgVector.h.
Referenced by SgEvaluatedMoves::BestMove(), SgPropList::IsEmpty(), SgIncrementalStack::IsEmpty(), SgVector< T >::Merge(), SgVector< void * >::NonEmpty(), SgMiaiStrategy::OpenThreatMove(), SgVector< T >::SortedRemoveDuplicates(), SgMiaiStrategy::Status(), and SgPropTextList::ToString().
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().
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().
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().
int SgVector< T >::Length | ( | ) | const |
Return the number of elements in this vector.
Definition at line 152 of file SgVector.h.
Referenced by SgEvaluatedMoves::BestMove(), SgVector< T >::DeleteAt(), SgVector< void * >::IsLength(), SgVector< T >::LimitListLength(), SgVector< void * >::MaxLength(), SgVector< T >::Merge(), SgVector< void * >::MinLength(), SgVector< void * >::PushBack(), SgVector< T >::RemoveDuplicates(), SgVector< T >::SetsAreEqual(), SgVector< T >::SortedRemoveDuplicates(), and SgVector< T >::UniqueElements().
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().
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().
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().
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().
bool SgVector< T >::NonEmpty | ( | ) | const |
Return whether this vector contains more than zero elements.
Definition at line 180 of file SgVector.h.
Referenced by SgVector< void * >::Back(), SgVector< void * >::BackAndPop(), SgVector< void * >::Front(), SgSearch::IteratedSearch(), SgVector< T >::PopBack(), SgVector< T >::PopFront(), and SgVector< void * >::TopNth().
Compare whether the contents of two vectors are not identical.
Definition at line 51 of file SgVector.h.
Assignment operator.
Copy content of other vector.
Definition at line 466 of file SgVector.h.
References SgVector< T >::Clear(), and SgVector< T >::PushBackList().
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.
const T& SgVector< T >::operator[] | ( | int | index | ) | const |
Return const reference to element.
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.
T& SgVector< T >::operator[] | ( | int | index | ) |
Return reference to element.
index | Position of element in range 0..length-1 . |
Definition at line 27 of file SgVector.h.
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().
T SgVector< T >::PopFront | ( | ) |
Remove element[0] of the vector.
The vector must not be empty.
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.
void SgVector< T >::PushBack | ( | const T & | elt | ) |
Add a single element at the end of the vector.
Definition at line 202 of file SgVector.h.
Referenced by SgEvaluatedMoves::AddMove(), SgMiaiStrategy::AddPair(), SgPropTextList::AddStringAtPoint(), SgEvaluatedMovesArray::BestMoves(), SgSearch::CallExecute(), SgMiaiStrategy::ExecuteMove(), SgPropPointList::FromString(), SgSortedMoves< MOVE, VALUE, SIZE >::GetMoves(), SgVector< void * >::Include(), SgSearch::InitSearch(), SgVectorUtil::Intersection(), SgPropPointList::PushBack(), SgIncrementalStack::PushInt(), SgIncrementalStack::PushPoint(), SgIncrementalStack::PushPtr(), SgVector< T >::RemoveDuplicates(), SgSearch::SearchEngine(), SgVector< void * >::SetTo(), SgPointSet::ToVector(), and SgSearch::TrySpecialMove().
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=().
void SgVector< T >::PushFront | ( | const T & | elt | ) |
Insert element at the beginning of the vector.
Definition at line 624 of file SgVector.h.
References SgVector< T >::m_vec.
bool SgVector< T >::RemoveDuplicates | ( | ) |
Removes all but the first copy of each element from the vector.
After calling RemoveDuplicates()
, UniqueElements()
is true
.
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().
void SgVector< T >::Reverse | ( | ) |
Definition at line 217 of file SgVector.h.
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().
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().
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.
void SgVector< T >::Sort | ( | ) |
Definition at line 656 of file SgVector.h.
References SgVector< T >::m_vec.
void SgVector< T >::SortedRemoveDuplicates | ( | ) |
remove duplicates in a sorted vector
Definition at line 682 of file SgVector.h.
References SgVector< T >::IsEmpty(), SgVector< T >::IsSorted(), SgVector< T >::IsSortedAndUnique(), SgVector< T >::Length(), SgVector< T >::LimitListLength(), SgVector< T >::m_vec, and SG_ASSERT.
Referenced by SgVector< T >::Merge().
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().
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().
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().
bool SgVector< T >::UniqueElements | ( | ) | const |
Check for duplicate elements.
true
if there are no duplicate elements in the vector. Useful for debugging. 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().
std::vector<T>& SgVector< T >::Vector | ( | ) |
Definition at line 269 of file SgVector.h.
const std::vector<T>& SgVector< T >::Vector | ( | ) | const |
Definition at line 274 of file SgVector.h.
Definition at line 280 of file SgVector.h.
Referenced by SgVector< void * >::Back(), SgVector< void * >::BackAndPop(), SgVector< void * >::Clear(), SgVector< T >::Contains(), SgVector< T >::DeleteAt(), SgVector< T >::Exclude(), SgVector< void * >::Front(), SgVector< T >::Index(), SgVector< T >::Insert(), SgVector< void * >::IsEmpty(), SgVector< T >::IsSorted(), SgVector< T >::IsSortedAndUnique(), SgVector< void * >::Length(), SgVector< T >::LimitListLength(), SgVector< T >::Merge(), SgVector< void * >::operator==(), SgVector< void * >::operator[](), SgVector< T >::PopBack(), SgVector< T >::PopFront(), SgVector< void * >::PushBack(), SgVector< T >::PushBackList(), SgVector< T >::PushFront(), SgVector< void * >::Reverse(), SgVector< T >::SetTo(), SgVector< T >::Sort(), SgVector< T >::SortedRemoveDuplicates(), SgVector< void * >::SwapWith(), SgVector< void * >::TopNth(), SgVector< T >::UniqueElements(), and SgVector< void * >::Vector().