Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

nonduplpool.inc
Go to the documentation of this file.
1 
29 #pragma once
30 
32 
33 namespace abacus {
34 
35 
36 template<class BaseType, class CoType>
37 PoolSlot<BaseType, CoType> * NonDuplPool<BaseType, CoType>::insert(
38  BaseType *cv)
39 {
40 
41  PoolSlot<BaseType, CoType>* slot;
42 
43  slot = present(cv);
44  if (slot == nullptr) {
46  if (slot)
47  hash_.insert(cv->hashKey(), slot);
48  }
49  else {
50  delete cv;
51  nDuplications_++;
52  }
53  return slot;
54 }
55 
56 
57 template<class BaseType, class CoType>
58 PoolSlot<BaseType, CoType> *NonDuplPool<BaseType, CoType>::present(
59  BaseType *cv)
60 {
61  int key = cv->hashKey();
62 
63  PoolSlot<BaseType, CoType> **cand = hash_.initializeIteration(key);
64  while(cand) {
65  if (cv->equal((*cand)->conVar())) {
66  return *cand;
67  }
68  cand = hash_.next(key);
69  }
70  return nullptr;
71 }
72 
73 template<class BaseType, class CoType>
74 const PoolSlot<BaseType, CoType> *NonDuplPool<BaseType, CoType>::present(
75  const BaseType *cv) const
76 {
77  int key = cv->hashKey();
78 
79  PoolSlot<BaseType, CoType> *const *cand = hash_.initializeIteration(key);
80  while(cand) {
81  if (cv->equal((*cand)->conVar())) {
82  return *cand;
83  }
84  cand = hash_.next(key);
85  }
86  return nullptr;
87 }
88 
89 template<class BaseType, class CoType>
90 int NonDuplPool<BaseType, CoType>::softDeleteConVar(PoolSlot<BaseType, CoType> *slot)
91 {
92  int key = slot->conVar()->hashKey();
93 
95  if (hash_.remove(key, slot)) {
96  // Commented out in ABACUS 3.2
97 #if 0
98  Logger::ifout() << "NonDuplPool::softDeleteCon(): slot not found in hash table.\n";
99  OGDF_THROW_PARAM(AlgorithmFailureException, ogdf::afcNonDuplPool);
100 #endif
101  }
102  return 0;
103  }
104  return 1;
105 }
106 
107 
108 template<class BaseType, class CoType>
110  PoolSlot<BaseType, CoType> *slot)
111 {
112  if (hash_.remove(slot->conVar()->hashKey(), slot)) {
113  // Commented out in ABACUS 3.2
114 #if 0
115  Logger::ifout() << "NonDuplPool::hardDeleteConVar(): constraint not found in hash table.\n";
116  OGDF_THROW_PARAM(AlgorithmFailureException, ogdf::afcNonDuplPool);
117 #endif
118  }
120 }
121 
122 }
abacus::NonDuplPool::present
virtual PoolSlot< BaseType, CoType > * present(BaseType *cv)
Checks if constraint/variables cv is already contained in the pool.
abacus
Definition: ILPClusterPlanarity.h:50
abacus::Pool::softDeleteConVar
virtual int softDeleteConVar(PoolSlot< BaseType, CoType > *slot)
Removes the constraint/variable stored in slot from the pool if it can be deleted.
Definition: pool.h:154
abacus::NonDuplPool::hardDeleteConVar
virtual void hardDeleteConVar(PoolSlot< BaseType, CoType > *slot)
Has to be redefined because the pool slot has to be removed from the hash table.
nonduplpool.h
standard pool without constraint duplication.
OGDF_THROW_PARAM
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
Definition: exceptions.h:71
abacus::NonDuplPool::insert
virtual PoolSlot< BaseType, CoType > * insert(BaseType *cv)
Insert constraint/variable cv in the pool.
ogdf::Logger::ifout
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition: Logger.h:218
abacus::StandardPool::insert
virtual PoolSlot< BaseType, CoType > * insert(BaseType *cv)
Tries to insert a constraint/variable in the pool.
abacus::NonDuplPool::softDeleteConVar
virtual int softDeleteConVar(PoolSlot< BaseType, CoType > *slot)
Has to be redefined because the slot has to be removed from the hash table if the constraint/variable...
abacus::Pool::hardDeleteConVar
virtual void hardDeleteConVar(PoolSlot< BaseType, CoType > *slot)
Removes a constraint/variable from the pool and adds the slot to the set of free slots.
Definition: pool.h:168