Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MEDMODULUSARRAY_H__
00024 #define __MEDMODULUSARRAY_H__
00025
00026 #include "MEDMEM.hxx"
00027
00028 #include "MEDMEM_Utilities.hxx"
00029 #include "MEDMEM_define.hxx"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 namespace MEDMEM {
00041 class MEDMEM_EXPORT MEDMODULUSARRAY {
00042 private:
00043
00044 int _length ;
00045
00046
00047 int _length2;
00048 const int * _array ;
00049
00050 inline bool compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const;
00051
00052 public:
00053 MEDMODULUSARRAY(int length, const int * array) :
00054 _length(length), _length2(length), _array(array) {}
00055
00056 MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array):
00057 _length(vertexLength), _length2( totalLength ), _array(array) {}
00058
00059 ~MEDMODULUSARRAY() {}
00060
00061 inline const int operator[](const int &i) const ;
00062
00063 inline int compare(const MEDMODULUSARRAY &modulusArray) const;
00064
00065 const int *getArray(int& length) const { length=_length; return _array; }
00066 };
00067
00068
00069 inline const int MEDMODULUSARRAY::operator[](const int &i) const
00070 {
00071 int position = i%_length ;
00072
00073 if (position < 0)
00074 position+=_length ;
00075
00076 return _array[position] ;
00077 }
00078
00079 inline int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
00080 {
00081 int ret = 0 ;
00082
00083 if (modulusArray._length != _length ||
00084 modulusArray._length2 != _length2 )
00085 return ret ;
00086
00087 if (_length==1)
00088 {
00089 if (_array[0]==modulusArray[0])
00090 return 1;
00091 else
00092 return 0;
00093 }
00094
00095 if (_length==2) {
00096 if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
00097 ret = 1;
00098 else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
00099 ret = -1;
00100 else
00101 return 0;
00102 if ( !compareNotVertexNodes( modulusArray ) )
00103 ret = 0;
00104 return ret;
00105 }
00106
00107
00108 for(int i=0;i<_length;i++)
00109 if ( _array[0] == modulusArray[i] ) {
00110
00111 if (_array[1]==modulusArray[i+1]){
00112 ret=1;
00113 for(int j=2;j<_length;j++)
00114 if (_array[j]!=modulusArray[i+j]) {
00115 ret = 0 ;
00116 break ;
00117 }
00118 } else if(_array[1]==modulusArray[i-1]) {
00119 ret=-1;
00120 for(int j=2;j<_length;j++)
00121 if (_array[j]!=modulusArray[i-j]) {
00122 ret = 0 ;
00123 break ;
00124 }
00125 }
00126 if (ret!=0) {
00127 if ( !compareNotVertexNodes( modulusArray ) )
00128 ret = 0;
00129 break ;
00130 }
00131
00132 }
00133 return ret ;
00134 }
00135
00140 inline bool MEDMODULUSARRAY::compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const
00141 {
00142 if ( _length2 > _length ) {
00143 for ( int i = _length; i < _length2; ++i ) {
00144 bool found = false;
00145 for ( int j = _length; ( j < _length2 && !found ); ++j )
00146 found = ( _array[ i ] == modulusArray._array[ j ] );
00147 if ( !found )
00148 return false;
00149 }
00150 }
00151 return true;
00152 }
00153
00154 }
00155
00156 # endif
00157