unsigned RangeMap<From, To>::inverseMap(To to, From &from, ISet<WideChar> &fromSet, WideChar &count) const { // FIXME use binary search unsigned ret = 0; count = wideCharMax; for (size_t i = 0; i < ranges_.size(); i++) { const RangeMapRange<From,To> &r = ranges_[i]; if (r.toMin <= to && to <= r.toMin + (r.fromMax - r.fromMin)) { From n = r.fromMin + (to - r.toMin); WideChar thisCount = r.fromMax - n + 1; if (ret > 1) { fromSet.add(n); if (thisCount < count) count = thisCount; } else if (ret == 1) { fromSet.add(from); fromSet.add(n); ret = 2; if (thisCount < count) count = thisCount; } else { count = thisCount; from = n; ret = 1; } } else if (ret == 0 && r.toMin > to && (r.toMin - to < count)) count = r.toMin - to; } return ret; }
void ClientTxnSetTest::testAddRemove() { ISet<std::string> s = client->getSet<std::string>("testAddRemove"); s.add("item1"); TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalSet<std::string> set = context.getSet<std::string>("testAddRemove"); assertTrue(set.add("item2")); assertEqual(2, set.size()); assertEqual(1, s.size()); assertFalse(set.remove("item3")); assertTrue(set.remove("item1")); context.commitTransaction(); assertEqual(1, s.size()); }