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 MEDMODULUSARRAY::MEDMODULUSARRAY(int length, const int * array) :
31 _length(length), _array(array)
34 // for (int i=0;i<_length;i++){
35 // MESSAGE("MEDMODULUSARRAY["<<i<<"]="<<_array[i]);
39 MEDMODULUSARRAY::~MEDMODULUSARRAY()
41 // do nothing because nothing is allocated !
42 // MESSAGE("MEDMODULUSARRAY::~MEDMODULUSARRAY()") ;
46 const int & MEDMODULUSARRAY::operator[](const int &i) const
48 int position = i%_length ;
51 return _array[position] ;
54 int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
58 if (modulusArray._length != _length)
62 if (_array[0]==modulusArray[0])
68 if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
70 else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
75 //search if there is one start point in common in two array
76 for(int i=0;i<_length;i++)
77 if ( _array[0] == modulusArray[i] ) {
78 // we search if cycle is the same
79 if (_array[1]==modulusArray[i+1]){ // positive order
81 for(int j=2;j<_length;j++)
82 if (_array[j]!=modulusArray[i+j]) {
86 } else if(_array[1]==modulusArray[i-1]) { //negative order
88 for(int j=2;j<_length;j++)
89 if (_array[j]!=modulusArray[i-j]) {
94 if (ret!=0) {// we have found it !
97 // else we continue if there is another start point i
103 # endif /* # ifndef __MEDMODULUSARRAY_H__ */