-
Notifications
You must be signed in to change notification settings - Fork 2
/
Alg_elements.h
54 lines (43 loc) · 1.41 KB
/
Alg_elements.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _ALG_ELEMENTS_H_
#define _ALG_ELEMENTS_H_
/*******************************************************************/
/*** FILE : Alg_elements.h ***/
/*** AUTHOR: Sekhar Muddana ***/
/*** MODIFIED: 9/93 - Trent Whiteley ***/
/*** Changed basis_coef from array to ptr ***/
/*******************************************************************/
#include <map>
#include "Build_defs.h"
#include "Scalar_arithmetic.h"
typedef std::map<Basis, Scalar> Alg_element; // basis -> coef
int IsZeroAE(const Alg_element &p);
void ScalarMultAE(Scalar x, Alg_element &p);
void AddAE(const Alg_element &p1, Alg_element &p2);
int MultAE(const Alg_element &p1, const Alg_element &p2, Alg_element &p3);
inline void SetAE(Alg_element &p, Basis b, Scalar x) {
if(x != S_zero()) {
p[b] = x;
} else {
p.erase(b);
}
}
inline Scalar GetAE(const Alg_element &p, Basis b) {
std::map<Basis, Scalar>::const_iterator i = p.find(b);
return i != p.end() ? i->second : S_zero();
}
inline void AccumAE(Alg_element &p, Basis b, Scalar x) {
if(b != 0 && x != S_zero()) {
std::map<Basis, Scalar>::iterator i = p.find(b);
if(i != p.end()) {
x = S_add(i->second, x);
if(x != S_zero()) {
i->second = x;
} else {
p.erase(i);
}
} else {
p[b] = x;
}
}
}
#endif