00001
00002
00014
00015
00016 #ifndef polybori_groebner_PolyEntryIndices_h_
00017 #define polybori_groebner_PolyEntryIndices_h_
00018
00019
00020 #include "groebner_defs.h"
00021 #include "PolyEntry.h"
00022
00023 BEGIN_NAMESPACE_PBORIGB
00024
00025 typedef Monomial::idx_map_type lm2Index_map_type;
00026 typedef Exponent::idx_map_type exp2Index_map_type;
00027
00033 class PolyEntryIndices {
00034
00035 class check {};
00036 class uncheck {};
00037
00038 public:
00039 typedef Monomial::idx_map_type lm2Index_map_type;
00040 typedef Exponent::idx_map_type exp2Index_map_type;
00041 typedef lm2Index_map_type::value_type value_type;
00042 typedef value_type::second_type data_type;
00043
00044 PolyEntryIndices():
00045 lm2Index(), exp2Index() {}
00046
00048 void insert(const PolyEntry& entry, const data_type& rhs) {
00049 exp2Index[entry.leadExp] = rhs;
00050 lm2Index[entry.lead] = rhs;
00051 }
00052
00054 void update(const Monomial& key, const PolyEntry& entry) {
00055
00056 if PBORI_UNLIKELY(entry.lead != key) {
00057 lm2Index_map_type::iterator lm_pos = lm2Index.find(key);
00058 PBORI_ASSERT(lm_pos != lm2Index.end());
00059 lm2Index[entry.lead] = lm_pos->second;
00060 exp2Index[entry.leadExp] = lm_pos->second;
00061 lm2Index.erase(lm_pos);
00062 exp2Index.erase(exp2Index.find(key.exp()));
00063 }
00064 }
00065
00067 template <class KeyType>
00068 data_type operator()(const KeyType& key) const {
00069 return get(key, uncheck());
00070 }
00071
00073 template <class KeyType>
00074 data_type checked(const KeyType& key) const {
00075 return get(key, check());
00076 }
00077
00078 protected:
00079
00080
00081 template <class CheckType>
00082 data_type get(data_type key, CheckType) const { return key; }
00083
00084 template <class CheckType>
00085 data_type get(const Exponent& key, CheckType dummy) const {
00086 return get(exp2Index, key, dummy);
00087 }
00088
00089 template <class CheckType>
00090 data_type get(const Monomial& key, CheckType dummy) const {
00091 return get(lm2Index, key, dummy);
00092 }
00093
00094 template <class CheckType>
00095 data_type get(const PolyEntry& key, CheckType dummy) const {
00096 return get(lm2Index, key.lead, dummy);
00097 }
00098
00099 template <class MapType, class KeyType>
00100 data_type get(const MapType& map, const KeyType& key, check) const {
00101
00102 typename MapType::const_iterator result(map.find(key));
00103
00104 if (result == map.end())
00105 return (data_type)-1;
00106
00107 PBORI_ASSERT(result->second != data_type(-1));
00108 return result->second;
00109 }
00110
00111 template <class MapType, class KeyType>
00112 data_type get(const MapType& map, const KeyType& key, uncheck) const {
00113
00114 typename MapType::const_iterator result(map.find(key));
00115 PBORI_ASSERT(result != map.end());
00116 return result->second;
00117 }
00118
00119 private:
00120 lm2Index_map_type lm2Index;
00121 exp2Index_map_type exp2Index;
00122 };
00123
00124
00125 END_NAMESPACE_PBORIGB
00126
00127 #endif