Macaulay2 Engine
Loading...
Searching...
No Matches
monsort.cpp
Go to the documentation of this file.
1// Copyright 2005 Michael E. Stillman
2
3#include "monsort.hpp"
4
5#if 0
6#include "moninfo.hpp"
7
8// Here is an example use of QuickSorter.
9
10class MSorter
11{
12 public:
14 typedef long value;
15
16 private:
17 MonomialInfo *M;
18 monomial *monoms;
19 long *indices;
20 long len;
21 long ncmps;
22
23 public:
24 int compare(value a, value b)
25 {
26 ncmps++;
27 return M->compare_grevlex(monoms[a], monoms[b]);
28 }
29
30 MSorter(MonomialInfo *M0, monomial *monoms0, long *indices0, long len0)
31 : M(M0), monoms(monoms0), indices(indices0), len(len0), ncmps(0)
32 {
33 }
34
35 ~MSorter() {}
36 void sort()
37 {
38 QuickSorter<MSorter>::sort(this, indices, len);
39 fprintf(stderr, "sort: nelements %ld ncompares %ld\n", len, ncmps);
40 }
41
42 static void sort(MonomialInfo *M0,
43 monomial *monoms0,
44 long *indices0,
45 long len0)
46 {
47 // monoms0 is an array 0..len0-1 of monomials
48 // indices0 is an array 0..len0-1, starts at the identity permutation
49 // monoms0 is not modified. Only the permutation to place the
50 // elements in descending monomial order is modified.
51 MSorter S(M0, monoms0, indices0, len0);
52 S.sort();
53 }
54};
55
56template class QuickSorter<MSorter>;
57#endif
58
59
60// Local Variables:
61// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
62// indent-tabs-mode: nil
63// End:
monomial value
Definition moninfo.hpp:149
int compare_grevlex(const_packed_monomial m, const_packed_monomial n) const
Definition moninfo.hpp:419
void sort(long lo, long hi)
Definition monsort.hpp:110
#define monomial
Definition gb-toric.cpp:11
static int compare(const vecterm *t, const vecterm *s)
Definition geovec.hpp:112
MonomialInfo — F4's packed_monomial encoding plus operations.
QuickSorter<Sorter> — ring-agnostic in-place sort over a duck-typed adapter.