#include <SgVector.h>
Definition at line 17 of file 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 |
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 63 of file SgVector.h.
Referenced by SgVectorOf< std::string >::Back(), and SgVector< T >::Merge().
T SgVector< T >::BackAndPop | ( | ) |
Definition at line 69 of file SgVector.h.
void SgVector< T >::Clear | ( | ) |
Remove all elements in this vector.
Definition at line 78 of file SgVector.h.
Referenced by SgEvaluatedMovesArray::BestMoves(), SgPropList::Clear(), SgVector< T >::Concat(), SgVector< T >::operator=(), ReverseCopyStack(), SgVector< std::pair< SgPoint, SgPoint > >::SetTo(), 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 505 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 512 of file SgVector.h.
References SgVector< T >::m_vec.
Referenced by SgVectorOf< std::string >::Contains(), SgVector< std::pair< SgPoint, SgPoint > >::Include(), SgVectorUtility::Intersection(), SgVector< T >::RemoveDuplicates(), SgEvaluatedMovesArray::SelectNextBest(), SgVector< T >::SetsAreEqual(), SgSearch::TryMove(), and SgSearch::TrySpecialMove().
void SgVector< T >::DeleteAt | ( | int | index | ) |
delete element at specified index
Definition at line 520 of file SgVector.h.
References SgVector< T >::Length(), SgVector< T >::m_vec, and SG_ASSERT.
Referenced by SgPropTextList::ClearStringAtPoint().
Exclude each element of vector
from this vector.
Definition at line 541 of file SgVector.h.
References SgVector< T >::Exclude().
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 528 of file SgVector.h.
References SgVector< T >::m_vec.
Referenced by SgVectorUtility::Difference(), SgVector< T >::Exclude(), and SgVectorOf< std::string >::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 113 of file SgVector.h.
Referenced by SgVectorOf< std::string >::Front(), 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 129 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 548 of file SgVector.h.
References SgVector< T >::m_vec.
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 559 of file SgVector.h.
References SgVector< T >::IsSorted(), SgVector< T >::m_vec, and SG_ASSERT.
Referenced by SgVectorOf< std::string >::Insert().
bool SgVector< T >::IsEmpty | ( | ) | const |
Return whether this vector contains zero elements.
Definition at line 146 of file SgVector.h.
Referenced by SgPropList::IsEmpty(), SgVector< T >::Merge(), SgVector< std::pair< SgPoint, SgPoint > >::NonEmpty(), and SgVector< T >::SortedRemoveDuplicates().
bool SgVector< T >::IsLength | ( | int | length | ) | const |
Test whether a vector is as long as a given length.
Definition at line 152 of file SgVector.h.
Referenced by SgVector< T >::SetsAreEqual(), and SgVector< T >::SetTo().
bool SgVector< T >::IsSorted | ( | bool | ascending = true |
) | const |
Returns whether the vector is sorted in given order.
Definition at line 578 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 589 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 164 of file SgVector.h.
Referenced by SgVector< T >::DeleteAt(), SgVector< std::pair< SgPoint, SgPoint > >::IsLength(), SgVector< T >::LimitListLength(), SgVector< std::pair< SgPoint, SgPoint > >::MaxLength(), SgVector< T >::Merge(), SgVector< std::pair< SgPoint, SgPoint > >::MinLength(), 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 603 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 173 of file SgVector.h.
Merges two sorted vectors into this.
Equivalent to, but faster than:
for (SgVectorIterator<T> it(vector); it; ++it) Insert(*it);
Definition at line 610 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 187 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 193 of file SgVector.h.
Referenced by SgVector< std::pair< SgPoint, SgPoint > >::Back(), SgVector< std::pair< SgPoint, SgPoint > >::BackAndPop(), SgVector< std::pair< SgPoint, SgPoint > >::Front(), SgVector< T >::PopBack(), SgVector< T >::PopFront(), and SgVector< std::pair< SgPoint, SgPoint > >::TopNth().
Compare whether the contents of two vectors are not identical.
Definition at line 55 of file SgVector.h.
Assignment operator.
Copy content of other vector.
Definition at line 488 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 49 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 36 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 28 of file SgVector.h.
Referenced by SgVectorOf< std::string >::operator[]().
void SgVector< T >::PopBack | ( | ) |
Remove the last element of the vector.
The vector must not be empty.
Definition at line 639 of file SgVector.h.
References SgVector< T >::m_vec, SgVector< T >::NonEmpty(), and SG_ASSERT.
Referenced by SgVector< std::pair< SgPoint, SgPoint > >::BackAndPop().
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 630 of file SgVector.h.
References SgVector< T >::Front(), SgVector< T >::m_vec, SgVector< T >::NonEmpty(), and SG_ASSERT.
Referenced by SgVectorOf< std::string >::PopFront().
void SgVector< T >::PushBack | ( | const T & | elt | ) |
Add a single element at the end of the vector.
Definition at line 218 of file SgVector.h.
Referenced by SgEvaluatedMovesArray::BestMoves(), SgMiaiStrategy::ExecuteMove(), SgSortedMoves< MOVE, VALUE, SIZE >::GetMoves(), SgVector< std::pair< SgPoint, SgPoint > >::Include(), SgVectorUtility::Intersection(), SgVectorOf< std::string >::PushBack(), SgVector< T >::RemoveDuplicates(), ReverseCopyStack(), SgVector< std::pair< SgPoint, SgPoint > >::SetTo(), SgPointSet::ToVector(), and SgSearch::TrySpecialMove().
Push all elements from vector
to the back of this.
Definition at line 499 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 646 of file SgVector.h.
References SgVector< T >::m_vec.
Referenced by SgVectorOf< std::string >::PushFront().
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 691 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 232 of file SgVector.h.
Do vectors contain the same elements, possibly in different order?
Definition at line 652 of file SgVector.h.
References SgVector< T >::Contains(), SgVector< T >::IsLength(), and SgVector< T >::Length().
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 671 of file SgVector.h.
References SgVector< T >::IsLength(), SgVector< T >::m_vec, and SG_ASSERT.
void SgVector< T >::SetTo | ( | const T & | elt | ) |
Clear this vector and set it to contain only elt
.
Definition at line 238 of file SgVector.h.
Referenced by SgSortedArray< T, K, size >::GetElements(), and SgSortedArray< T, K, size >::GetKeys().
void SgVector< T >::Sort | ( | ) |
void SgVector< T >::SortedRemoveDuplicates | ( | ) |
remove duplicates in a sorted vector
Definition at line 704 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 260 of file SgVector.h.
Referenced by SgVectorUtility::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 267 of file SgVector.h.
Include all elements from set
into this vector.
Appends new elements at the end of this vector.
Definition at line 684 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 727 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().
const std::vector<T>& SgVector< T >::Vector | ( | ) | const |
Definition at line 293 of file SgVector.h.
std::vector<T>& SgVector< T >::Vector | ( | ) |
Definition at line 288 of file SgVector.h.
Definition at line 299 of file SgVector.h.
Referenced by SgVector< std::pair< SgPoint, SgPoint > >::Back(), SgVector< std::pair< SgPoint, SgPoint > >::BackAndPop(), SgVector< std::pair< SgPoint, SgPoint > >::Clear(), SgVector< T >::Contains(), SgVector< T >::DeleteAt(), SgVector< T >::Exclude(), SgVector< std::pair< SgPoint, SgPoint > >::Front(), SgVector< T >::Index(), SgVector< T >::Insert(), SgVector< std::pair< SgPoint, SgPoint > >::IsEmpty(), SgVector< T >::IsSorted(), SgVector< T >::IsSortedAndUnique(), SgVector< std::pair< SgPoint, SgPoint > >::Length(), SgVector< T >::LimitListLength(), SgVector< T >::Merge(), SgVector< std::pair< SgPoint, SgPoint > >::operator==(), SgVector< std::pair< SgPoint, SgPoint > >::operator[](), SgVector< T >::PopBack(), SgVector< T >::PopFront(), SgVector< std::pair< SgPoint, SgPoint > >::PushBack(), SgVector< T >::PushBackList(), SgVector< T >::PushFront(), SgVector< std::pair< SgPoint, SgPoint > >::Reverse(), SgVector< T >::SetTo(), SgVector< T >::Sort(), SgVector< T >::SortedRemoveDuplicates(), SgVector< std::pair< SgPoint, SgPoint > >::SwapWith(), SgVector< std::pair< SgPoint, SgPoint > >::TopNth(), SgVector< T >::UniqueElements(), and SgVector< std::pair< SgPoint, SgPoint > >::Vector().