PolyBoRi
PolyEntryIndices.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
14 //*****************************************************************************
15 
16 #ifndef polybori_groebner_PolyEntryIndices_h_
17 #define polybori_groebner_PolyEntryIndices_h_
18 
19 // include basic definitions
20 #include "groebner_defs.h"
21 #include "PolyEntry.h"
22 
24 
27 
34 
35  class check {};
36  class uncheck {};
37 
38 public:
41  typedef lm2Index_map_type::value_type value_type;
42  typedef value_type::second_type data_type;
43 
45  lm2Index(), exp2Index() {}
46 
48  void insert(const PolyEntry& entry, const data_type& rhs) {
49  exp2Index[entry.leadExp] = rhs;
50  lm2Index[entry.lead] = rhs;
51  }
52 
54  void update(const Monomial& key, const PolyEntry& entry) {
55 
56  if PBORI_UNLIKELY(entry.lead != key) {
57  lm2Index_map_type::iterator lm_pos = lm2Index.find(key);
58  PBORI_ASSERT(lm_pos != lm2Index.end());
59  lm2Index[entry.lead] = lm_pos->second;
60  exp2Index[entry.leadExp] = lm_pos->second;
61  lm2Index.erase(lm_pos);
62  exp2Index.erase(exp2Index.find(key.exp()));
63  }
64  }
65 
67  template <class KeyType>
68  data_type operator()(const KeyType& key) const {
69  return get(key, uncheck());
70  }
71 
73  template <class KeyType>
74  data_type checked(const KeyType& key) const {
75  return get(key, check());
76  }
77 
78 protected:
79 
80 
81  template <class CheckType>
82  data_type get(data_type key, CheckType) const { return key; }
83 
84  template <class CheckType>
85  data_type get(const Exponent& key, CheckType dummy) const {
86  return get(exp2Index, key, dummy);
87  }
88 
89  template <class CheckType>
90  data_type get(const Monomial& key, CheckType dummy) const {
91  return get(lm2Index, key, dummy);
92  }
93 
94  template <class CheckType>
95  data_type get(const PolyEntry& key, CheckType dummy) const {
96  return get(lm2Index, key.lead, dummy);
97  }
98 
99  template <class MapType, class KeyType>
100  data_type get(const MapType& map, const KeyType& key, check) const {
101 
102  typename MapType::const_iterator result(map.find(key));
103 
104  if (result == map.end())
105  return (data_type)-1;
106 
107  PBORI_ASSERT(result->second != data_type(-1));
108  return result->second;
109  }
110 
111  template <class MapType, class KeyType>
112  data_type get(const MapType& map, const KeyType& key, uncheck) const {
113 
114  typename MapType::const_iterator result(map.find(key));
115  PBORI_ASSERT(result != map.end());
116  return result->second;
117  }
118 
119 private:
120  lm2Index_map_type lm2Index;
121  exp2Index_map_type exp2Index;
122 };
123 
124 
126 
127 #endif /* polybori_groebner_PolyEntryIndices_h_ */