/usr/include/polybori/cache/CCacheManagement.h is in libbrial-dev 0.8.5-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | // -*- c++ -*-
//*****************************************************************************
/** @file CCacheManagement.h
*
* @author Alexander Dreyer
* @date 2006-10-23
*
* This file
*
* @par Copyright:
* (c) 2006-2010 by The PolyBoRi Team
*
**/
//*****************************************************************************
#ifndef polybori_cache_CCacheManagement_h_
#define polybori_cache_CCacheManagement_h_
// include basic definitions
#include <polybori/pbori_defs.h>
// get DD navigation
#include <polybori/iterators/CCuddNavigator.h>
#include <polybori/ring/CCuddCore.h>
#include <boost/intrusive_ptr.hpp>
// get standard functionality
#include <functional>
BEGIN_NAMESPACE_PBORI
class CCacheTypes {
public:
struct no_cache_tag { enum { nargs = 0 }; };
struct unary_cache_tag { enum { nargs = 1 }; };
struct binary_cache_tag { enum { nargs = 2 }; };
struct ternary_cache_tag { enum { nargs = 3 }; };
template <class TagType>
struct lead_tag: public binary_cache_tag {};
// user functions
struct no_cache: public no_cache_tag { };
struct union_xor: public binary_cache_tag { };
struct multiply_recursive: public binary_cache_tag { };
struct divide: public binary_cache_tag { };
struct minimal_mod: public binary_cache_tag { };
struct minimal_elements: public unary_cache_tag { };
struct multiplesof: public binary_cache_tag { };
struct divisorsof: public binary_cache_tag { };
struct ll_red_nf: public binary_cache_tag { };
struct plug_1: public binary_cache_tag { };
struct exist_abstract: public binary_cache_tag { };
struct degree: public unary_cache_tag { };
struct has_factor_x: public binary_cache_tag { };
struct has_factor_x_plus_one: public binary_cache_tag { };
struct mod_varset: public binary_cache_tag { };
struct interpolate: public binary_cache_tag { };
struct zeros: public binary_cache_tag { };
struct interpolate_smallest_lex: public binary_cache_tag { };
struct include_divisors: public unary_cache_tag { };
//struct mod_deg2_set: public binary_cache_tag { };
typedef mod_varset mod_deg2_set;
typedef mod_varset mod_mon_set;
struct contained_deg2: public unary_cache_tag { };
struct contained_variables: public unary_cache_tag { };
struct map_every_x_to_x_plus_one: public unary_cache_tag { };
struct lex_lead: public unary_cache_tag {};
typedef lead_tag<dlex_tag> dlex_lead;
typedef lead_tag<dp_asc_tag> dp_asc_lead;
typedef lead_tag<block_dlex_tag> block_dlex_lead;
typedef lead_tag<block_dp_asc_tag> block_dp_asc_lead;
struct divisorsof_fixedpath: public ternary_cache_tag { };
struct testwise_ternary: public ternary_cache_tag { };
struct used_variables: public unary_cache_tag { };
struct block_degree: public binary_cache_tag { };
struct has_factor_x_plus_y: public ternary_cache_tag { };
struct left_equals_right_x_branch_and_r_has_fac_x:
public ternary_cache_tag { };
struct graded_part: public binary_cache_tag { };
struct mapping: public binary_cache_tag { };
struct is_rewriteable: public binary_cache_tag{};
};
// Reserve integer Numbers for Ternary operations (for cudd)
template <class TagType>
struct count_tags;
template<>
struct count_tags<CCacheTypes::divisorsof_fixedpath>{
enum { value = 0 };
};
template <class BaseTag>
struct increment_count_tags {
enum{ value = count_tags<BaseTag>::value + 1 };
};
template<>
class count_tags<CCacheTypes::testwise_ternary>:
public increment_count_tags<CCacheTypes::divisorsof_fixedpath>{ };
template<>
class count_tags<CCacheTypes::left_equals_right_x_branch_and_r_has_fac_x>:
public increment_count_tags<CCacheTypes::testwise_ternary>{ };
template<>
class count_tags<CCacheTypes::has_factor_x_plus_y>:
public increment_count_tags<CCacheTypes::left_equals_right_x_branch_and_r_has_fac_x>{ };
// generate tag number (special pattern with 4 usable bits)
// 18 bits are already used
template <unsigned Counted, unsigned Offset = 18>
class cudd_tag_number {
public:
enum { value =
( ((Counted + Offset) & 0x3 ) << 2) |
( ((Counted + Offset) & 0x1C ) << 3) | 0x2 };
};
/** @class CCuddLikeMgrStorage
*
* This template defines how to used the Cudd-like decision diagram managers
* like Cudd and CCuddInterface.
**/
template <class MgrType>
class CCuddLikeMgrStorage {
public:
/// Set manager type
typedef MgrType manager_type;
/// Set type of Cudd's internal manager type
typedef DdManager* internal_manager_type;
/// Set type of Cudd's nodes
typedef DdNode* node_type;
/// Type of navigators
typedef CCuddNavigator navigator;
// typedef CTypes::dd_base dd_base;
// typedef typename manager_type::mgrcore_ptr mgrcore_ptr;
/// Type of Boolean rings
typedef BoolePolyRing ring_type;
/// Get high-level decision diagram type
typedef typename ring_type::dd_type dd_type;
/// Constructor
CCuddLikeMgrStorage(const manager_type& mgr):
m_mgr(mgr) {}
// CCuddLikeMgrStorage(const mgrcore_ptr& mgr):
// m_mgr(mgr) {}
/// Accessing manager
manager_type manager() const { return m_mgr; }
/// Re-generate valid decision diagram from navigator
dd_type generate(navigator navi) const {
return dd_type(m_mgr, navi);
}
/// Get constant one
dd_type one() const {
return ring_type(m_mgr).one();//dd_type(m_mgr, DD_ONE(m_mgr->manager()));//manager().zddOne();
}
/// Get constant zero
dd_type zero() const {
return ring_type(m_mgr).zero();//dd_base(m_mgr, PBORI_PREFIX(Cudd_ReadZero)(m_mgr->manager()));//manager().zddZero();
}
ring_type ring() const { return ring_type(manager()); }
protected:
/// Accessing Cudd-internal decision diagram manager
internal_manager_type internalManager() const {
return m_mgr.getManager();
// return manager().getManager();
}
private:
/// Store (pointer) to internal manager
manager_type m_mgr;
// typename manager_type::mgrcore_ptr m_mgr;
};
/** @class CCacheManBase
*
* @brief This template forms the base for CCacheManagement. It implements
* routines for finding and inserting results into the cache.
*
* Template arguments: ManagerType, CacheType, nArgs
*
* @note We have template specializations for nArgs = 1, 2, 3 corresponding to
* unary, binary and ternary funtions to be cached. In addition, nArgs = 0 is
* used, when no cache is used.
**/
template <class ManagerType, class CacheType, unsigned ArgumentLength>
class CCacheManBase;
// Fixing base type for Cudd-Like type CCuddInterface
template <class CacheType, unsigned ArgumentLength>
struct pbori_base<CCacheManBase<CCuddInterface, CacheType, ArgumentLength> > {
typedef CCuddLikeMgrStorage<CCuddInterface> type;
};
// Fixing base type for Cudd-Like type CCuddInterface
template <class CacheType, unsigned ArgumentLength>
struct pbori_base<CCacheManBase<BoolePolyRing, CacheType, ArgumentLength> > {
typedef CCuddLikeMgrStorage<BoolePolyRing> type;
};
// Fixing base type for Cudd-Like type CCuddInterface
template <class CacheType, unsigned ArgumentLength>
struct pbori_base<CCacheManBase<boost::intrusive_ptr<CCuddCore>, CacheType, ArgumentLength> > {
typedef CCuddLikeMgrStorage<boost::intrusive_ptr<CCuddCore> > type;
};
// Dummy variant for generating empty cache managers, e.g. for using generate()
template <class ManagerType, class CacheType>
class CCacheManBase<ManagerType, CacheType, 0> :
public pbori_base<CCacheManBase<ManagerType, CacheType, 0> >::type {
public:
/// Set this type
typedef CCacheManBase<ManagerType, CacheType, 0> self;
/// Set base type
typedef typename pbori_base<self>::type base;
/// @name Extracting inherited types
//@{
typedef typename base::node_type node_type;
typedef typename base::navigator navigator;
typedef typename base::manager_type manager_type;
//@}
/// Constructor
CCacheManBase(const manager_type& mgr): base(mgr) {}
/// @name Dummy functions
//@{
navigator find(navigator, ...) const { return navigator(); }
node_type find(node_type, ...) const { return NULL; }
void insert(...) const {}
//@}
};
// Variant for unary functions
template <class ManagerType, class CacheType>
class CCacheManBase<ManagerType, CacheType, 1> :
public pbori_base<CCacheManBase<ManagerType, CacheType, 1> >::type {
public:
/// Set this type
typedef CCacheManBase<ManagerType, CacheType, 1> self;
/// Set base type
typedef typename pbori_base<self>::type base;
/// @name Extracting inherited types
//@{
typedef typename base::node_type node_type;
typedef typename base::navigator navigator;
typedef typename base::manager_type manager_type;
//@}
/// Constructor
CCacheManBase(const manager_type& mgr): base(mgr) {}
/// Find cached value wrt. given node
node_type find(node_type node) const {
return PBORI_PREFIX(cuddCacheLookup1Zdd)(internalManager(), cache_dummy, node);
}
/// Find cached value wrt. given node (for navigator type)
navigator find(navigator node) const {
return explicit_navigator_cast(find(node.getNode()));
}
/// Store cached value wrt. given node
void insert(node_type node, node_type result) const {
PBORI_PREFIX(Cudd_Ref)(result);
PBORI_PREFIX(cuddCacheInsert1)(internalManager(), cache_dummy, node, result);
PBORI_PREFIX(Cudd_Deref)(result);
}
/// Store cached value wrt. given node
void insert(navigator node, navigator result) const {
insert(node.getNode(), result.getNode());
}
protected:
/// Access manager used for caching
using base::internalManager;
private:
/// Define unique static function, as marker for Cudd cache
static node_type cache_dummy(typename base::internal_manager_type,node_type){ // LCOV_EXCL_LINE
return NULL; // LCOV_EXCL_LINE
}
};
// Variant for binary functions
template <class ManagerType, class CacheType>
class CCacheManBase<ManagerType, CacheType, 2> :
public pbori_base<CCacheManBase<ManagerType, CacheType, 2> >::type {
public:
/// Set this type
typedef CCacheManBase<ManagerType, CacheType, 2> self;
/// Set base type
typedef typename pbori_base<self>::type base;
/// @name Extracting inherited types
//@{
typedef typename base::node_type node_type;
typedef typename base::navigator navigator;
typedef typename base::manager_type manager_type;
//@}
/// Constructor
CCacheManBase(const manager_type& mgr): base(mgr) {}
/// Find cached value wrt. given node
node_type find(node_type first, node_type second) const {
return PBORI_PREFIX(cuddCacheLookup2Zdd)(internalManager(), cache_dummy, first, second);
}
/// Find cached value wrt. given node (for navigator type)
navigator find(navigator first, navigator second) const {
return explicit_navigator_cast(find(first.getNode(), second.getNode()));
}
/// Store cached value wrt. given node
void insert(node_type first, node_type second, node_type result) const {
PBORI_PREFIX(Cudd_Ref)(result);
PBORI_PREFIX(cuddCacheInsert2)(internalManager(), cache_dummy, first, second, result);
PBORI_PREFIX(Cudd_Deref)(result);
}
/// Store cached value wrt. given node
void insert(navigator first, navigator second, navigator result) const {
insert(first.getNode(), second.getNode(), result.getNode());
}
protected:
/// Access manager used for caching
using base::internalManager;
private:
/// Define unique static function, as marker for Cudd cache
static node_type cache_dummy(typename base::internal_manager_type, // LCOV_EXCL_LINE
node_type, node_type){ // LCOV_EXCL_LINE
return NULL; // LCOV_EXCL_LINE
}
};
// Variant for ternary functions
template <class ManagerType, class CacheType>
class CCacheManBase<ManagerType, CacheType, 3> :
public pbori_base<CCacheManBase<ManagerType, CacheType, 3> >::type {
public:
/// Set this type
typedef CCacheManBase<ManagerType, CacheType, 3> self;
/// Set base type
typedef typename pbori_base<self>::type base;
/// @name Extracting inherited types
//@{
typedef typename base::node_type node_type;
typedef typename base::navigator navigator;
typedef typename base::manager_type manager_type;
//@}
/// Constructor
CCacheManBase(const manager_type& mgr): base(mgr) {}
/// Find cached value wrt. given node
node_type find(node_type first, node_type second, node_type third) const {
return PBORI_PREFIX(cuddCacheLookupZdd)(internalManager(), (ptruint)GENERIC_DD_TAG,
first, second, third);
}
/// Find cached value wrt. given node (for navigator type)
navigator find(navigator first, navigator second, navigator third) const {
return explicit_navigator_cast(find(first.getNode(), second.getNode(),
third.getNode()));
}
/// Store cached value wrt. given node
void insert(node_type first, node_type second, node_type third,
node_type result) const {
PBORI_PREFIX(Cudd_Ref)(result);
PBORI_PREFIX(cuddCacheInsert)(internalManager(), (ptruint)GENERIC_DD_TAG,
first, second, third, result);
PBORI_PREFIX(Cudd_Deref)(result);
}
/// Store cached value wrt. given node
void insert(navigator first, navigator second, navigator third,
navigator result) const {
insert(first.getNode(), second.getNode(), third.getNode(),
result.getNode());
}
protected:
/// Access manager used for caching
using base::internalManager;
private:
enum { GENERIC_DD_TAG =
cudd_tag_number<count_tags<CacheType>::value>::value };
};
/** @class CCacheManagement
*
* @brief This template class forms the base for CCommutativeCacheManagement and
* CacheManager. It is an interface defining find and insert on decision diagram
* cache.
*
* It it mainly a wrapper for the template specialization of CCacheManBase,
* which allows a simple call of CCacheManagement<CacheType>, if CacheType is
* inherited from unary_cache_tag, binary_cache_tag, and ternary_cache_tag.
* It also fixes the ManagerType to CTypes::manager_base.
*
**/
template <class ManagerType, class CacheType,
unsigned ArgumentLength = CacheType::nargs>
class CCacheManagement:
public CCacheManBase<ManagerType,
CacheType, ArgumentLength> {
public:
/// @name Get template parameters and global types
//@{
typedef ManagerType manager_type;
typedef typename manager_type::deg_type deg_type;
typedef typename manager_type::size_type size_type;
typedef typename manager_type::idx_type idx_type;
typedef CacheType cache_type;
enum { nargs = ArgumentLength };
//@}
/// Name base type
typedef CCacheManBase<manager_type, cache_type, nargs> base;
/// Extracting inherited node type
typedef typename base::node_type node_type;
/// Constructor and default constructor
CCacheManagement(const manager_type& mgr):
base(mgr) {}
using base::find;
using base::insert;
};
/** @class CCommutativeCacheManagement
* This is the variant for cache management of binary commutative functions.
**/
template <class ManagerType, class CacheType>
class CCommutativeCacheManagement:
public CCacheManagement<ManagerType, CacheType, 2> {
public:
/// @name Get template parameters
//@{
typedef ManagerType manager_type;
typedef CacheType cache_type;
//@}
/// Name base type
typedef CCacheManagement<manager_type, cache_type, 2> base;
/// Define node type
typedef typename base::node_type node_type;
typedef typename base::navigator navigator;
/// Constructor and default constructor
CCommutativeCacheManagement(const typename base::manager_type& mgr):
base(mgr) {}
/// Find cached value wrt. given node
node_type find(node_type first, node_type second) const {
if ( std::less<node_type>()(first, second) )
return base::find(first, second);
else
return base::find(second, first);
}
/// Find cached value wrt. given node (for navigator type)
navigator find(navigator first, navigator second) const {
return explicit_navigator_cast(find(first.getNode(), second.getNode()));
}
/// Store cached value wrt. given node
void insert(node_type first, node_type second, node_type result) const {
if ( std::less<node_type>()(first, second) )
base::insert(first, second, result);
else
base::insert(second, first, result);
}
/// Store cached value wrt. given node (for navigator type)
void insert(navigator first, navigator second, navigator result) const {
insert(first.getNode(), second.getNode(), result.getNode());
}
};
END_NAMESPACE_PBORI
#endif
|