📄 vector_of_vector.hpp
字号:
iterator_type it (static_cast<vector_data_value_type &> (*itv).find (functor_type::element2 (i, size1_, j, size2_)));
if (it == static_cast<vector_data_value_type &> (*itv).end ())
return;
static_cast<vector_data_value_type &> (*itv).erase (it);
}
BOOST_UBLAS_INLINE
void clear () {
data ().resize (functor_type::size1 (size1_, size2_) + 1);
for (size_type i = 0; i < functor_type::size1 (size1_, size2_); ++ i)
static_cast<vector_data_value_type &> (data_ [i]).resize (functor_type::size2 (size1_, size2_));
data_ [functor_type::size1 (size1_, size2_)] = vector_data_value_type ();
}
class const_iterator1;
class iterator1;
class const_iterator2;
class iterator2;
#ifdef BOOST_MSVC_STD_ITERATOR
typedef reverse_iterator_base1<const_iterator1, value_type, const_reference> const_reverse_iterator1;
typedef reverse_iterator_base1<iterator1, value_type, reference> reverse_iterator1;
typedef reverse_iterator_base2<const_iterator2, value_type, const_reference> const_reverse_iterator2;
typedef reverse_iterator_base2<iterator2, value_type, reference> reverse_iterator2;
#else
typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
typedef reverse_iterator_base1<iterator1> reverse_iterator1;
typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
typedef reverse_iterator_base2<iterator2> reverse_iterator2;
#endif
// Element lookup
// This function seems to be big. So we do not let the compiler inline it.
// BOOST_UBLAS_INLINE
const_iterator1 find1 (int rank, size_type i, size_type j, int direction = 1) const {
BOOST_UBLAS_CHECK (data ().begin () != data ().end (), internal_logic ());
for (;;) {
vector_const_iterator_type itv (data ().find (functor_type::address1 (i, size1_, j, size2_)));
vector_const_iterator_type itv_end (data ().end ());
if (itv == itv_end)
return const_iterator1 (*this, rank, i, j, itv_end, static_cast<const vector_data_value_type &> (*(-- itv)).end ());
const_iterator_type it (static_cast<const vector_data_value_type &> (*itv).find (functor_type::address2 (i, size1_, j, size2_)));
const_iterator_type it_end (static_cast<const vector_data_value_type &> (*itv).end ());
if (it != it_end) {
#ifdef BOOST_UBLAS_BOUNDS_CHECK
size_type index1 (functor_type::index1 (itv.index (), it.index ()));
BOOST_UBLAS_CHECK (index1 >= i, internal_logic ());
#endif
size_type index2 (functor_type::index2 (itv.index (), it.index ()));
BOOST_UBLAS_CHECK (index2 >= j, internal_logic ());
if ((rank == 0 && index2 >= j) ||
(rank == 1 && index2 == j))
return const_iterator1 (*this, rank, i, j, itv, it);
}
if (direction > 0) {
if (rank == 0 || i >= size1_)
return const_iterator1 (*this, 0, i, j, itv, it_end);
++ i;
} else /* if (direction < 0) */ {
if (rank == 0 || i == 0)
return const_iterator1 (*this, 0, i, j, itv, it_end);
-- i;
}
}
}
// This function seems to be big. So we do not let the compiler inline it.
// BOOST_UBLAS_INLINE
iterator1 find1 (int rank, size_type i, size_type j, int direction = 1) {
BOOST_UBLAS_CHECK (data ().begin () != data ().end (), internal_logic ());
for (;;) {
vector_iterator_type itv (data ().find (functor_type::address1 (i, size1_, j, size2_)));
vector_iterator_type itv_end (data ().end ());
if (itv == itv_end)
return iterator1 (*this, rank, i, j, itv_end, static_cast<vector_data_value_type &> (*(-- itv)).end ());
iterator_type it (static_cast<vector_data_value_type &> (*itv).find (functor_type::address2 (i, size1_, j, size2_)));
iterator_type it_end (static_cast<vector_data_value_type &> (*itv).end ());
if (it != it_end) {
#ifdef BOOST_UBLAS_BOUNDS_CHECK
size_type index1 (functor_type::index1 (itv.index (), it.index ()));
BOOST_UBLAS_CHECK (index1 >= i, internal_logic ());
#endif
size_type index2 (functor_type::index2 (itv.index (), it.index ()));
BOOST_UBLAS_CHECK (index2 >= j, internal_logic ());
if ((rank == 0 && index2 >= j) ||
(rank == 1 && index2 == j))
return iterator1 (*this, rank, i, j, itv, it);
}
if (direction > 0) {
if (rank == 0 || i >= size1_)
return iterator1 (*this, 0, i, j, itv, it_end);
++ i;
} else /* if (direction < 0) */ {
if (rank == 0 || i == 0)
return iterator1 (*this, 0, i, j, itv, it_end);
-- i;
}
}
}
// This function seems to be big. So we do not let the compiler inline it.
// BOOST_UBLAS_INLINE
const_iterator2 find2 (int rank, size_type i, size_type j, int direction = 1) const {
BOOST_UBLAS_CHECK (data ().begin () != data ().end (), internal_logic ());
for (;;) {
vector_const_iterator_type itv (data ().find (functor_type::address1 (i, size1_, j, size2_)));
vector_const_iterator_type itv_end (data ().end ());
if (itv == itv_end)
return const_iterator2 (*this, rank, i, j, itv_end, static_cast<const vector_data_value_type &> (*(-- itv)).end ());
const_iterator_type it (static_cast<const vector_data_value_type &> (*itv).find (functor_type::address2 (i, size1_, j, size2_)));
const_iterator_type it_end (static_cast<const vector_data_value_type &> (*itv).end ());
if (it != it_end) {
size_type index1 (functor_type::index1 (itv.index (), it.index ()));
BOOST_UBLAS_CHECK (index1 >= i, internal_logic ());
#ifdef BOOST_UBLAS_BOUNDS_CHECK
size_type index2 (functor_type::index2 (itv.index (), it.index ()));
BOOST_UBLAS_CHECK (index2 >= j, internal_logic ());
#endif
if ((rank == 0 && index1 >= i) ||
(rank == 1 && index1 == i))
return const_iterator2 (*this, rank, i, j, itv, it);
}
if (direction > 0) {
if (rank == 0 || j >= size2_)
return const_iterator2 (*this, 0, i, j, itv, it_end);
++ j;
} else /* if (direction < 0) */ {
if (rank == 0 || j == 0)
return const_iterator2 (*this, 0, i, j, itv, it_end);
-- j;
}
}
}
// This function seems to be big. So we do not let the compiler inline it.
// BOOST_UBLAS_INLINE
iterator2 find2 (int rank, size_type i, size_type j, int direction = 1) {
BOOST_UBLAS_CHECK (data ().begin () != data ().end (), internal_logic ());
for (;;) {
vector_iterator_type itv (data ().find (functor_type::address1 (i, size1_, j, size2_)));
vector_iterator_type itv_end (data ().end ());
if (itv == itv_end)
return iterator2 (*this, rank, i, j, itv_end, static_cast<vector_data_value_type &> (*(-- itv)).end ());
iterator_type it (static_cast<vector_data_value_type &> (*itv).find (functor_type::address2 (i, size1_, j, size2_)));
iterator_type it_end (static_cast<vector_data_value_type &> (*itv).end ());
if (it != it_end) {
size_type index1 (functor_type::index1 (itv.index (), it.index ()));
BOOST_UBLAS_CHECK (index1 >= i, internal_logic ());
#ifdef BOOST_UBLAS_BOUNDS_CHECK
size_type index2 (functor_type::index2 (itv.index (), it.index ()));
BOOST_UBLAS_CHECK (index2 >= j, internal_logic ());
#endif
if ((rank == 0 && index1 >= i) ||
(rank == 1 && index1 == i))
return iterator2 (*this, rank, i, j, itv, it);
}
if (direction > 0) {
if (rank == 0 || j >= size2_)
return iterator2 (*this, 0, i, j, itv, it_end);
++ j;
} else /* if (direction < 0) */ {
if (rank == 0 || j == 0)
return iterator2 (*this, 0, i, j, itv, it_end);
-- j;
}
}
}
// Iterators simply are pointers.
class const_iterator1:
public container_const_reference<generalized_vector_of_vector>,
public bidirectional_iterator_base<sparse_bidirectional_iterator_tag,
const_iterator1, value_type> {
public:
typedef sparse_bidirectional_iterator_tag iterator_category;
#ifdef BOOST_MSVC_STD_ITERATOR
typedef const_reference reference;
#else
typedef typename generalized_vector_of_vector::difference_type difference_type;
typedef typename generalized_vector_of_vector::value_type value_type;
typedef typename generalized_vector_of_vector::const_reference reference;
typedef typename generalized_vector_of_vector::const_pointer pointer;
#endif
typedef const_iterator2 dual_iterator_type;
typedef const_reverse_iterator2 dual_reverse_iterator_type;
// Construction and destruction
BOOST_UBLAS_INLINE
const_iterator1 ():
container_const_reference<self_type> (), rank_ (), i_ (), j_ (), itv_ (), it_ () {}
BOOST_UBLAS_INLINE
const_iterator1 (const self_type &m, int rank, size_type i, size_type j, const vector_const_iterator_type &itv, const const_iterator_type &it):
container_const_reference<self_type> (m), rank_ (rank), i_ (i), j_ (j), itv_ (itv), it_ (it) {}
BOOST_UBLAS_INLINE
const_iterator1 (const iterator1 &it):
container_const_reference<self_type> (it ()), rank_ (it.rank_), i_ (it.i_), j_ (it.j_), itv_ (it.itv_), it_ (it.it_) {}
// Arithmetic
BOOST_UBLAS_INLINE
const_iterator1 &operator ++ () {
const self_type &m = (*this) ();
if (rank_ == 1 && functor_type::fast1 ())
++ it_;
else {
i_ = index1 () + 1;
if (rank_ == 1 && ++ itv_ == m.end1 ().itv_)
*this = m.find1 (rank_, i_, j_, 1);
else if (rank_ == 1) {
it_ = static_cast<const vector_data_value_type &> (*itv_).begin ();
if (it_ == static_cast<const vector_data_value_type &> (*itv_).end () || index2 () != j_)
*this = m.find1 (rank_, i_, j_, 1);
}
}
return *this;
}
BOOST_UBLAS_INLINE
const_iterator1 &operator -- () {
const self_type &m = (*this) ();
if (rank_ == 1 && functor_type::fast1 ())
-- it_;
else {
i_ = index1 () - 1;
if (rank_ == 1 && -- itv_ == m.end1 ().itv_)
*this = m.find1 (rank_, i_, j_, -1);
else if (rank_ == 1) {
it_ = static_cast<const vector_data_value_type &> (*itv_).begin ();
if (it_ == static_cast<const vector_data_value_type &> (*itv_).end () || index2 () != j_)
*this = m.find1 (rank_, i_, j_, -1);
}
}
return *this;
}
// Dereference
BOOST_UBLAS_INLINE
reference operator * () const {
if (rank_ == 1) {
BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());
BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());
return static_cast<const value_type &> (*it_);
} else {
return (*this) () (i_, j_);
}
}
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_iterator2 begin () const {
const self_type &m = (*this) ();
return m.find2 (1, index1 (), 0);
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_iterator2 end () const {
const self_type &m = (*this) ();
return m.find2 (1, index1 (), m.size2 ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_reverse_iterator2 rbegin () const {
return const_reverse_iterator2 (end ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_reverse_iterator2 rend () const {
return const_reverse_iterator2 (begin ());
}
#endif
// Indices
BOOST_UBLAS_INLINE
size_type index1 () const {
if (rank_ == 1) {
return functor_type::index1 (itv_.index (), it_.index ());
} else {
return i_;
}
}
BOOST_UBLAS_INLINE
size_type index2 () const {
if (rank_ == 1) {
return functor_type::index2 (itv_.index (), it_.index ());
} else {
return j_;
}
}
// Assignment
BOOST_UBLAS_INLINE
const_iterator1 &operator = (const const_iterator1 &it) {
container_const_reference<self_type>::assign (&it ());
rank_ = it.rank_;
i_ = it.i_;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -