xref: /AOO41X/main/sc/source/core/data/segmenttree.cxx (revision b3f79822e811ac3493b185030a72c3c5a51f32d8)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "segmenttree.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <mdds/flat_segment_tree.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <limits>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using ::std::numeric_limits;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // ============================================================================
36cdf0e10cSrcweir 
37cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType = _ValueType>
38cdf0e10cSrcweir class ScFlatSegmentsImpl
39cdf0e10cSrcweir {
40cdf0e10cSrcweir public:
41cdf0e10cSrcweir     typedef _ValueType ValueType;
42cdf0e10cSrcweir     typedef _ExtValueType ExtValueType;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     struct RangeData
45cdf0e10cSrcweir     {
46cdf0e10cSrcweir         SCCOLROW    mnPos1;
47cdf0e10cSrcweir         SCCOLROW    mnPos2;
48cdf0e10cSrcweir         ValueType   mnValue;
49cdf0e10cSrcweir     };
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     ScFlatSegmentsImpl(SCCOLROW nMax, ValueType nDefault);
52cdf0e10cSrcweir     ScFlatSegmentsImpl(const ScFlatSegmentsImpl& r);
53cdf0e10cSrcweir     ~ScFlatSegmentsImpl();
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     void setValue(SCCOLROW nPos1, SCCOLROW nPos2, ValueType nValue);
56cdf0e10cSrcweir     ValueType getValue(SCCOLROW nPos);
57cdf0e10cSrcweir     ExtValueType getSumValue(SCCOLROW nPos1, SCCOLROW nPos2);
58cdf0e10cSrcweir     bool getRangeData(SCCOLROW nPos, RangeData& rData);
59cdf0e10cSrcweir     void removeSegment(SCCOLROW nPos1, SCCOLROW nPos2);
60cdf0e10cSrcweir     void insertSegment(SCCOLROW nPos, SCCOLROW nSize, bool bSkipStartBoundary);
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     SCROW findLastNotOf(ValueType nValue) const;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     // range iteration
65cdf0e10cSrcweir     bool getFirst(RangeData& rData);
66cdf0e10cSrcweir     bool getNext(RangeData& rData);
67cdf0e10cSrcweir 
enableTreeSearch(bool b)68cdf0e10cSrcweir     void enableTreeSearch(bool b)
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir         mbTreeSearchEnabled = b;
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
setInsertFromBack(bool b)73cdf0e10cSrcweir     void setInsertFromBack(bool b)
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         mbInsertFromBack = b;
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir private:
79cdf0e10cSrcweir     typedef ::mdds::flat_segment_tree<SCCOLROW, ValueType> fst_type;
80cdf0e10cSrcweir     fst_type maSegments;
81cdf0e10cSrcweir     typename fst_type::const_iterator maItr;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     bool mbTreeSearchEnabled:1;
84cdf0e10cSrcweir     bool mbInsertFromBack:1;
85cdf0e10cSrcweir };
86cdf0e10cSrcweir 
87cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
ScFlatSegmentsImpl(SCCOLROW nMax,ValueType nDefault)88cdf0e10cSrcweir ScFlatSegmentsImpl<_ValueType, _ExtValueType>::ScFlatSegmentsImpl(SCCOLROW nMax, ValueType nDefault) :
89cdf0e10cSrcweir     maSegments(0, nMax+1, nDefault),
90cdf0e10cSrcweir     mbTreeSearchEnabled(true),
91cdf0e10cSrcweir     mbInsertFromBack(false)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
ScFlatSegmentsImpl(const ScFlatSegmentsImpl<_ValueType,_ExtValueType> & r)96cdf0e10cSrcweir ScFlatSegmentsImpl<_ValueType, _ExtValueType>::ScFlatSegmentsImpl(const ScFlatSegmentsImpl<_ValueType, _ExtValueType>& r) :
97cdf0e10cSrcweir     maSegments(r.maSegments),
98cdf0e10cSrcweir     mbTreeSearchEnabled(r.mbTreeSearchEnabled),
99cdf0e10cSrcweir     mbInsertFromBack(r.mbInsertFromBack)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
~ScFlatSegmentsImpl()104cdf0e10cSrcweir ScFlatSegmentsImpl<_ValueType, _ExtValueType>::~ScFlatSegmentsImpl()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
setValue(SCCOLROW nPos1,SCCOLROW nPos2,ValueType nValue)109cdf0e10cSrcweir void ScFlatSegmentsImpl<_ValueType, _ExtValueType>::setValue(SCCOLROW nPos1, SCCOLROW nPos2, ValueType nValue)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     if (mbInsertFromBack)
112cdf0e10cSrcweir         maSegments.insert_back(nPos1, nPos2+1, nValue);
113cdf0e10cSrcweir     else
114cdf0e10cSrcweir         maSegments.insert_front(nPos1, nPos2+1, nValue);
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
getValue(SCCOLROW nPos)118cdf0e10cSrcweir typename ScFlatSegmentsImpl<_ValueType, _ExtValueType>::ValueType ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getValue(SCCOLROW nPos)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     ValueType nValue = 0;
121cdf0e10cSrcweir     if (!mbTreeSearchEnabled)
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir         maSegments.search(nPos, nValue);
124cdf0e10cSrcweir         return nValue;
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     if (!maSegments.is_tree_valid())
128cdf0e10cSrcweir         maSegments.build_tree();
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     maSegments.search_tree(nPos, nValue);
131cdf0e10cSrcweir     return nValue;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
135cdf0e10cSrcweir typename ScFlatSegmentsImpl<_ValueType, _ExtValueType>::ExtValueType
getSumValue(SCCOLROW nPos1,SCCOLROW nPos2)136cdf0e10cSrcweir ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getSumValue(SCCOLROW nPos1, SCCOLROW nPos2)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     RangeData aData;
139cdf0e10cSrcweir     if (!getRangeData(nPos1, aData))
140cdf0e10cSrcweir         return 0;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     sal_uInt32 nValue = 0;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     SCROW nCurPos = nPos1;
145cdf0e10cSrcweir     SCROW nEndPos = aData.mnPos2;
146cdf0e10cSrcweir     while (nEndPos <= nPos2)
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         nValue += aData.mnValue * (nEndPos - nCurPos + 1);
149cdf0e10cSrcweir         nCurPos = nEndPos + 1;
150cdf0e10cSrcweir         if (!getRangeData(nCurPos, aData))
151cdf0e10cSrcweir             break;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         nEndPos = aData.mnPos2;
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir     if (nCurPos <= nPos2)
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         nEndPos = ::std::min(nEndPos, nPos2);
158cdf0e10cSrcweir         nValue += aData.mnValue * (nEndPos - nCurPos + 1);
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir     return nValue;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
getRangeData(SCCOLROW nPos,RangeData & rData)164cdf0e10cSrcweir bool ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getRangeData(SCCOLROW nPos, RangeData& rData)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     ValueType nValue;
167cdf0e10cSrcweir     SCCOLROW nPos1, nPos2;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     if (mbTreeSearchEnabled)
170cdf0e10cSrcweir     {
171cdf0e10cSrcweir         if (!maSegments.is_tree_valid())
172cdf0e10cSrcweir             maSegments.build_tree();
173cdf0e10cSrcweir 
174cdf0e10cSrcweir         if (!maSegments.search_tree(nPos, nValue, &nPos1, &nPos2))
175cdf0e10cSrcweir             return false;
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir     else
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         // Conduct leaf-node only search.  Faster when searching between range insertion.
180cdf0e10cSrcweir         if (!maSegments.search(nPos, nValue, &nPos1, &nPos2))
181cdf0e10cSrcweir             return false;
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     rData.mnPos1 = nPos1;
185cdf0e10cSrcweir     rData.mnPos2 = nPos2-1; // end point is not inclusive.
186cdf0e10cSrcweir     rData.mnValue = nValue;
187cdf0e10cSrcweir     return true;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
removeSegment(SCCOLROW nPos1,SCCOLROW nPos2)191cdf0e10cSrcweir void ScFlatSegmentsImpl<_ValueType, _ExtValueType>::removeSegment(SCCOLROW nPos1, SCCOLROW nPos2)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     maSegments.shift_left(nPos1, nPos2);
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
insertSegment(SCCOLROW nPos,SCCOLROW nSize,bool bSkipStartBoundary)197cdf0e10cSrcweir void ScFlatSegmentsImpl<_ValueType, _ExtValueType>::insertSegment(SCCOLROW nPos, SCCOLROW nSize, bool bSkipStartBoundary)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir     maSegments.shift_right(nPos, nSize, bSkipStartBoundary);
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
findLastNotOf(ValueType nValue) const203cdf0e10cSrcweir SCCOLROW ScFlatSegmentsImpl<_ValueType, _ExtValueType>::findLastNotOf(ValueType nValue) const
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     SCCOLROW nPos = numeric_limits<SCCOLROW>::max(); // position not found.
206cdf0e10cSrcweir     typename fst_type::const_reverse_iterator itr = maSegments.rbegin(), itrEnd = maSegments.rend();
207cdf0e10cSrcweir     // Note that when searching in reverse direction, we need to skip the first
208cdf0e10cSrcweir     // node, since the right-most leaf node does not store a valid value.
209cdf0e10cSrcweir     for (++itr; itr != itrEnd; ++itr)
210cdf0e10cSrcweir     {
211cdf0e10cSrcweir         if (itr->second != nValue)
212cdf0e10cSrcweir         {
213cdf0e10cSrcweir             nPos = (--itr)->first - 1;
214cdf0e10cSrcweir             break;
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir     return nPos;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
getFirst(RangeData & rData)221cdf0e10cSrcweir bool ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getFirst(RangeData& rData)
222cdf0e10cSrcweir {
223cdf0e10cSrcweir     maItr = maSegments.begin();
224cdf0e10cSrcweir     return getNext(rData);
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir template<typename _ValueType, typename _ExtValueType>
getNext(RangeData & rData)228cdf0e10cSrcweir bool ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getNext(RangeData& rData)
229cdf0e10cSrcweir {
230cdf0e10cSrcweir     typename fst_type::const_iterator itrEnd = maSegments.end();
231cdf0e10cSrcweir     if (maItr == itrEnd)
232cdf0e10cSrcweir         return false;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     rData.mnPos1 = maItr->first;
235cdf0e10cSrcweir     rData.mnValue = maItr->second;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     ++maItr;
238cdf0e10cSrcweir     if (maItr == itrEnd)
239cdf0e10cSrcweir         return false;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     rData.mnPos2 = maItr->first - 1;
242cdf0e10cSrcweir     return true;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir // ============================================================================
246cdf0e10cSrcweir 
247cdf0e10cSrcweir class ScFlatUInt16SegmentsImpl : public ScFlatSegmentsImpl<sal_uInt16, sal_uInt32>
248cdf0e10cSrcweir {
249cdf0e10cSrcweir public:
ScFlatUInt16SegmentsImpl(SCCOLROW nMax,sal_uInt16 nDefault)250cdf0e10cSrcweir     explicit ScFlatUInt16SegmentsImpl(SCCOLROW nMax, sal_uInt16 nDefault) :
251cdf0e10cSrcweir         ScFlatSegmentsImpl<sal_uInt16, sal_uInt32>(nMax, nDefault)
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir };
255cdf0e10cSrcweir 
256cdf0e10cSrcweir // ----------------------------------------------------------------------------
257cdf0e10cSrcweir 
258cdf0e10cSrcweir class ScFlatBoolSegmentsImpl : public ScFlatSegmentsImpl<bool>
259cdf0e10cSrcweir {
260cdf0e10cSrcweir public:
ScFlatBoolSegmentsImpl(SCCOLROW nMax)261cdf0e10cSrcweir     explicit ScFlatBoolSegmentsImpl(SCCOLROW nMax) :
262cdf0e10cSrcweir         ScFlatSegmentsImpl<bool>(nMax, false)
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     void setTrue(SCCOLROW nPos1, SCCOLROW nPos2);
267cdf0e10cSrcweir     void setFalse(SCCOLROW nPos1, SCCOLROW nPos2);
268cdf0e10cSrcweir };
269cdf0e10cSrcweir 
setTrue(SCCOLROW nPos1,SCCOLROW nPos2)270cdf0e10cSrcweir void ScFlatBoolSegmentsImpl::setTrue(SCCOLROW nPos1, SCCOLROW nPos2)
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     setValue(nPos1, nPos2, true);
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
setFalse(SCCOLROW nPos1,SCCOLROW nPos2)275cdf0e10cSrcweir void ScFlatBoolSegmentsImpl::setFalse(SCCOLROW nPos1, SCCOLROW nPos2)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir     setValue(nPos1, nPos2, false);
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir // ============================================================================
281cdf0e10cSrcweir 
ForwardIterator(ScFlatBoolRowSegments & rSegs)282cdf0e10cSrcweir ScFlatBoolRowSegments::ForwardIterator::ForwardIterator(ScFlatBoolRowSegments& rSegs) :
283cdf0e10cSrcweir     mrSegs(rSegs), mnCurPos(0), mnLastPos(-1), mbCurValue(false)
284cdf0e10cSrcweir {
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
getValue(SCROW nPos,bool & rVal)287cdf0e10cSrcweir bool ScFlatBoolRowSegments::ForwardIterator::getValue(SCROW nPos, bool& rVal)
288cdf0e10cSrcweir {
289cdf0e10cSrcweir     if (nPos >= mnCurPos)
290cdf0e10cSrcweir         // It can only go in a forward direction.
291cdf0e10cSrcweir         mnCurPos = nPos;
292cdf0e10cSrcweir 
293cdf0e10cSrcweir     if (mnCurPos > mnLastPos)
294cdf0e10cSrcweir     {
295cdf0e10cSrcweir         // position not in the current segment.  Update the current value.
296cdf0e10cSrcweir         ScFlatBoolRowSegments::RangeData aData;
297cdf0e10cSrcweir         if (!mrSegs.getRangeData(mnCurPos, aData))
298cdf0e10cSrcweir             return false;
299cdf0e10cSrcweir 
300cdf0e10cSrcweir         mbCurValue = aData.mbValue;
301cdf0e10cSrcweir         mnLastPos = aData.mnRow2;
302cdf0e10cSrcweir     }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir     rVal = mbCurValue;
305cdf0e10cSrcweir     return true;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir 
getLastPos() const308cdf0e10cSrcweir SCROW ScFlatBoolRowSegments::ForwardIterator::getLastPos() const
309cdf0e10cSrcweir {
310cdf0e10cSrcweir     return mnLastPos;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir // ----------------------------------------------------------------------------
314cdf0e10cSrcweir 
RangeIterator(ScFlatBoolRowSegments & rSegs)315cdf0e10cSrcweir ScFlatBoolRowSegments::RangeIterator::RangeIterator(ScFlatBoolRowSegments& rSegs) :
316cdf0e10cSrcweir     mrSegs(rSegs)
317cdf0e10cSrcweir {
318cdf0e10cSrcweir }
319cdf0e10cSrcweir 
getFirst(RangeData & rRange)320cdf0e10cSrcweir bool ScFlatBoolRowSegments::RangeIterator::getFirst(RangeData& rRange)
321cdf0e10cSrcweir {
322cdf0e10cSrcweir     ScFlatBoolSegmentsImpl::RangeData aData;
323cdf0e10cSrcweir     if (!mrSegs.mpImpl->getFirst(aData))
324cdf0e10cSrcweir         return false;
325cdf0e10cSrcweir 
326cdf0e10cSrcweir     rRange.mnRow1  = static_cast<SCROW>(aData.mnPos1);
327cdf0e10cSrcweir     rRange.mnRow2  = static_cast<SCROW>(aData.mnPos2);
328cdf0e10cSrcweir     rRange.mbValue = static_cast<bool>(aData.mnValue);
329cdf0e10cSrcweir     return true;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
getNext(RangeData & rRange)332cdf0e10cSrcweir bool ScFlatBoolRowSegments::RangeIterator::getNext(RangeData& rRange)
333cdf0e10cSrcweir {
334cdf0e10cSrcweir     ScFlatBoolSegmentsImpl::RangeData aData;
335cdf0e10cSrcweir     if (!mrSegs.mpImpl->getNext(aData))
336cdf0e10cSrcweir         return false;
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     rRange.mnRow1  = static_cast<SCROW>(aData.mnPos1);
339cdf0e10cSrcweir     rRange.mnRow2  = static_cast<SCROW>(aData.mnPos2);
340cdf0e10cSrcweir     rRange.mbValue = static_cast<bool>(aData.mnValue);
341cdf0e10cSrcweir     return true;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir // ----------------------------------------------------------------------------
345cdf0e10cSrcweir 
ScFlatBoolRowSegments()346cdf0e10cSrcweir ScFlatBoolRowSegments::ScFlatBoolRowSegments() :
347cdf0e10cSrcweir     mpImpl(new ScFlatBoolSegmentsImpl(static_cast<SCCOLROW>(MAXROW)))
348cdf0e10cSrcweir {
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
ScFlatBoolRowSegments(const ScFlatBoolRowSegments & r)351cdf0e10cSrcweir ScFlatBoolRowSegments::ScFlatBoolRowSegments(const ScFlatBoolRowSegments& r) :
352cdf0e10cSrcweir     mpImpl(new ScFlatBoolSegmentsImpl(*r.mpImpl))
353cdf0e10cSrcweir {
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
~ScFlatBoolRowSegments()356cdf0e10cSrcweir ScFlatBoolRowSegments::~ScFlatBoolRowSegments()
357cdf0e10cSrcweir {
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
setTrue(SCROW nRow1,SCROW nRow2)360cdf0e10cSrcweir void ScFlatBoolRowSegments::setTrue(SCROW nRow1, SCROW nRow2)
361cdf0e10cSrcweir {
362cdf0e10cSrcweir     mpImpl->setTrue(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2));
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
setFalse(SCROW nRow1,SCROW nRow2)365cdf0e10cSrcweir void ScFlatBoolRowSegments::setFalse(SCROW nRow1, SCROW nRow2)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     mpImpl->setFalse(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2));
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
getValue(SCROW nRow)370cdf0e10cSrcweir bool ScFlatBoolRowSegments::getValue(SCROW nRow)
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     return mpImpl->getValue(static_cast<SCCOLROW>(nRow));
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
getRangeData(SCROW nRow,RangeData & rData)375cdf0e10cSrcweir bool ScFlatBoolRowSegments::getRangeData(SCROW nRow, RangeData& rData)
376cdf0e10cSrcweir {
377cdf0e10cSrcweir     ScFlatBoolSegmentsImpl::RangeData aData;
378cdf0e10cSrcweir     if (!mpImpl->getRangeData(static_cast<SCCOLROW>(nRow), aData))
379cdf0e10cSrcweir         return false;
380cdf0e10cSrcweir 
381cdf0e10cSrcweir     rData.mbValue = aData.mnValue;
382cdf0e10cSrcweir     rData.mnRow1  = static_cast<SCROW>(aData.mnPos1);
383cdf0e10cSrcweir     rData.mnRow2  = static_cast<SCROW>(aData.mnPos2);
384cdf0e10cSrcweir     return true;
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
removeSegment(SCROW nRow1,SCROW nRow2)387cdf0e10cSrcweir void ScFlatBoolRowSegments::removeSegment(SCROW nRow1, SCROW nRow2)
388cdf0e10cSrcweir {
389cdf0e10cSrcweir     mpImpl->removeSegment(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2));
390cdf0e10cSrcweir }
391cdf0e10cSrcweir 
insertSegment(SCROW nRow,SCROW nSize,bool bSkipStartBoundary)392cdf0e10cSrcweir void ScFlatBoolRowSegments::insertSegment(SCROW nRow, SCROW nSize, bool bSkipStartBoundary)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir     mpImpl->insertSegment(static_cast<SCCOLROW>(nRow), static_cast<SCCOLROW>(nSize), bSkipStartBoundary);
395cdf0e10cSrcweir }
396cdf0e10cSrcweir 
findLastNotOf(bool bValue) const397cdf0e10cSrcweir SCROW ScFlatBoolRowSegments::findLastNotOf(bool bValue) const
398cdf0e10cSrcweir {
399cdf0e10cSrcweir     return static_cast<SCROW>(mpImpl->findLastNotOf(bValue));
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
enableTreeSearch(bool bEnable)402cdf0e10cSrcweir void ScFlatBoolRowSegments::enableTreeSearch(bool bEnable)
403cdf0e10cSrcweir {
404cdf0e10cSrcweir     mpImpl->enableTreeSearch(bEnable);
405cdf0e10cSrcweir }
406cdf0e10cSrcweir 
setInsertFromBack(bool bInsertFromBack)407cdf0e10cSrcweir void ScFlatBoolRowSegments::setInsertFromBack(bool bInsertFromBack)
408cdf0e10cSrcweir {
409cdf0e10cSrcweir     mpImpl->setInsertFromBack(bInsertFromBack);
410cdf0e10cSrcweir }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir // ============================================================================
413cdf0e10cSrcweir 
ScFlatBoolColSegments()414cdf0e10cSrcweir ScFlatBoolColSegments::ScFlatBoolColSegments() :
415cdf0e10cSrcweir     mpImpl(new ScFlatBoolSegmentsImpl(static_cast<SCCOLROW>(MAXCOL)))
416cdf0e10cSrcweir {
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
ScFlatBoolColSegments(const ScFlatBoolColSegments & r)419cdf0e10cSrcweir ScFlatBoolColSegments::ScFlatBoolColSegments(const ScFlatBoolColSegments& r) :
420cdf0e10cSrcweir     mpImpl(new ScFlatBoolSegmentsImpl(*r.mpImpl))
421cdf0e10cSrcweir {
422cdf0e10cSrcweir }
423cdf0e10cSrcweir 
~ScFlatBoolColSegments()424cdf0e10cSrcweir ScFlatBoolColSegments::~ScFlatBoolColSegments()
425cdf0e10cSrcweir {
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
setTrue(SCCOL nCol1,SCCOL nCol2)428cdf0e10cSrcweir void ScFlatBoolColSegments::setTrue(SCCOL nCol1, SCCOL nCol2)
429cdf0e10cSrcweir {
430cdf0e10cSrcweir     mpImpl->setTrue(static_cast<SCCOLROW>(nCol1), static_cast<SCCOLROW>(nCol2));
431cdf0e10cSrcweir }
432cdf0e10cSrcweir 
setFalse(SCCOL nCol1,SCCOL nCol2)433cdf0e10cSrcweir void ScFlatBoolColSegments::setFalse(SCCOL nCol1, SCCOL nCol2)
434cdf0e10cSrcweir {
435cdf0e10cSrcweir     mpImpl->setFalse(static_cast<SCCOLROW>(nCol1), static_cast<SCCOLROW>(nCol2));
436cdf0e10cSrcweir }
437cdf0e10cSrcweir 
getValue(SCCOL nCol)438cdf0e10cSrcweir bool ScFlatBoolColSegments::getValue(SCCOL nCol)
439cdf0e10cSrcweir {
440cdf0e10cSrcweir     return mpImpl->getValue(static_cast<SCCOLROW>(nCol));
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
getRangeData(SCCOL nCol,RangeData & rData)443cdf0e10cSrcweir bool ScFlatBoolColSegments::getRangeData(SCCOL nCol, RangeData& rData)
444cdf0e10cSrcweir {
445cdf0e10cSrcweir     ScFlatBoolSegmentsImpl::RangeData aData;
446cdf0e10cSrcweir     if (!mpImpl->getRangeData(static_cast<SCCOLROW>(nCol), aData))
447cdf0e10cSrcweir         return false;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir     rData.mbValue = aData.mnValue;
450cdf0e10cSrcweir     rData.mnCol1  = static_cast<SCCOL>(aData.mnPos1);
451cdf0e10cSrcweir     rData.mnCol2  = static_cast<SCCOL>(aData.mnPos2);
452cdf0e10cSrcweir     return true;
453cdf0e10cSrcweir }
454cdf0e10cSrcweir 
removeSegment(SCCOL nCol1,SCCOL nCol2)455cdf0e10cSrcweir void ScFlatBoolColSegments::removeSegment(SCCOL nCol1, SCCOL nCol2)
456cdf0e10cSrcweir {
457cdf0e10cSrcweir     mpImpl->removeSegment(static_cast<SCCOLROW>(nCol1), static_cast<SCCOLROW>(nCol2));
458cdf0e10cSrcweir }
459cdf0e10cSrcweir 
insertSegment(SCCOL nCol,SCCOL nSize,bool bSkipStartBoundary)460cdf0e10cSrcweir void ScFlatBoolColSegments::insertSegment(SCCOL nCol, SCCOL nSize, bool bSkipStartBoundary)
461cdf0e10cSrcweir {
462cdf0e10cSrcweir     mpImpl->insertSegment(static_cast<SCCOLROW>(nCol), static_cast<SCCOLROW>(nSize), bSkipStartBoundary);
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
enableTreeSearch(bool bEnable)465cdf0e10cSrcweir void ScFlatBoolColSegments::enableTreeSearch(bool bEnable)
466cdf0e10cSrcweir {
467cdf0e10cSrcweir     mpImpl->enableTreeSearch(bEnable);
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
setInsertFromBack(bool bInsertFromBack)470cdf0e10cSrcweir void ScFlatBoolColSegments::setInsertFromBack(bool bInsertFromBack)
471cdf0e10cSrcweir {
472cdf0e10cSrcweir     mpImpl->setInsertFromBack(bInsertFromBack);
473cdf0e10cSrcweir }
474cdf0e10cSrcweir 
475cdf0e10cSrcweir // ============================================================================
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 
478cdf0e10cSrcweir // ============================================================================
479cdf0e10cSrcweir 
ForwardIterator(ScFlatUInt16RowSegments & rSegs)480cdf0e10cSrcweir ScFlatUInt16RowSegments::ForwardIterator::ForwardIterator(ScFlatUInt16RowSegments& rSegs) :
481cdf0e10cSrcweir     mrSegs(rSegs), mnCurPos(0), mnLastPos(-1), mnCurValue(0)
482cdf0e10cSrcweir {
483cdf0e10cSrcweir }
484cdf0e10cSrcweir 
getValue(SCROW nPos,sal_uInt16 & rVal)485cdf0e10cSrcweir bool ScFlatUInt16RowSegments::ForwardIterator::getValue(SCROW nPos, sal_uInt16& rVal)
486cdf0e10cSrcweir {
487cdf0e10cSrcweir     if (nPos >= mnCurPos)
488cdf0e10cSrcweir         // It can only go in a forward direction.
489cdf0e10cSrcweir         mnCurPos = nPos;
490cdf0e10cSrcweir 
491cdf0e10cSrcweir     if (mnCurPos > mnLastPos)
492cdf0e10cSrcweir     {
493cdf0e10cSrcweir         // position not in the current segment.  Update the current value.
494cdf0e10cSrcweir         ScFlatUInt16RowSegments::RangeData aData;
495cdf0e10cSrcweir         if (!mrSegs.getRangeData(mnCurPos, aData))
496cdf0e10cSrcweir             return false;
497cdf0e10cSrcweir 
498cdf0e10cSrcweir         mnCurValue = aData.mnValue;
499cdf0e10cSrcweir         mnLastPos = aData.mnRow2;
500cdf0e10cSrcweir     }
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     rVal = mnCurValue;
503cdf0e10cSrcweir     return true;
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
getLastPos() const506cdf0e10cSrcweir SCROW ScFlatUInt16RowSegments::ForwardIterator::getLastPos() const
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     return mnLastPos;
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir // ----------------------------------------------------------------------------
512cdf0e10cSrcweir 
ScFlatUInt16RowSegments(sal_uInt16 nDefault)513cdf0e10cSrcweir ScFlatUInt16RowSegments::ScFlatUInt16RowSegments(sal_uInt16 nDefault) :
514cdf0e10cSrcweir     mpImpl(new ScFlatUInt16SegmentsImpl(static_cast<SCCOLROW>(MAXROW), nDefault))
515cdf0e10cSrcweir {
516cdf0e10cSrcweir }
517cdf0e10cSrcweir 
ScFlatUInt16RowSegments(const ScFlatUInt16RowSegments & r)518cdf0e10cSrcweir ScFlatUInt16RowSegments::ScFlatUInt16RowSegments(const ScFlatUInt16RowSegments& r) :
519cdf0e10cSrcweir     mpImpl(new ScFlatUInt16SegmentsImpl(*r.mpImpl))
520cdf0e10cSrcweir {
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
~ScFlatUInt16RowSegments()523cdf0e10cSrcweir ScFlatUInt16RowSegments::~ScFlatUInt16RowSegments()
524cdf0e10cSrcweir {
525cdf0e10cSrcweir }
526cdf0e10cSrcweir 
setValue(SCROW nRow1,SCROW nRow2,sal_uInt16 nValue)527cdf0e10cSrcweir void ScFlatUInt16RowSegments::setValue(SCROW nRow1, SCROW nRow2, sal_uInt16 nValue)
528cdf0e10cSrcweir {
529cdf0e10cSrcweir     mpImpl->setValue(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2), nValue);
530cdf0e10cSrcweir }
531cdf0e10cSrcweir 
getValue(SCROW nRow)532cdf0e10cSrcweir sal_uInt16 ScFlatUInt16RowSegments::getValue(SCROW nRow)
533cdf0e10cSrcweir {
534cdf0e10cSrcweir     return mpImpl->getValue(static_cast<SCCOLROW>(nRow));
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
getSumValue(SCROW nRow1,SCROW nRow2)537cdf0e10cSrcweir sal_uInt32 ScFlatUInt16RowSegments::getSumValue(SCROW nRow1, SCROW nRow2)
538cdf0e10cSrcweir {
539cdf0e10cSrcweir     return mpImpl->getSumValue(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2));
540cdf0e10cSrcweir }
541cdf0e10cSrcweir 
getRangeData(SCROW nRow,RangeData & rData)542cdf0e10cSrcweir bool ScFlatUInt16RowSegments::getRangeData(SCROW nRow, RangeData& rData)
543cdf0e10cSrcweir {
544cdf0e10cSrcweir     ScFlatUInt16SegmentsImpl::RangeData aData;
545cdf0e10cSrcweir     if (!mpImpl->getRangeData(static_cast<SCCOLROW>(nRow), aData))
546cdf0e10cSrcweir         return false;
547cdf0e10cSrcweir 
548cdf0e10cSrcweir     rData.mnRow1  = aData.mnPos1;
549cdf0e10cSrcweir     rData.mnRow2  = aData.mnPos2;
550cdf0e10cSrcweir     rData.mnValue = aData.mnValue;
551cdf0e10cSrcweir     return true;
552cdf0e10cSrcweir }
553cdf0e10cSrcweir 
removeSegment(SCROW nRow1,SCROW nRow2)554cdf0e10cSrcweir void ScFlatUInt16RowSegments::removeSegment(SCROW nRow1, SCROW nRow2)
555cdf0e10cSrcweir {
556cdf0e10cSrcweir     mpImpl->removeSegment(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2));
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
insertSegment(SCROW nRow,SCROW nSize,bool bSkipStartBoundary)559cdf0e10cSrcweir void ScFlatUInt16RowSegments::insertSegment(SCROW nRow, SCROW nSize, bool bSkipStartBoundary)
560cdf0e10cSrcweir {
561cdf0e10cSrcweir     mpImpl->insertSegment(static_cast<SCCOLROW>(nRow), static_cast<SCCOLROW>(nSize), bSkipStartBoundary);
562cdf0e10cSrcweir }
563cdf0e10cSrcweir 
findLastNotOf(sal_uInt16 nValue) const564cdf0e10cSrcweir SCROW ScFlatUInt16RowSegments::findLastNotOf(sal_uInt16 nValue) const
565cdf0e10cSrcweir {
566cdf0e10cSrcweir     return static_cast<SCROW>(mpImpl->findLastNotOf(nValue));
567cdf0e10cSrcweir }
568cdf0e10cSrcweir 
enableTreeSearch(bool bEnable)569cdf0e10cSrcweir void ScFlatUInt16RowSegments::enableTreeSearch(bool bEnable)
570cdf0e10cSrcweir {
571cdf0e10cSrcweir     mpImpl->enableTreeSearch(bEnable);
572cdf0e10cSrcweir }
573cdf0e10cSrcweir 
setInsertFromBack(bool bInsertFromBack)574cdf0e10cSrcweir void ScFlatUInt16RowSegments::setInsertFromBack(bool bInsertFromBack)
575cdf0e10cSrcweir {
576cdf0e10cSrcweir     mpImpl->setInsertFromBack(bInsertFromBack);
577cdf0e10cSrcweir }
578cdf0e10cSrcweir 
579