00001
00002
00014
00015
00016 #ifndef polybori_cache_CDegreeCache_h_
00017 #define polybori_cache_CDegreeCache_h_
00018
00019
00020 #include <polybori/pbori_defs.h>
00021 #include <polybori/BooleEnv.h>
00022
00023 #include "CCacheManagement.h"
00024
00025 BEGIN_NAMESPACE_PBORI
00026
00032 template <class NaviType>
00033 class CIndexHandle {
00034 public:
00035
00036 enum { invalid = CTypes::max_idx };
00037
00039 typedef NaviType navigator;
00040
00042 typedef navigator base;
00043
00045 typedef typename navigator::bool_type bool_type;
00046
00048 typedef typename CTypes::idx_type idx_type;
00049
00051 typedef typename CTypes::size_type size_type;
00052
00054 typedef BoolePolyRing manager_type;
00055
00057 CIndexHandle(idx_type idx): m_idx(idx) {}
00058
00060 explicit CIndexHandle(navigator navi, const manager_type& mgr):
00061 m_idx(fromNode(navi, mgr)) {}
00062
00064 idx_type operator*() const {
00065 return m_idx;
00066 }
00067
00068 bool isValid() const {
00069 return (m_idx != invalid);
00070 }
00071 protected:
00073 idx_type fromNode(navigator navi, const manager_type& mgr) const {
00074
00075 if (!navi.isValid())
00076 return invalid;
00077
00078 if PBORI_UNLIKELY(navi.isConstant())
00079 return mgr.nVariables();
00080 else
00081 return *navi;
00082 }
00083
00084
00085
00086 idx_type m_idx;
00087 };
00088
00089
00090 template <class NaviType>
00091 class CIndexCacheHandle {
00092 public:
00093
00095 typedef NaviType navigator;
00096
00098
00099
00101 typedef typename navigator::bool_type bool_type;
00102
00104 typedef typename navigator::value_type idx_type;
00105
00107 typedef typename navigator::size_type size_type;
00108
00110 typedef BoolePolyRing manager_type;
00111
00113 CIndexCacheHandle(idx_type idx, const manager_type& mgr):
00114 m_navi( toNode(idx, mgr) ) {}
00115
00117 explicit CIndexCacheHandle(navigator navi):
00118 m_navi(navi) {}
00119
00120 operator navigator() const { return m_navi; }
00121
00122 protected:
00124 navigator toNode(idx_type idx, const manager_type& mgr) const {
00125
00126 if PBORI_LIKELY((size_type)idx < mgr.nVariables())
00127 return mgr.variable(idx).set().navigation();
00128
00129 return mgr.zero().navigation();
00130 }
00131
00133 navigator m_navi;
00134 };
00135
00136 template <class DDType>
00137 class CDegreeCache:
00138 public CCacheManagement<BoolePolyRing, typename CCacheTypes::degree, 1> {
00139 typedef CDegreeCache self;
00140 public:
00142
00143 typedef DDType dd_type;
00144 typedef typename CCacheTypes::degree tag_type;
00145 typedef CCacheManagement<BoolePolyRing, tag_type, 1> base;
00147
00149
00150 typedef typename base::node_type input_node_type;
00151 typedef typename base::manager_type manager_type;
00152 typedef typename dd_type::navigator navi_type;
00153 typedef CIndexHandle<navi_type> node_type;
00154 typedef CIndexCacheHandle<navi_type> node_cache_type;
00156
00158 CDegreeCache(const manager_type& mgr): base(mgr) {}
00159
00161 CDegreeCache(const self& rhs): base(rhs) {}
00162
00164 ~CDegreeCache() {}
00165
00167 node_type find(input_node_type navi) const{
00168 return node_type(base::find(navi), base::manager()); }
00169
00170 node_type find(navi_type navi) const{
00171 return node_type(base::find(navi), base::manager()); }
00172
00174 void insert(input_node_type navi, deg_type deg) const {
00175 base::insert(navi, node_cache_type(deg, base::manager()));
00176 }
00177
00179 void insert(navi_type navi, deg_type deg) const {
00180 base::insert(navi, node_cache_type(deg, base::manager()));
00181 }
00183 node_type find(input_node_type navi, deg_type) const { return self::find(navi); }
00184
00185 node_type find(navi_type navi, deg_type) const{ return self::find(navi); }
00186
00188 void insert(input_node_type navi, deg_type, deg_type deg) const {
00189 self::insert(navi, deg);
00190 }
00191
00193 void insert(navi_type navi, deg_type, deg_type deg) const {
00194 self::insert(navi, deg);
00195 }
00196
00197 };
00198
00199 template <class DDType>
00200 class CBoundedDegreeCache:
00201 public CCacheManagement<BoolePolyRing, typename CCacheTypes::degree, 2> {
00202 typedef CBoundedDegreeCache self;
00203 public:
00205
00206 typedef DDType dd_type;
00207 typedef typename CCacheTypes::degree tag_type;
00208 typedef CCacheManagement<BoolePolyRing, tag_type, 2> base;
00210
00212
00213 typedef typename base::node_type input_node_type;
00214 typedef typename base::manager_type manager_type;
00215 typedef typename dd_type::navigator navi_type;
00216 typedef CIndexHandle<navi_type> node_type;
00217 typedef CIndexCacheHandle<navi_type> node_cache_type;
00219
00221 CBoundedDegreeCache(const manager_type& mgr): base(mgr) {}
00222
00224 CBoundedDegreeCache(const self& rhs): base(rhs) {}
00225
00227 ~CBoundedDegreeCache() {}
00228
00230 node_type find(input_node_type navi, deg_type upper_bound) const{
00231 return node_type(base::find(navi,
00232 node_cache_type(upper_bound, base::manager())),
00233 base::manager());
00234 }
00235
00236 node_type find(navi_type navi, deg_type upper_bound) const{
00237 return node_type(base::find(navi,
00238 node_cache_type(upper_bound, base::manager())),
00239 base::manager());
00240 }
00241
00243 void insert(input_node_type navi, deg_type upper_bound, deg_type deg) const {
00244 base::insert(navi, node_cache_type(upper_bound, base::manager()),
00245 node_cache_type(deg, base::manager()));
00246 }
00247
00249 void insert(navi_type navi, deg_type upper_bound, deg_type deg) const {
00250 base::insert(navi, node_cache_type(upper_bound, base::manager()),
00251 node_cache_type(deg, base::manager()));
00252 }
00253
00254 };
00255
00256
00257 template <class DDType>
00258 class CBlockDegreeCache:
00259 public CCacheManagement<BoolePolyRing,
00260 typename CCacheTypes::block_degree, 2> {
00261
00262 public:
00264
00265 typedef DDType dd_type;
00266 typedef typename CCacheTypes::block_degree tag_type;
00267 typedef CCacheManagement<BoolePolyRing, tag_type, 2> base;
00268 typedef CBlockDegreeCache<dd_type> self;
00270
00272
00273 typedef typename base::node_type input_node_type;
00274 typedef typename base::manager_type manager_type;
00275 typedef typename dd_type::navigator navi_type;
00276 typedef CIndexHandle<navi_type> node_type;
00277 typedef CIndexCacheHandle<navi_type> node_cache_type;
00279
00281 CBlockDegreeCache(const manager_type& mgr): base(mgr) {}
00282
00284 CBlockDegreeCache(const self& rhs): base(rhs) {}
00285
00287 ~CBlockDegreeCache() {}
00288
00290 node_type find(input_node_type navi, idx_type idx) const{
00291 return node_type(base::find(navi, node_cache_type(idx, base::manager())),
00292 base::manager()); }
00293
00294 node_type find(navi_type navi, idx_type idx) const{
00295 return node_type(base::find(navi, node_cache_type(idx, base::manager())),
00296 base::manager()); }
00297
00299 void insert(input_node_type navi, idx_type idx, size_type deg) const {
00300 base::insert(navi, node_cache_type(idx, base::manager()),
00301 node_cache_type(deg, base::manager()));
00302 }
00303
00305 void insert(navi_type navi, idx_type idx, size_type deg) const {
00306 base::insert(navi, node_cache_type(idx, base::manager()),
00307 node_cache_type(deg, base::manager()));
00308 }
00309 };
00310
00311 template <class TagType,
00312 class DDType>
00313 class CDegreeArgumentCache:
00314 public CCacheManagement<BoolePolyRing, TagType, 2>,
00315 public CAuxTypes {
00316
00317 public:
00319
00320 typedef DDType dd_type;
00321 typedef TagType tag_type;
00322 typedef CCacheManagement<BoolePolyRing, tag_type, 2> base;
00323 typedef CDegreeArgumentCache<tag_type, dd_type> self;
00325
00327
00328 typedef typename base::node_type node_type;
00329 typedef typename base::manager_type manager_type;
00330 typedef typename dd_type::navigator navi_type;
00331 typedef CIndexCacheHandle<navi_type> degree_node_type;
00333
00335 CDegreeArgumentCache(const manager_type& mgr): base(mgr) {}
00336
00338 CDegreeArgumentCache(const self& rhs): base(rhs) {}
00339
00341 ~CDegreeArgumentCache() {}
00342
00344 navi_type find(navi_type navi, size_type deg) const{
00345 return base::find(navi, degree_node_type(deg, base::manager()));
00346 }
00347
00349 void insert(navi_type navi, size_type deg, navi_type result) const {
00350 base::insert(navi, degree_node_type(deg, base::manager()), result);
00351 }
00352
00353 };
00354
00355
00356 END_NAMESPACE_PBORI
00357
00358 #endif