Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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