1 | #ifndef GRING_SA_CACHEHASH_H |
---|
2 | #define GRING_SA_CACHEHASH_H |
---|
3 | /***************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | *****************************************/ |
---|
6 | /* $Id$ */ |
---|
7 | |
---|
8 | // #include <ncSACache.h> // for CCacheHash etc classes |
---|
9 | |
---|
10 | #include <structs.h> |
---|
11 | #include <febase.h> // for Print! |
---|
12 | // //////////////////////////////////////////////////////////////////////// // |
---|
13 | // |
---|
14 | |
---|
15 | const int iMaxCacheSize = 20; |
---|
16 | |
---|
17 | template <typename CExponent> |
---|
18 | class CCacheHash |
---|
19 | { |
---|
20 | private: |
---|
21 | ring m_basering; |
---|
22 | int m_NVars; |
---|
23 | |
---|
24 | public: |
---|
25 | CCacheHash(ring r): m_basering(r), m_NVars(r->N){}; |
---|
26 | |
---|
27 | const ring GetBasering() const { return m_basering; }; |
---|
28 | inline int NVars() const { return m_NVars; } |
---|
29 | |
---|
30 | virtual ~CCacheHash(){}; |
---|
31 | |
---|
32 | |
---|
33 | enum EHistoryType { |
---|
34 | MULT_LOOKUP = 0, |
---|
35 | MULT_STORE = 1 |
---|
36 | }; |
---|
37 | |
---|
38 | struct CCacheItem |
---|
39 | { |
---|
40 | union{ |
---|
41 | CExponent aExponent; |
---|
42 | poly aMonom; |
---|
43 | } a; |
---|
44 | |
---|
45 | union{ |
---|
46 | CExponent bExponent; |
---|
47 | poly bMonom; |
---|
48 | } b; |
---|
49 | |
---|
50 | poly pProduct; |
---|
51 | |
---|
52 | int iPairType; |
---|
53 | long lHits; |
---|
54 | }; |
---|
55 | |
---|
56 | |
---|
57 | // -1 means no hits! |
---|
58 | int LookupEE(CExponent a, CExponent b, CCacheItem*& pItems) |
---|
59 | { |
---|
60 | /* |
---|
61 | PrintS("//////////////////////////////////////////////////////////////////////////////////////////////"); |
---|
62 | PrintLn(); |
---|
63 | PrintS("CCacheHash::LookupEE(a, b, *results)!"); |
---|
64 | PrintLn(); |
---|
65 | */ |
---|
66 | History(MULT_LOOKUP, a, b); |
---|
67 | |
---|
68 | pItems = NULL; |
---|
69 | return -1; |
---|
70 | } |
---|
71 | |
---|
72 | bool StoreEE(CExponent a, CExponent b, poly pProduct) |
---|
73 | { |
---|
74 | /* |
---|
75 | PrintS("CCacheHash::StoreEE(a, b, Product)!"); |
---|
76 | PrintLn(); |
---|
77 | */ |
---|
78 | |
---|
79 | History(MULT_STORE, a, b, pProduct); |
---|
80 | |
---|
81 | /* |
---|
82 | PrintS("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"); |
---|
83 | PrintLn(); |
---|
84 | */ |
---|
85 | |
---|
86 | return false; // the pair was not stored! |
---|
87 | }; |
---|
88 | |
---|
89 | virtual void History(const EHistoryType t, const CExponent a, const CExponent b, const poly p = NULL) |
---|
90 | { |
---|
91 | PrintS("CCacheHash::History(a, b, [p])!\n"); |
---|
92 | } |
---|
93 | |
---|
94 | private: // no copy constuctors! |
---|
95 | CCacheHash(const CCacheHash&); |
---|
96 | CCacheHash& operator=(const CCacheHash&); |
---|
97 | }; |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | class CGlobalCacheHash: public CCacheHash<poly> |
---|
102 | { |
---|
103 | public: |
---|
104 | typedef poly CExponent; |
---|
105 | |
---|
106 | CGlobalCacheHash(ring r): CCacheHash<poly>(r) {}; |
---|
107 | |
---|
108 | virtual ~CGlobalCacheHash() {}; |
---|
109 | |
---|
110 | protected: |
---|
111 | virtual void History(const EHistoryType t, const CExponent a, const CExponent b, const poly p = NULL); |
---|
112 | }; |
---|
113 | |
---|
114 | class CSpecialPairCacheHash: public CCacheHash<int> |
---|
115 | { |
---|
116 | public: |
---|
117 | typedef int CExponent; |
---|
118 | |
---|
119 | CSpecialPairCacheHash(ring r): CCacheHash<int>(r) {}; |
---|
120 | |
---|
121 | virtual ~CSpecialPairCacheHash() {}; |
---|
122 | |
---|
123 | protected: |
---|
124 | virtual void History(const EHistoryType t, const CExponent a, const CExponent b, const poly p = NULL); |
---|
125 | }; |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | #endif // GRING_SA_CACHEHASH_H |
---|
130 | |
---|
131 | |
---|