Macaulay2 Engine
Loading...
Searching...
No Matches

◆ compare() [1/2]

int FreeMonoid::compare ( const Monom & m1,
const Monom & m2 ) const

Definition at line 99 of file FreeMonoid.cpp.

100{
101 // order of events:
102 // compare weights first
103 // then compare word length
104 // then compare with lex
105
106 // is this thread-safe?
107 //FreeMonoidLogger::logCompare();
108
109 // compare weights first
110 for (int j = 1; j <= mNumWeights; ++j)
111 {
112 if (m1[j] > m2[j]) return GT;
113 if (m1[j] < m2[j]) return LT;
114 }
115
116 // at this point, the weights are the same.
117 // the total length is just mNumWeights + 1 + wordLength, so just
118 // compare the total length (i.e. m1[0] and m2[0]
119 if (m1.size() > m2.size()) return GT;
120 if (m1.size() < m2.size()) return LT;
121
122 // at this stage, they have the same weights and word length, so use lex order
123 for (int j = mNumWeights+1; j < m1.size(); ++j)
124 {
125 if (m1[j] > m2[j]) return LT;
126 if (m1[j] < m2[j]) return GT;
127 }
128 // if we are here, the monomials are the same.
129 return EQ;
130}
const int mNumWeights
int size() const
const int EQ
Definition style.hpp:40
const int GT
Definition style.hpp:41
const int LT
Definition style.hpp:39

References EQ, GT, LT, mNumWeights, and Monom::size().

Referenced by FreeAlgebra::compare_elems().