/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
template<typename ValueType_, typename ExtValueType_> void ScFlatSegmentsImpl<ValueType_, ExtValueType_>::setValueIf(SCCOLROW nPos1, SCCOLROW nPos2,
ValueType nValue, const std::function<bool(ValueType)>& rPredicate)
{
SCCOLROW nCurrentStartRow = nPos1; while (nCurrentStartRow <= nPos2)
{
RangeData aRangeData;
getRangeData(nCurrentStartRow, aRangeData); if (rPredicate(aRangeData.mnValue))
{ // set value from current iteration point on, til end of range. // Note that aRangeData may well contain much lower values for nPos1
setValue(nCurrentStartRow, std::min<SCCOLROW>(nPos2, aRangeData.mnPos2), nValue);
}
// even if nPos2 is bigger than nPos2 this should terminate the loop
nCurrentStartRow = aRangeData.mnPos2 + 1;
}
}
if (!maSegments.valid_tree())
{
assert(!ScGlobal::bThreadedGroupCalcInProgress);
maSegments.build_tree();
}
RangeData aData; auto [it, found] = maSegments.search_tree(nPos1, aData.mnValue, &aData.mnPos1, &aData.mnPos2); if (!found) return 0;
aData.mnPos2 = aData.mnPos2-1; // end point is not inclusive.
sal_uInt64 nValue = 0;
SCROW nCurPos = nPos1;
SCROW nEndPos = aData.mnPos2; while (nEndPos <= nPos2)
{
sal_uInt64 nRes; if (o3tl::checked_multiply<sal_uInt64>(aData.mnValue, nEndPos - nCurPos + 1, nRes))
{
SAL_WARN("sc.core", "row height overflow");
nRes = SAL_MAX_INT64;
}
nValue = o3tl::saturating_add(nValue, nRes);
nCurPos = nEndPos + 1; auto itPair = maSegments.search(it, nCurPos, aData.mnValue, &aData.mnPos1, &aData.mnPos2); if (!itPair.second) break;
it = itPair.first;
aData.mnPos2 = aData.mnPos2-1; // end point is not inclusive.
nEndPos = aData.mnPos2;
} if (nCurPos <= nPos2)
{
nEndPos = ::std::min(nEndPos, nPos2);
sal_uInt64 nRes; if (o3tl::checked_multiply<sal_uInt64>(aData.mnValue, nEndPos - nCurPos + 1, nRes))
{
SAL_WARN("sc.core", "row height overflow");
nRes = SAL_MAX_INT64;
}
nValue = o3tl::saturating_add(nValue, nRes);
} return nValue;
} else
{
RangeData aData; if (!getRangeDataLeaf(nPos1, aData)) return 0;
if (!maSegments.valid_tree())
{
assert(!ScGlobal::bThreadedGroupCalcInProgress);
maSegments.build_tree();
}
auto [it,found] = maSegments.search_tree(nPos, rData.mnValue, &rData.mnPos1, &rData.mnPos2); if (!found) returnfalse;
maItr = std::move(it); // cache the iterator to speed up ForwardIterator.
rData.mnPos2 = rData.mnPos2-1; // end point is not inclusive. returntrue;
}
template<typename ValueType_, typename ExtValueType_> bool ScFlatSegmentsImpl<ValueType_, ExtValueType_>::getRangeDataLeaf(SCCOLROW nPos, RangeData& rData)
{ // Conduct leaf-node only search. Faster when searching between range insertion. const ::std::pair<typename fst_type::const_iterator, bool> &ret =
maSegments.search(maItr, nPos, rData.mnValue, &rData.mnPos1, &rData.mnPos2);
if (!ret.second) returnfalse;
maItr = ret.first;
rData.mnPos2 = rData.mnPos2-1; // end point is not inclusive. returntrue;
}
template<typename ValueType_, typename ExtValueType_>
SCCOLROW ScFlatSegmentsImpl<ValueType_, ExtValueType_>::findLastTrue(ValueType nValue) const
{
SCCOLROW nPos = numeric_limits<SCCOLROW>::max(); // position not found. typename fst_type::const_reverse_iterator itr = maSegments.rbegin(), itrEnd = maSegments.rend(); // Note that when searching in reverse direction, we need to skip the first // node, since the right-most leaf node does not store a valid value. for (++itr; itr != itrEnd; ++itr)
{ if (itr->second != nValue)
{
nPos = (--itr)->first - 1; break;
}
} return nPos;
}
bool ScFlatBoolRowSegments::ForwardIterator::getValue(SCROW nPos, bool& rVal)
{ if (nPos >= mnCurPos) // It can only go in a forward direction.
mnCurPos = nPos;
if (mnCurPos > mnLastPos)
{ // position not in the current segment. Update the current value.
ScFlatBoolRowSegments::RangeData aData; if (!mrSegs.getRangeData(mnCurPos, aData)) returnfalse;
bool ScFlatUInt16RowSegments::ForwardIterator::getValue(SCROW nPos, sal_uInt16& rVal)
{ if (nPos >= mnCurPos) // It can only go in a forward direction.
mnCurPos = nPos;
if (mnCurPos > mnLastPos)
{ // position not in the current segment. Update the current value.
ScFlatUInt16SegmentsImpl::RangeData aData; if (mnLastPos == -1)
{ // first time in this method, use the tree search based method if (!mrSegs.mpImpl->getRangeData(mnCurPos, aData)) returnfalse;
} else
{ // but on subsequent calls, use the leaf method, which is faster // because we have a cached iterator. if (!mrSegs.mpImpl->getRangeDataLeaf(mnCurPos, aData)) returnfalse;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.