[1495df4] | 1 | #ifndef GRING_SA_CACHEHASH_H |
---|
| 2 | #define GRING_SA_CACHEHASH_H |
---|
[1367162] | 3 | /***************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | *****************************************/ |
---|
[f78891] | 6 | /* $Id: ncSACache.h,v 1.3 2008-07-18 17:12:37 motsak Exp $ */ |
---|
[1367162] | 7 | |
---|
| 8 | // #include <ncSACache.h> // for CCacheHash etc classes |
---|
| 9 | |
---|
| 10 | #include <structs.h> |
---|
[1495df4] | 11 | #include <febase.h> // for Print! |
---|
[1367162] | 12 | // //////////////////////////////////////////////////////////////////////// // |
---|
| 13 | // |
---|
| 14 | |
---|
| 15 | const int iMaxCacheSize = 20; |
---|
| 16 | |
---|
| 17 | template <typename CExponent> |
---|
| 18 | class CCacheHash |
---|
| 19 | { |
---|
[1495df4] | 20 | private: |
---|
| 21 | ring m_basering; |
---|
| 22 | int m_NVars; |
---|
| 23 | |
---|
[1367162] | 24 | public: |
---|
[1495df4] | 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(){}; |
---|
[f78891] | 31 | |
---|
[1495df4] | 32 | |
---|
[1367162] | 33 | enum EHistoryType { |
---|
[f78891] | 34 | MULT_LOOKUP = 0, |
---|
| 35 | MULT_STORE = 1 |
---|
[1495df4] | 36 | }; |
---|
[1367162] | 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! |
---|
[1495df4] | 58 | int LookupEE(CExponent a, CExponent b, CCacheItem*& pItems) |
---|
[1367162] | 59 | { |
---|
[f78891] | 60 | Print("//////////////////////////////////////////////////////////////////////////////////////////////"); |
---|
| 61 | PrintLn(); |
---|
| 62 | Print("CCacheHash::LookupEE(a, b, *results)!"); |
---|
| 63 | PrintLn(); |
---|
| 64 | |
---|
| 65 | History(MULT_LOOKUP, a, b); |
---|
| 66 | |
---|
[1367162] | 67 | pItems = NULL; |
---|
| 68 | return -1; |
---|
| 69 | } |
---|
| 70 | |
---|
[1495df4] | 71 | bool StoreEE(CExponent a, CExponent b, poly pProduct) |
---|
[1367162] | 72 | { |
---|
[f78891] | 73 | Print("CCacheHash::StoreEE(a, b, Product)!"); |
---|
| 74 | PrintLn(); |
---|
| 75 | |
---|
| 76 | History(MULT_STORE, a, b, pProduct); |
---|
| 77 | |
---|
| 78 | Print("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"); |
---|
| 79 | PrintLn(); |
---|
| 80 | |
---|
[1367162] | 81 | return false; // the pair was not stored! |
---|
| 82 | }; |
---|
| 83 | |
---|
[f78891] | 84 | virtual void History(const EHistoryType t, const CExponent a, const CExponent b, const poly p = NULL) |
---|
[1367162] | 85 | { |
---|
[f78891] | 86 | Print("CCacheHash::History(a, b, [p])!"); |
---|
| 87 | PrintLn(); |
---|
[1367162] | 88 | } |
---|
| 89 | |
---|
| 90 | private: // no copy constuctors! |
---|
[1495df4] | 91 | CCacheHash(const CCacheHash&); |
---|
| 92 | CCacheHash& operator=(const CCacheHash&); |
---|
[1367162] | 93 | }; |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | class CGlobalCacheHash: public CCacheHash<poly> |
---|
| 98 | { |
---|
| 99 | public: |
---|
| 100 | typedef poly CExponent; |
---|
| 101 | |
---|
[1495df4] | 102 | CGlobalCacheHash(ring r): CCacheHash<poly>(r) {}; |
---|
| 103 | |
---|
| 104 | virtual ~CGlobalCacheHash() {}; |
---|
| 105 | |
---|
[1367162] | 106 | protected: |
---|
[f78891] | 107 | virtual void History(const EHistoryType t, const CExponent a, const CExponent b, const poly p = NULL); |
---|
[1367162] | 108 | }; |
---|
| 109 | |
---|
| 110 | class CSpecialPairCacheHash: public CCacheHash<int> |
---|
| 111 | { |
---|
| 112 | public: |
---|
| 113 | typedef int CExponent; |
---|
[1495df4] | 114 | |
---|
| 115 | CSpecialPairCacheHash(ring r): CCacheHash<int>(r) {}; |
---|
| 116 | |
---|
| 117 | virtual ~CSpecialPairCacheHash() {}; |
---|
| 118 | |
---|
[1367162] | 119 | protected: |
---|
[f78891] | 120 | virtual void History(const EHistoryType t, const CExponent a, const CExponent b, const poly p = NULL); |
---|
[1367162] | 121 | }; |
---|
| 122 | |
---|
[1495df4] | 123 | |
---|
| 124 | |
---|
| 125 | #endif // GRING_SA_CACHEHASH_H |
---|
| 126 | |
---|
| 127 | |
---|