50 ResultIteratorBase::ResultIteratorBase()
51 : mapIterator(
QMap<int, ResultItem>::const_iterator()), m_vectorIndex(0) { }
53 : mapIterator(_mapIterator), m_vectorIndex(_vectorIndex) { }
55 int ResultIteratorBase::vectorIndex()
const {
return m_vectorIndex; }
56 int ResultIteratorBase::resultIndex()
const {
return mapIterator.key() + m_vectorIndex; }
58 ResultIteratorBase ResultIteratorBase::operator++()
60 if (canIncrementVectorIndex()) {
69 int ResultIteratorBase::batchSize()
const 71 return mapIterator.value().count();
74 void ResultIteratorBase::batchedAdvance()
82 return (mapIterator == other.mapIterator && m_vectorIndex == other.m_vectorIndex);
90 bool ResultIteratorBase::isVector()
const 92 return mapIterator.value().isVector();
95 bool ResultIteratorBase::canIncrementVectorIndex()
const 97 return (m_vectorIndex + 1 < mapIterator.value().m_count);
100 ResultStoreBase::ResultStoreBase()
101 : insertIndex(0), resultCount(0), m_filterMode(false), filteredResults(0) { }
103 void ResultStoreBase::setFilterMode(
bool enable)
105 m_filterMode = enable;
108 bool ResultStoreBase::filterMode()
const 113 void ResultStoreBase::syncResultCount()
115 ResultIteratorBase
it = resultAt(resultCount);
116 while (it !=
end()) {
117 resultCount += it.batchSize();
118 it = resultAt(resultCount);
122 void ResultStoreBase::insertResultItemIfValid(
int index, ResultItem &resultItem)
124 if (resultItem.isValid()) {
125 m_results[
index] = resultItem;
128 filteredResults += resultItem.count();
132 int ResultStoreBase::insertResultItem(
int index, ResultItem &resultItem)
135 if (m_filterMode && index != -1 && index > insertIndex) {
136 pendingResults[
index] = resultItem;
139 storeIndex = updateInsertIndex(index, resultItem.count());
140 insertResultItemIfValid(storeIndex - filteredResults, resultItem);
142 syncPendingResults();
146 void ResultStoreBase::syncPendingResults()
150 while (it != pendingResults.end()) {
151 int index = it.
key();
152 if (index != resultCount + filteredResults)
155 ResultItem result = it.
value();
156 insertResultItemIfValid(index - filteredResults, result);
157 pendingResults.erase(it);
158 it = pendingResults.begin();
162 int ResultStoreBase::addResult(
int index,
const void *result)
164 ResultItem resultItem(result, 0);
165 return insertResultItem(index, resultItem);
168 int ResultStoreBase::addResults(
int index,
const void *results,
int vectorSize,
int totalCount)
170 if (m_filterMode ==
false || vectorSize == totalCount) {
171 ResultItem resultItem(results, vectorSize);
172 return insertResultItem(index, resultItem);
174 if (vectorSize > 0) {
175 ResultItem filteredIn(results, vectorSize);
176 insertResultItem(index, filteredIn);
178 ResultItem filteredAway(0, totalCount - vectorSize);
179 return insertResultItem(index + vectorSize, filteredAway);
183 ResultIteratorBase ResultStoreBase::begin()
const 185 return ResultIteratorBase(m_results.begin());
190 return ResultIteratorBase(m_results.end());
193 bool ResultStoreBase::hasNextResult()
const 195 return begin() !=
end();
198 ResultIteratorBase ResultStoreBase::resultAt(
int index)
const 200 if (m_results.isEmpty())
201 return ResultIteratorBase(m_results.end());
207 if (it == m_results.end()) {
209 if (it.
value().isVector() ==
false) {
210 return ResultIteratorBase(m_results.end());
214 if (it == m_results.begin())
215 return ResultIteratorBase(m_results.end());
220 const int vectorIndex = index - it.
key();
222 if (vectorIndex >= it.
value().count())
223 return ResultIteratorBase(m_results.end());
224 else if (it.
value().isVector() ==
false && vectorIndex != 0)
225 return ResultIteratorBase(m_results.end());
226 return ResultIteratorBase(it, vectorIndex);
229 bool ResultStoreBase::contains(
int index)
const 231 return (resultAt(index) !=
end());
234 int ResultStoreBase::count()
const 241 int ResultStoreBase::updateInsertIndex(
int index,
int _count)
245 insertIndex += _count;
247 insertIndex =
qMax(index + _count, insertIndex);
256 #endif // QT_NO_CONCURRENT const Key & key() const
Returns the current item's key as a const reference.
#define QT_END_NAMESPACE
This macro expands to.
#define it(className, varName)
const Key & key() const
Returns the current item's key.
bool operator!=(QBool b1, bool b2)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
T & value() const
Returns a modifiable reference to the current item's value.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded pro...
const T & value() const
Returns the current item's value.
static const KeyPair *const end
bool operator==(QBool b1, bool b2)
The QMap class is a template class that provides a skip-list-based dictionary.