Skip to content

Commit 566bbaa

Browse files
committed
Advance PairQuantity ticker on pair-mask change.
Check if PairQuantity::setPairMask introduces any change to mask data and if so, advance the ticker.
1 parent cc5f6fa commit 566bbaa

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

src/diffpy/srreal/PairQuantity.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,34 +218,45 @@ void PairQuantity::setPairMask(int i, int j, bool mask)
218218
this->maskAllPairs(mask);
219219
return;
220220
}
221+
bool modified = false;
221222
// update ticker if we are switching from type-mask mode
222223
if (!mtypemask.empty())
223224
{
224225
mtypemask.clear();
225-
mticker.click();
226+
modified = true;
226227
}
227228
// handle one ALLATOMSINT argument
228229
if (ALLATOMSINT == i || ALLATOMSINT == j)
229230
{
230231
int k = (ALLATOMSINT != i) ? i : j;
231-
msiteallmask[k] = mask;
232+
pair<boost::unordered_map<int, bool>::iterator, bool> pmm;
233+
pmm = msiteallmask.emplace(k, mask);
234+
if (pmm.second || pmm.first->second != mask) modified = true;
235+
pmm.first->second = mask;
232236
int cntsites = this->countSites();
233237
for (int l = 0; l < cntsites; ++l)
234238
{
235239
this->setPairMaskValue(k, l, mask);
236240
}
241+
if (modified) mticker.click();
237242
return;
238243
}
239244
// here neither i nor j is ALLATOMSINT
240-
if (msiteallmask.count(i) && mask != msiteallmask.at(i))
245+
boost::unordered_map<int, bool>::iterator ii, jj;
246+
ii = msiteallmask.find(i);
247+
if (ii != msiteallmask.end() && mask != ii->second)
241248
{
242-
msiteallmask.erase(i);
249+
msiteallmask.erase(ii);
250+
modified = true;
243251
}
244-
if (msiteallmask.count(j) && mask != msiteallmask.at(j))
252+
jj = msiteallmask.find(j);
253+
if (jj != msiteallmask.end() && mask != jj->second)
245254
{
246-
msiteallmask.erase(j);
255+
msiteallmask.erase(jj);
256+
modified = true;
247257
}
248-
this->setPairMaskValue(i, j, mask);
258+
modified = this->setPairMaskValue(i, j, mask) ? true : modified;
259+
if (modified) mticker.click();
249260
}
250261

251262

@@ -299,10 +310,11 @@ setTypeMask(string smbli, string smblj, bool mask)
299310
else ++tpmsk;
300311
}
301312
}
302-
modified = modified ||
303-
!(mtypemask.count(smblij) && mtypemask.at(smblij) == mask);
313+
pair<TypeMaskStorage::iterator, bool> pmm;
314+
pmm = mtypemask.emplace(smblij, mask);
315+
if (pmm.second || pmm.first->second != mask) modified = true;
316+
pmm.first->second = mask;
304317
if (modified) mticker.click();
305-
mtypemask[smblij] = mask;
306318
}
307319

308320

@@ -461,12 +473,15 @@ void PairQuantity::updateMaskData()
461473
}
462474

463475

464-
void PairQuantity::setPairMaskValue(int i, int j, bool mask)
476+
bool PairQuantity::setPairMaskValue(int i, int j, bool mask)
465477
{
466478
assert(i >= 0 && j >= 0);
467479
pair<int,int> ij = (i > j) ? make_pair(j, i) : make_pair(i, j);
468-
if (mask == mdefaultpairmask) minvertpairmask.erase(ij);
469-
else minvertpairmask.insert(ij);
480+
bool rv;
481+
rv = (mask == mdefaultpairmask) ?
482+
minvertpairmask.erase(ij) :
483+
minvertpairmask.insert(ij).second;
484+
return rv;
470485
}
471486

472487
// Other functions -----------------------------------------------------------

src/diffpy/srreal/PairQuantity.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class PairQuantity : public diffpy::Attributes
120120

121121
// methods
122122
void updateMaskData();
123-
void setPairMaskValue(int i, int j, bool mask);
123+
bool setPairMaskValue(int i, int j, bool mask);
124124

125125
// serialization
126126
friend class boost::serialization::access;

src/tests/TestPairCounter.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ class TestPairCounter : public CxxTest::TestSuite
111111
pcount.setPairMask(0, 0, false);
112112
EventTicker et3 = pcount.ticker();
113113
TS_ASSERT_LESS_THAN(et2, et3);
114-
pcount.setPairMask(0, 5, false);
114+
pcount.setPairMask(0, 0, false);
115115
TS_ASSERT_EQUALS(et3, pcount.ticker());
116+
pcount.setPairMask(0, 5, true);
117+
TS_ASSERT_EQUALS(et3, pcount.ticker());
118+
pcount.setPairMask(0, 5, false);
119+
TS_ASSERT_LESS_THAN(et3, pcount.ticker());
116120
}
117121

118122

0 commit comments

Comments
 (0)