From: Michael F. Herbst Date: Tue, 24 Feb 2015 15:07:59 +0000 (+0100) Subject: Use AlignedVector::size_type in all of table.h X-Git-Tag: v8.3.0-rc1~422^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=386ab8f533f62400f91eb136dec9474f66709772;p=dealii.git Use AlignedVector::size_type in all of table.h In all classes of table.h the type Use AlignedVector::size_type is now used for the calculation of indices for the values vector and the indexing of elements in the values vector. Note: This commit changes the interface of the n_elements function in TableBase --- diff --git a/include/deal.II/base/table.h b/include/deal.II/base/table.h index 965d08f44a..71f58c1e2a 100644 --- a/include/deal.II/base/table.h +++ b/include/deal.II/base/table.h @@ -153,6 +153,9 @@ namespace internal typedef typename Types::iterator iterator; typedef typename Types::const_iterator const_iterator; + + typedef size_t size_type; + typedef ptrdiff_t difference_type; private: /** * Constructor. Take a pointer to the table object to know about the @@ -400,6 +403,12 @@ template class TableBase : public Subscriptor { public: + /** + * Integer type used to count the number of elements in this container. + */ + typedef typename AlignedVector::size_type size_type; + + /** * Default constructor. Set all dimensions to zero. */ @@ -492,7 +501,7 @@ public: * Return the number of elements stored in this object, which is the product * of the extensions in each dimension. */ - unsigned int n_elements () const; + size_type n_elements () const; /** * Return whether the object is empty, i.e. one of the directions is zero. @@ -592,7 +601,7 @@ protected: * Return the position of the indicated element within the array of elements * stored one after the other. This function does no index checking. */ - typename AlignedVector::size_type position (const TableIndices &indices) const; + size_type position (const TableIndices &indices) const; /** * Return a read-write reference to the indicated element. @@ -667,6 +676,11 @@ template class Table<1,T> : public TableBase<1,T> { public: + /** + * Integer type used to count the number of elements in this container. + */ + typedef typename TableBase<1,T>::size_type size_type; + /** * Default constructor. Set all dimensions to zero. */ @@ -781,6 +795,11 @@ template class Table<2,T> : public TableBase<2,T> { public: + /** + * Integer type used to count the number of elements in this container. + */ + typedef typename TableBase<2,T>::size_type size_type; + /** * Default constructor. Set all dimensions to zero. */ @@ -959,6 +978,11 @@ template class Table<3,T> : public TableBase<3,T> { public: + /** + * Integer type used to count the number of elements in this container. + */ + typedef typename TableBase<3,T>::size_type size_type; + /** * Default constructor. Set all dimensions to zero. */ @@ -1088,6 +1112,11 @@ template class Table<4,T> : public TableBase<4,T> { public: + /** + * Integer type used to count the number of elements in this container. + */ + typedef typename TableBase<4,T>::size_type size_type; + /** * Default constructor. Set all dimensions to zero. */ @@ -1175,6 +1204,12 @@ template class Table<5,T> : public TableBase<5,T> { public: + /** + * Integer type used to count the number of elements in this container. + */ + typedef typename TableBase<5,T>::size_type size_type; + + /** * Default constructor. Set all dimensions to zero. */ @@ -1264,6 +1299,11 @@ template class Table<6,T> : public TableBase<6,T> { public: + /** + * Integer type used to count the number of elements in this container. + */ + typedef typename TableBase<6,T>::size_type size_type; + /** * Default constructor. Set all dimensions to zero. */ @@ -1355,6 +1395,11 @@ template class Table<7,T> : public TableBase<7,T> { public: + /** + * Integer type used to count the number of elements in this container. + */ + typedef typename TableBase<7,T>::size_type size_type; + /** * Default constructor. Set all dimensions to zero. */ @@ -1453,6 +1498,11 @@ template class TransposeTable : public TableBase<2,T> { public: + /** + * Integer type used to count the number of elements in this container. + */ + typedef typename TableBase<2,T>::size_type size_type; + /** * Default constructor. Set all dimensions to zero. */ @@ -1663,7 +1713,7 @@ namespace internal // note: P>1, otherwise the // specialization would have // been taken! - unsigned int subobject_size = table.size()[N-1]; + size_type subobject_size = table.size()[N-1]; for (int p=P-1; p>1; --p) subobject_size *= table.size()[N-p]; const iterator new_data = data + i*subobject_size; @@ -1831,7 +1881,7 @@ TableBase::reinit (const TableIndices &new_sizes, { table_size = new_sizes; - const unsigned int new_size = n_elements(); + const size_type new_size = n_elements(); // if zero size was given: free all memory if (new_size == 0) @@ -1878,10 +1928,10 @@ TableBase::size (const unsigned int i) const template inline -unsigned int +typename TableBase::size_type TableBase::n_elements () const { - unsigned int s = 1; + size_type s = 1; for (unsigned int n=0; n::memory_consumption () const template inline -typename AlignedVector::size_type +typename TableBase::size_type TableBase::position (const TableIndices &indices) const { - typedef typename AlignedVector::size_type size_type; - // specialize this for the // different numbers of dimensions, // to make the job somewhat easier @@ -2216,7 +2264,7 @@ Table<2,T>::operator [] (const unsigned int i) const Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); return dealii::internal::TableBaseAccessors::Accessor<2,T,true,1>(*this, - this->values.begin()+i*n_cols()); + this->values.begin()+size_type(i)*n_cols()); } @@ -2229,7 +2277,7 @@ Table<2,T>::operator [] (const unsigned int i) Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); return dealii::internal::TableBaseAccessors::Accessor<2,T,false,1>(*this, - this->values.begin()+i*n_cols()); + this->values.begin()+size_type(i)*n_cols()); } @@ -2244,8 +2292,6 @@ Table<2,T>::operator () (const unsigned int i, ExcIndexRange (i, 0, this->table_size[0])); Assert (j < this->table_size[1], ExcIndexRange (j, 0, this->table_size[1])); - - typedef typename AlignedVector::size_type size_type; return this->values[size_type(i)*this->table_size[1]+j]; } @@ -2261,8 +2307,6 @@ Table<2,T>::operator () (const unsigned int i, ExcIndexRange (i, 0, this->table_size[0])); Assert (j < this->table_size[1], ExcIndexRange (j, 0, this->table_size[1])); - - typedef typename AlignedVector::size_type size_type; return this->values[size_type(i)*this->table_size[1]+j]; } @@ -2294,7 +2338,6 @@ typename AlignedVector::const_reference Table<2,T>::el (const unsigned int i, const unsigned int j) const { - typedef typename AlignedVector::size_type size_type; return this->values[size_type(i)*this->table_size[1]+j]; } @@ -2306,7 +2349,6 @@ typename AlignedVector::reference Table<2,T>::el (const unsigned int i, const unsigned int j) { - typedef typename AlignedVector::size_type size_type; return this->values[size_type(i)*this->table_size[1]+j]; } @@ -2373,8 +2415,6 @@ TransposeTable::operator () (const unsigned int i, ExcIndexRange (i, 0, this->table_size[1])); Assert (j < this->table_size[0], ExcIndexRange (j, 0, this->table_size[0])); - - typedef typename AlignedVector::size_type size_type; return this->values[size_type(j)*this->table_size[1]+i]; } @@ -2390,8 +2430,6 @@ TransposeTable::operator () (const unsigned int i, ExcIndexRange (i, 0, this->table_size[1])); Assert (j < this->table_size[0], ExcIndexRange (j, 0, this->table_size[0])); - - typedef typename AlignedVector::size_type size_type; return this->values[size_type(j)*this->table_size[1]+i]; } @@ -2403,7 +2441,6 @@ typename AlignedVector::const_reference TransposeTable::el (const unsigned int i, const unsigned int j) const { - typedef typename AlignedVector::size_type size_type; return this->values[size_type(j)*this->table_size[1]+i]; } @@ -2415,7 +2452,6 @@ typename AlignedVector::reference TransposeTable::el (const unsigned int i, const unsigned int j) { - typedef typename AlignedVector::size_type size_type; return this->values[size_type(j)*this->table_size[1]+i]; } @@ -2485,8 +2521,8 @@ Table<3,T>::operator [] (const unsigned int i) const { Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); - const unsigned int subobject_size = this->table_size[1] * - this->table_size[2]; + const size_type subobject_size = size_type(this->table_size[1]) * + this->table_size[2]; return (dealii::internal::TableBaseAccessors::Accessor<3,T,true,2> (*this, this->values.begin() + i*subobject_size)); @@ -2501,8 +2537,8 @@ Table<3,T>::operator [] (const unsigned int i) { Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); - const unsigned int subobject_size = this->table_size[1] * - this->table_size[2]; + const size_type subobject_size = size_type(this->table_size[1]) * + this->table_size[2]; return (dealii::internal::TableBaseAccessors::Accessor<3,T,false,2> (*this, this->values.begin() + i*subobject_size)); @@ -2523,8 +2559,6 @@ Table<3,T>::operator () (const unsigned int i, ExcIndexRange (j, 0, this->table_size[1])); Assert (k < this->table_size[2], ExcIndexRange (k, 0, this->table_size[2])); - - typedef typename AlignedVector::size_type size_type; return this->values[(size_type(i)*this->table_size[1]+j) *this->table_size[2] + k]; } @@ -2544,8 +2578,6 @@ Table<3,T>::operator () (const unsigned int i, ExcIndexRange (j, 0, this->table_size[1])); Assert (k < this->table_size[2], ExcIndexRange (k, 0, this->table_size[2])); - - typedef typename AlignedVector::size_type size_type; return this->values[(size_type(i)*this->table_size[1]+j) *this->table_size[2] + k]; } @@ -2598,9 +2630,9 @@ Table<4,T>::operator [] (const unsigned int i) const { Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); - const unsigned int subobject_size = this->table_size[1] * - this->table_size[2] * - this->table_size[3]; + const size_type subobject_size = size_type(this->table_size[1]) * + this->table_size[2] * + this->table_size[3]; return (dealii::internal::TableBaseAccessors::Accessor<4,T,true,3> (*this, this->values.begin() + i*subobject_size)); @@ -2615,9 +2647,9 @@ Table<4,T>::operator [] (const unsigned int i) { Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); - const unsigned int subobject_size = this->table_size[1] * - this->table_size[2] * - this->table_size[3]; + const size_type subobject_size = size_type(this->table_size[1]) * + this->table_size[2] * + this->table_size[3]; return (dealii::internal::TableBaseAccessors::Accessor<4,T,false,3> (*this, this->values.begin() + i*subobject_size)); @@ -2641,8 +2673,6 @@ Table<4,T>::operator () (const unsigned int i, ExcIndexRange (k, 0, this->table_size[2])); Assert (l < this->table_size[3], ExcIndexRange (l, 0, this->table_size[3])); - - typedef typename AlignedVector::size_type size_type; return this->values[((size_type(i)*this->table_size[1]+j) *this->table_size[2] + k) *this->table_size[3] + l]; @@ -2666,8 +2696,6 @@ Table<4,T>::operator () (const unsigned int i, ExcIndexRange (k, 0, this->table_size[2])); Assert (l < this->table_size[3], ExcIndexRange (l, 0, this->table_size[3])); - - typedef typename AlignedVector::size_type size_type; return this->values[((size_type(i)*this->table_size[1]+j) *this->table_size[2] + k) *this->table_size[3] + l]; @@ -2722,10 +2750,10 @@ Table<5,T>::operator [] (const unsigned int i) const { Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); - const unsigned int subobject_size = this->table_size[1] * - this->table_size[2] * - this->table_size[3] * - this->table_size[4]; + const size_type subobject_size = size_type(this->table_size[1]) * + this->table_size[2] * + this->table_size[3] * + this->table_size[4]; return (dealii::internal::TableBaseAccessors::Accessor<5,T,true,4> (*this, this->values.begin() + i*subobject_size)); @@ -2740,10 +2768,10 @@ Table<5,T>::operator [] (const unsigned int i) { Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); - const unsigned int subobject_size = this->table_size[1] * - this->table_size[2] * - this->table_size[3] * - this->table_size[4]; + const size_type subobject_size = size_type(this->table_size[1]) * + this->table_size[2] * + this->table_size[3] * + this->table_size[4]; return (dealii::internal::TableBaseAccessors::Accessor<5,T,false,4> (*this, this->values.begin() + i*subobject_size)); @@ -2770,8 +2798,6 @@ Table<5,T>::operator () (const unsigned int i, ExcIndexRange (l, 0, this->table_size[3])); Assert (m < this->table_size[4], ExcIndexRange (m, 0, this->table_size[4])); - - typedef typename AlignedVector::size_type size_type; return this->values[(((size_type(i)*this->table_size[1]+j) *this->table_size[2] + k) *this->table_size[3] + l) @@ -2799,8 +2825,6 @@ Table<5,T>::operator () (const unsigned int i, ExcIndexRange (l, 0, this->table_size[3])); Assert (m < this->table_size[4], ExcIndexRange (m, 0, this->table_size[4])); - - typedef typename AlignedVector::size_type size_type; return this->values[(((size_type(i)*this->table_size[1]+j) *this->table_size[2] + k) *this->table_size[3] + l) @@ -2857,11 +2881,11 @@ Table<6,T>::operator [] (const unsigned int i) const { Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); - const unsigned int subobject_size = this->table_size[1] * - this->table_size[2] * - this->table_size[3] * - this->table_size[4] * - this->table_size[5]; + const size_type subobject_size = size_type(this->table_size[1]) * + this->table_size[2] * + this->table_size[3] * + this->table_size[4] * + this->table_size[5]; return (dealii::internal::TableBaseAccessors::Accessor<6,T,true,5> (*this, this->values.begin() + i*subobject_size)); @@ -2876,11 +2900,11 @@ Table<6,T>::operator [] (const unsigned int i) { Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); - const unsigned int subobject_size = this->table_size[1] * - this->table_size[2] * - this->table_size[3] * - this->table_size[4] * - this->table_size[5]; + const size_type subobject_size = size_type(this->table_size[1]) * + this->table_size[2] * + this->table_size[3] * + this->table_size[4] * + this->table_size[5]; return (dealii::internal::TableBaseAccessors::Accessor<6,T,false,5> (*this, this->values.begin() + i*subobject_size)); @@ -2910,8 +2934,6 @@ Table<6,T>::operator () (const unsigned int i, ExcIndexRange (m, 0, this->table_size[4])); Assert (n < this->table_size[5], ExcIndexRange (n, 0, this->table_size[5])); - - typedef typename AlignedVector::size_type size_type; return this->values[((((size_type(i)*this->table_size[1]+j) *this->table_size[2] + k) *this->table_size[3] + l) @@ -2943,8 +2965,6 @@ Table<6,T>::operator () (const unsigned int i, ExcIndexRange (m, 0, this->table_size[4])); Assert (n < this->table_size[5], ExcIndexRange (n, 0, this->table_size[5])); - - typedef typename AlignedVector::size_type size_type; return this->values[((((size_type(i)*this->table_size[1]+j) *this->table_size[2] + k) *this->table_size[3] + l) @@ -3003,12 +3023,12 @@ Table<7,T>::operator [] (const unsigned int i) const { Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); - const unsigned int subobject_size = this->table_size[1] * - this->table_size[2] * - this->table_size[3] * - this->table_size[4] * - this->table_size[5] * - this->table_size[6]; + const size_type subobject_size = size_type(this->table_size[1]) * + this->table_size[2] * + this->table_size[3] * + this->table_size[4] * + this->table_size[5] * + this->table_size[6]; return (dealii::internal::TableBaseAccessors::Accessor<7,T,true,6> (*this, this->values.begin() + i*subobject_size)); @@ -3023,12 +3043,12 @@ Table<7,T>::operator [] (const unsigned int i) { Assert (i < this->table_size[0], ExcIndexRange (i, 0, this->table_size[0])); - const unsigned int subobject_size = this->table_size[1] * - this->table_size[2] * - this->table_size[3] * - this->table_size[4] * - this->table_size[5] * - this->table_size[6]; + const size_type subobject_size = size_type(this->table_size[1]) * + this->table_size[2] * + this->table_size[3] * + this->table_size[4] * + this->table_size[5] * + this->table_size[6]; return (dealii::internal::TableBaseAccessors::Accessor<7,T,false,6> (*this, this->values.begin() + i*subobject_size)); @@ -3061,8 +3081,6 @@ Table<7,T>::operator () (const unsigned int i, ExcIndexRange (n, 0, this->table_size[5])); Assert (o < this->table_size[6], ExcIndexRange (o, 0, this->table_size[6])); - - typedef typename AlignedVector::size_type size_type; return this->values[(((((size_type(i)*this->table_size[1]+j) *this->table_size[2] + k) *this->table_size[3] + l) @@ -3098,8 +3116,6 @@ Table<7,T>::operator () (const unsigned int i, ExcIndexRange (n, 0, this->table_size[5])); Assert (o < this->table_size[5], ExcIndexRange (o, 0, this->table_size[6])); - - typedef typename AlignedVector::size_type size_type; return this->values[(((((size_type(i)*this->table_size[1]+j) *this->table_size[2] + k) *this->table_size[3] + l)