Macaulay2 Engine
Loading...
Searching...
No Matches
montable.hpp
Go to the documentation of this file.
1#ifndef __montable_h
2#define __montable_h
3
41
42#include "mem.hpp"
43#include <vector>
44#include <memory>
45#include <algorithm>
46#include <stdio.h>
47#include <stddef.h>
48
49#include "ExponentVector.hpp"
50#include "newdelete.hpp"
51#include "style.hpp"
52
53/* "Tricks" used in this implementation */
54/*
55 1. exponent vectors: these look like: [e1, ..., en],
56 where n is the number of variables. HOWEVER, these
57 exponents are never created or freed by these routines,
58 so if they have more entries (e.g. a "sugar" homogenization)
59 then that (those) value(s) are ignored.
60 2. comparison routine: elements are kept in (increasing?) lex order.
61 Is this really an OK idea?
62 */
63
81{
82 static MonomialTable *make_minimal(int nvars,
83 const VECTOR(exponents_t) & exps,
84 const VECTOR(int) & comps,
85 const VECTOR(int) & vals,
86 VECTOR(int) & rejects);
87
88 static void minimalize(int nvars,
89 const VECTOR(exponents_t) & exps,
90 const VECTOR(int) & comps,
91 bool keep_duplicates,
92 VECTOR(int) & result_positions);
93
94 MonomialTable(); // the public must use "make" below
95 public:
108 struct mon_term
109 {
112 exponents_t _lead; /* Who owns this? */
113 unsigned long _mask;
114 int _val;
115 };
116
117 static MonomialTable *make(
118 int nvars); // this function serves as the constructor
119 /* Create a zero element table */
120
122
123 void insert(exponents_t exp, int comp, int id);
124 /* Insert [exp,comp,id] into the table. If there is already
125 an element which is <= [exp,comp], this triple is still
126 inserted. If that is not desired, use find_divisors.
127 */
128
129 int find_divisor(exponents_t exp, int comp);
130 /* returns the integer 'val' of the first divisor of exp*comp found,
131 or, returns -1 if none is found. */
132
133 int find_divisors(int max,
134 exponents_t exp,
135 int comp,
136 VECTOR(mon_term *) *result = nullptr);
137 /* max: the max number of divisors to find.
138 exp: the monomial whose divisors we seek.
139 result: an array of mon_term's.
140 return value: length of this array, i.e. the number of matches found */
141
142 mon_term *find_exact(exponents_t exp, int comp) const;
143 /* If this returns non-NULL, it is valid to grab the 'val' field, and/or to
144 assign to it.
145 All other fields should be considered read only */
146
147 /* Need a way of looping through the elements? */
148
149 void show(FILE *fil); /* Only for debugging */
150
151 private:
155 VECTOR(mon_term *) _head; /* One per component */
156 mon_term *_last_match; // optimization cache for find_divisors
157 int _last_match_comp; // optimization cache for find_divisors
159 static void move_up(mon_term *const y, mon_term *const head);
160 static void insert_before(mon_term *const y, mon_term *const z);
161 static void remove(mon_term *const y);
162};
163
164#endif
165
166// Local Variables:
167// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
168// indent-tabs-mode: nil
169// End:
exponents::Exponents exponents_t
Dense exponent-vector template [e_0, ..., e_{nvars-1}] for monomial operations.
stash * mon_term_stash
Definition montable.hpp:152
mon_term * make_list_head()
Definition montable.cpp:46
static void insert_before(mon_term *const y, mon_term *const z)
Definition montable.cpp:116
void insert(exponents_t exp, int comp, int id)
Definition montable.cpp:218
static MonomialTable * make_minimal(int nvars, const VECTOR(exponents_t) &exps, const VECTOR(int) &comps, const VECTOR(int) &vals, VECTOR(int) &rejects)
Definition montable.cpp:367
void show(FILE *fil)
Definition montable.cpp:419
static MonomialTable * make(int nvars)
Definition montable.cpp:61
int find_divisor(exponents_t exp, int comp)
Definition montable.cpp:131
static void move_up(mon_term *const y, mon_term *const head)
Definition montable.cpp:94
int find_divisors(int max, exponents_t exp, int comp, VECTOR(mon_term *) *result=nullptr)
Definition montable.cpp:152
mon_term * _last_match
Definition montable.hpp:156
static void minimalize(int nvars, const VECTOR(exponents_t) &exps, const VECTOR(int) &comps, bool keep_duplicates, VECTOR(int) &result_positions)
Definition montable.cpp:297
VECTOR(mon_term *) _head
static void remove(mon_term *const y)
Definition montable.cpp:108
mon_term * find_exact(exponents_t exp, int comp) const
Definition montable.cpp:193
Definition mem.hpp:78
VALGRIND_MAKE_MEM_DEFINED & result(result)
stash and doubling_stash — legacy size-class allocator interfaces, now stubbed to plain GC allocation...
#define VECTOR(T)
Definition newdelete.hpp:78
our_new_delete — per-class opt-in routing of new / delete through bdwgc.
#define max(a, b)
Definition polyroots.cpp:52
Doubly-linked-list node of a MonomialTable's per-component monomial list.
Definition montable.hpp:109
Engine-wide stylistic constants: LT / EQ / GT codes, INTSIZE, GEOHEAP_SIZE.