mat_util: make arguments of lex_cmp const
[barvinok.git] / mat_util.cc
blobd3fdc667288d9eab2506fe5a4174d3de2bf59c5e
1 #include <assert.h>
2 #include <NTL/vec_ZZ.h>
3 #include <NTL/mat_ZZ.h>
4 #include "mat_util.h"
6 int lex_cmp(const vec_ZZ& a, const vec_ZZ& b)
8 assert(a.length() == b.length());
10 for (int j = 0; j < a.length(); ++j)
11 if (a[j] != b[j])
12 return a[j] < b[j] ? -1 : 1;
13 return 0;
16 void lex_order_rows(mat_ZZ& mat)
18 for (int i = 0; i < mat.NumRows(); ++i) {
19 int m = i;
20 for (int j = i+1; j < mat.NumRows(); ++j)
21 if (lex_cmp(mat[j], mat[m]) < 0)
22 m = j;
23 if (m != i) {
24 vec_ZZ tmp = mat[m];
25 mat[m] = mat[i];
26 mat[i] = tmp;