iterator.h
来自「高效的c++科学算法库」· C头文件 代码 · 共 134 行
H
134 行
/* -*- c++ -*- ****************************** * Scientific Library (GNU Public Licence) * * Author: Laurent Deniau, Laurent.Deniau@cern.ch * * $Id: iterator.h,v 1.1 1998/11/05 12:48:41 paubert Exp $ * * Suggestions: sl@mathinsa.insa-lyon.fr * Bugs: sl-bugs@mathinsa.insa-lyon.fr * * For more information, please see the sl++ Home Page: * http://wwwinfo.cern.ch/~ldeniau/sl.html * ****************************** */#ifndef SL_MATRIX_STRUCTURES_TRIANG_ITERATOR_H#define SL_MATRIX_STRUCTURES_TRIANG_ITERATOR_H#ifndef SL_MATRIX_STRUCTURES_TRIANG_H#error <sl/matrix/structures/triang/iterator.h> must be included via <sl/matrix/structures/triang.h>#endif#ifdef HAVE_NAMESPACEnamespace sl {#endif class LowerTriangularIterator : public GeneralIterator { public: typedef LowerTriangular structure_t; LowerTriangularIterator(structure_t const* structure, Index const i =MinIndex, Index const j =MinIndex) : GeneralIterator(structure->rows(),structure->cols(), i, j, map(i,j)) { assert ( structure->rows() == structure->cols() ); assert ( j <= i ); } void operator ++ () { if (++my_j > my_i) { my_j = MinIndex; if (++my_i > my_n) my_ok = false; } ++my_o; } void incRow() { if (++my_i > my_n) my_ok = false; else my_o += my_i-1; } void incCol() { if (++my_j > my_i) my_ok = false; else ++my_o; } private: Index map (Index const i, Index const j) const { return (i-MinIndex)*(i-MinIndex+1)/2+j; } }; class UpperTriangularIterator : public GeneralIterator { public: typedef UpperTriangular structure_t; UpperTriangularIterator(structure_t const* structure, Index const i =MinIndex, Index const j =MinIndex) : GeneralIterator(structure->rows(),structure->cols(),i, j, map(i,j)) { assert ( structure->rows() == structure->cols() ); assert ( i <= j ); } void operator ++ () { if (++my_i > my_j) { my_i = MinIndex; if (++my_j > my_p) my_ok = false; } ++my_o; } void incRow() { if (++my_i > my_j) my_ok = false; else ++my_o; } void incCol() { if (++my_j > my_p) my_ok = false; else my_o += my_j-1; } private: Index map (Index const i, Index const j) const { return (j-MinIndex)*(j-MinIndex+1)/2+i; } };#ifdef HAVE_NAMESPACE}#endif #endif// SL_MATRIX_STRUCTURES_TRIANG_TRIANG_H
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?