1 #ifndef __MEDMODULUSARRAY_H__
2 #define __MEDMODULUSARRAY_H__
7 This class is use to set cyclic (modulus length) array.
8 (array[length+1]==array[1])
10 We use it in particular to compare faces nodes lists to know if
11 they are the same (positive or negative cycle) !
15 class MEDMODULUSARRAY {
21 MEDMODULUSARRAY(int length, const int * array) ;
24 const int & operator[](const int &i) const ;
26 int compare(const MEDMODULUSARRAY &modulusArray) const;
30 using namespace MEDMEM;
32 MEDMODULUSARRAY::MEDMODULUSARRAY(int length, const int * array) :
33 _length(length), _array(array)
36 // for (int i=0;i<_length;i++){
37 // MESSAGE("MEDMODULUSARRAY["<<i<<"]="<<_array[i]);
41 MEDMODULUSARRAY::~MEDMODULUSARRAY()
43 // do nothing because nothing is allocated !
44 // MESSAGE("MEDMODULUSARRAY::~MEDMODULUSARRAY()") ;
48 const int & MEDMODULUSARRAY::operator[](const int &i) const
50 int position = i%_length ;
53 return _array[position] ;
56 int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
60 if (modulusArray._length != _length)
64 if (_array[0]==modulusArray[0])
70 if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
72 else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
77 //search if there is one start point in common in two array
78 for(int i=0;i<_length;i++)
79 if ( _array[0] == modulusArray[i] ) {
80 // we search if cycle is the same
81 if (_array[1]==modulusArray[i+1]){ // positive order
83 for(int j=2;j<_length;j++)
84 if (_array[j]!=modulusArray[i+j]) {
88 } else if(_array[1]==modulusArray[i-1]) { //negative order
90 for(int j=2;j<_length;j++)
91 if (_array[j]!=modulusArray[i-j]) {
96 if (ret!=0) {// we have found it !
99 // else we continue if there is another start point i
104 # endif /* # ifndef __MEDMODULUSARRAY_H__ */