43 template<
class BaseType,
class CoType>
46 for (
int i = 0; i < n_; i++) {
47 psRef_[i]->conVar()->unlock();
53 template<
class BaseType,
class CoType>
55 PoolSlot<BaseType, CoType> *slot,
61 psRef_[n_] =
new PoolSlotRef<BaseType, CoType>(slot);
62 keepInPool_[n_] = keepInPool;
64 slot->conVar()->lock();
71 template<
class BaseType,
class CoType>
73 PoolSlot<BaseType, CoType> *slot,
80 psRef_[n_] =
new PoolSlotRef<BaseType, CoType>(slot);
81 keepInPool_[n_] = keepInPool;
84 slot->conVar()->lock();
90 template<
class BaseType,
class CoType>
93 PoolSlotRef<BaseType, CoType> *psr;
95 const int nIndex = index.size();
97 for (
int i = 0; i < nIndex; i++) {
98 psr = psRef_[index[i]];
99 psr->conVar()->unlock();
100 PoolSlot<BaseType, CoType> *ps = psr->slot();
102 if (ps->conVar()->deletable())
103 ps->removeConVarFromPool();
105 psRef_.leftShift(index);
106 keepInPool_.leftShift(index);
107 rank_.leftShift(index);
113 template<
class BaseType,
class CoType>
117 if (n_ > threshold) {
130 Array< ogdf::Prioritized<int> > things(n_);
131 for (
int i = 0; i < n_; i++) {
132 things[i].setItem(i);
133 things[i].setPriority(-rank_[i]);
139 Array<PoolSlotRef<BaseType, CoType>*> psRefSorted(n_);
140 Array<bool> keepInPoolSorted(n_);
142 for (
int i = 0; i < n_; i++) {
143 psRefSorted[i] = psRef_[things[i].item()];
144 keepInPoolSorted[i] = keepInPool_[things[i].item()];
147 for (
int i = 0; i < n_; i++) {
148 psRef_[i] = psRefSorted[i];
149 keepInPool_[i] = keepInPoolSorted[i];
152 Logger::ilout(Logger::Level::Minor) <<
"\titems ranked: accepted in " << -things[0].priority() <<
" ... " 153 << -things[threshold - 1].priority() <<
", rejected in " 154 << -things[threshold].priority() <<
" ... " << -things[n_ - 1].priority() << endl;
158 Logger::ilout(Logger::Level::Minor) <<
"\tnot enough items, no ranking required" << endl;
161 Logger::ilout(Logger::Level::Minor) <<
"\tranking of buffered items not possible" << endl;
165 template<
class BaseType,
class CoType>
168 ArrayBuffer<PoolSlot<BaseType, CoType>*> &newSlots)
171 for (
int i = 0; i < n_; i++)
172 psRef_[i]->conVar()->unlock();
177 if (n_ < max) nExtract = n_;
190 PoolSlot<BaseType, CoType> *s;
192 for (
int i = nExtract; i < n_; i++) {
193 if (!keepInPool_[i]) {
194 s = psRef_[i]->slot();
196 if (s->conVar()->deletable())
197 s->removeConVarFromPool();
199 else delete psRef_[i];
205 for (
int i = 0; i < nExtract; i++) {
206 newSlots.push(psRef_[i]->slot());
Declarations for Comparer objects.
void sort(int threshold)
Sorts the items according to their ranks.
~CutBuffer()
The destructor.
int insert(PoolSlot< BaseType, CoType > *slot, bool keepInPool)
Adds a slot to the buffer.
void remove(ArrayBuffer< int > &index)
Removes the elements specified by index from the buffer.
static std::ostream & ilout(Level l=Level::Default)
void extract(int max, ArrayBuffer< PoolSlot< BaseType, CoType > *> &newSlots)
Takes the first max items from the buffer and clears the buffer.