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, int * array) ;
24 int & operator[](const int &i) const ;
26 int compare(const MEDMODULUSARRAY &modulusArray) const;
30 MEDMODULUSARRAY::MEDMODULUSARRAY(int length, int * array) :
31 _length(length), _array(array)
33 // MESSAGE("MEDMODULUSARRAY::MEDMODULUSARRAY("<<length<<", "<<array<<")") ;
36 MEDMODULUSARRAY::~MEDMODULUSARRAY()
38 // do nothing because nothing is allocated !
39 // MESSAGE("MEDMODULUSARRAY::~MEDMODULUSARRAY()") ;
43 int & MEDMODULUSARRAY::operator[](const int &i) const
45 int position = i%_length ;
48 return _array[position] ;
51 int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
55 if (modulusArray._length != _length)
59 if (_array[0]==modulusArray[0])
65 if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
67 else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
72 //search if there is one start point in common in two array
73 for(int i=0;i<_length;i++)
74 if ( _array[0] == modulusArray[i] ) {
75 // we search if cycle is the same
76 if (_array[1]==modulusArray[i+1]){ // positive order
78 for(int j=2;j<_length;j++)
79 if (_array[j]!=modulusArray[i+j]) {
83 } else if(_array[1]==modulusArray[i-1]) { //negative order
85 for(int j=2;j<_length;j++)
86 if (_array[j]!=modulusArray[i-j]) {
91 if (ret!=0) {// we have found it !
94 // else we continue if there is another start point i
99 # endif /* # ifndef __MEDMODULUSARRAY_H__ */