Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "segmenttree.hxx"
31 : :
32 : : #include <mdds/flat_segment_tree.hpp>
33 : :
34 : : #include <limits>
35 : :
36 : : using ::std::numeric_limits;
37 : :
38 : : // ============================================================================
39 : :
40 : : template<typename _ValueType, typename _ExtValueType = _ValueType>
41 : : class ScFlatSegmentsImpl
42 : : {
43 : : public:
44 : : typedef _ValueType ValueType;
45 : : typedef _ExtValueType ExtValueType;
46 : :
47 : : struct RangeData
48 : : {
49 : : SCCOLROW mnPos1;
50 : : SCCOLROW mnPos2;
51 : : ValueType mnValue;
52 : : };
53 : :
54 : : ScFlatSegmentsImpl(SCCOLROW nMax, ValueType nDefault);
55 : : ScFlatSegmentsImpl(const ScFlatSegmentsImpl& r);
56 : : ~ScFlatSegmentsImpl();
57 : :
58 : : bool setValue(SCCOLROW nPos1, SCCOLROW nPos2, ValueType nValue);
59 : : ValueType getValue(SCCOLROW nPos);
60 : : ExtValueType getSumValue(SCCOLROW nPos1, SCCOLROW nPos2);
61 : : bool getRangeData(SCCOLROW nPos, RangeData& rData);
62 : : bool getRangeDataLeaf(SCCOLROW nPos, RangeData& rData);
63 : : void removeSegment(SCCOLROW nPos1, SCCOLROW nPos2);
64 : : void insertSegment(SCCOLROW nPos, SCCOLROW nSize, bool bSkipStartBoundary);
65 : :
66 : : SCROW findLastNotOf(ValueType nValue) const;
67 : :
68 : : // range iteration
69 : : bool getFirst(RangeData& rData);
70 : : bool getNext(RangeData& rData);
71 : :
72 : 2418 : void enableTreeSearch(bool b)
73 : : {
74 : 2418 : mbTreeSearchEnabled = b;
75 : 2418 : }
76 : :
77 : : private:
78 : : typedef ::mdds::flat_segment_tree<SCCOLROW, ValueType> fst_type;
79 : : fst_type maSegments;
80 : : typename fst_type::const_iterator maItr;
81 : :
82 : : bool mbTreeSearchEnabled:1;
83 : : };
84 : :
85 : : template<typename _ValueType, typename _ExtValueType>
86 : 19145 : ScFlatSegmentsImpl<_ValueType, _ExtValueType>::ScFlatSegmentsImpl(SCCOLROW nMax, ValueType nDefault) :
87 : : maSegments(0, nMax+1, nDefault),
88 [ + - ][ + - ]: 19145 : mbTreeSearchEnabled(true)
89 : : {
90 : 19145 : }
91 : :
92 : : template<typename _ValueType, typename _ExtValueType>
93 : 0 : ScFlatSegmentsImpl<_ValueType, _ExtValueType>::ScFlatSegmentsImpl(const ScFlatSegmentsImpl<_ValueType, _ExtValueType>& r) :
94 : : maSegments(r.maSegments),
95 [ # # ][ # # ]: 0 : mbTreeSearchEnabled(r.mbTreeSearchEnabled)
96 : : {
97 : 0 : }
98 : :
99 : : template<typename _ValueType, typename _ExtValueType>
100 : 17639 : ScFlatSegmentsImpl<_ValueType, _ExtValueType>::~ScFlatSegmentsImpl()
101 : : {
102 : 17639 : }
103 : :
104 : : template<typename _ValueType, typename _ExtValueType>
105 : 5419443 : bool ScFlatSegmentsImpl<_ValueType, _ExtValueType>::setValue(SCCOLROW nPos1, SCCOLROW nPos2, ValueType nValue)
106 : : {
107 [ + - ][ + - ]: 5419443 : ::std::pair<typename fst_type::const_iterator, bool> ret;
108 [ + - ][ + - ]: 5419443 : ret = maSegments.insert(maItr, nPos1, nPos2+1, nValue);
[ + - ][ + - ]
109 [ + - ][ + - ]: 5419443 : maItr = ret.first;
110 : 5419443 : return ret.second;
111 : : }
112 : :
113 : : template<typename _ValueType, typename _ExtValueType>
114 : 14725919 : typename ScFlatSegmentsImpl<_ValueType, _ExtValueType>::ValueType ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getValue(SCCOLROW nPos)
115 : : {
116 : 14725919 : ValueType nValue = 0;
117 [ + + ][ - + ]: 14725919 : if (!mbTreeSearchEnabled)
118 : : {
119 [ + - ][ # # ]: 48 : maSegments.search(nPos, nValue);
120 : 48 : return nValue;
121 : : }
122 : :
123 [ + + ][ - + ]: 14725871 : if (!maSegments.is_tree_valid())
124 [ + - ][ # # ]: 5 : maSegments.build_tree();
125 : :
126 [ + - ][ + - ]: 14725871 : maSegments.search_tree(nPos, nValue);
127 : 14725919 : return nValue;
128 : : }
129 : :
130 : : template<typename _ValueType, typename _ExtValueType>
131 : : typename ScFlatSegmentsImpl<_ValueType, _ExtValueType>::ExtValueType
132 : 108503 : ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getSumValue(SCCOLROW nPos1, SCCOLROW nPos2)
133 : : {
134 : : RangeData aData;
135 [ + - ][ - + ]: 108503 : if (!getRangeData(nPos1, aData))
136 : 0 : return 0;
137 : :
138 : 108503 : sal_uInt32 nValue = 0;
139 : :
140 : 108503 : SCROW nCurPos = nPos1;
141 : 108503 : SCROW nEndPos = aData.mnPos2;
142 [ + + ]: 115242 : while (nEndPos <= nPos2)
143 : : {
144 : 113771 : nValue += aData.mnValue * (nEndPos - nCurPos + 1);
145 : 113771 : nCurPos = nEndPos + 1;
146 [ + - ][ + + ]: 113771 : if (!getRangeData(nCurPos, aData))
147 : 107032 : break;
148 : :
149 : 6739 : nEndPos = aData.mnPos2;
150 : : }
151 [ + + ]: 108503 : if (nCurPos <= nPos2)
152 : : {
153 [ + - ]: 1232 : nEndPos = ::std::min(nEndPos, nPos2);
154 : 1232 : nValue += aData.mnValue * (nEndPos - nCurPos + 1);
155 : : }
156 : 108503 : return nValue;
157 : : }
158 : :
159 : : template<typename _ValueType, typename _ExtValueType>
160 : 130667588 : bool ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getRangeData(SCCOLROW nPos, RangeData& rData)
161 : : {
162 [ + + ][ - + ]: 130667588 : if (!mbTreeSearchEnabled)
163 [ + - ][ # # ]: 9711 : return getRangeDataLeaf(nPos, rData);
164 : :
165 : : ValueType nValue;
166 : : SCCOLROW nPos1, nPos2;
167 : :
168 [ + + ][ + + ]: 130657877 : if (!maSegments.is_tree_valid())
169 [ + - ][ + - ]: 11501 : maSegments.build_tree();
170 : :
171 [ + - ][ + + ]: 130657877 : if (!maSegments.search_tree(nPos, nValue, &nPos1, &nPos2))
[ + - ][ - + ]
172 : 105639 : return false;
173 : :
174 : 130552238 : rData.mnPos1 = nPos1;
175 : 130552238 : rData.mnPos2 = nPos2-1; // end point is not inclusive.
176 : 130552238 : rData.mnValue = nValue;
177 : 130667588 : return true;
178 : : }
179 : :
180 : : template<typename _ValueType, typename _ExtValueType>
181 : 9845 : bool ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getRangeDataLeaf(SCCOLROW nPos, RangeData& rData)
182 : : {
183 : : ValueType nValue;
184 : : SCCOLROW nPos1, nPos2;
185 : :
186 : : // Conduct leaf-node only search. Faster when searching between range insertion.
187 : : ::std::pair<typename fst_type::const_iterator, bool> ret =
188 [ + - ][ + - ]: 9845 : maSegments.search(maItr, nPos, nValue, &nPos1, &nPos2);
189 : :
190 [ + + ][ - + ]: 9845 : if (!ret.second)
191 : 1393 : return false;
192 : :
193 [ + - ][ + - ]: 8452 : maItr = ret.first;
194 : :
195 : 8452 : rData.mnPos1 = nPos1;
196 : 8452 : rData.mnPos2 = nPos2-1; // end point is not inclusive.
197 : 8452 : rData.mnValue = nValue;
198 : 9845 : return true;
199 : : }
200 : :
201 : : template<typename _ValueType, typename _ExtValueType>
202 : 48 : void ScFlatSegmentsImpl<_ValueType, _ExtValueType>::removeSegment(SCCOLROW nPos1, SCCOLROW nPos2)
203 : : {
204 : 48 : maSegments.shift_left(nPos1, nPos2);
205 [ + - + - ]: 48 : maItr = maSegments.begin();
206 : 48 : }
207 : :
208 : : template<typename _ValueType, typename _ExtValueType>
209 : 84 : void ScFlatSegmentsImpl<_ValueType, _ExtValueType>::insertSegment(SCCOLROW nPos, SCCOLROW nSize, bool bSkipStartBoundary)
210 : : {
211 : 84 : maSegments.shift_right(nPos, nSize, bSkipStartBoundary);
212 [ + - + - ]: 84 : maItr = maSegments.begin();
213 : 84 : }
214 : :
215 : : template<typename _ValueType, typename _ExtValueType>
216 : 12 : SCCOLROW ScFlatSegmentsImpl<_ValueType, _ExtValueType>::findLastNotOf(ValueType nValue) const
217 : : {
218 : 12 : SCCOLROW nPos = numeric_limits<SCCOLROW>::max(); // position not found.
219 [ + - + - ]: 12 : typename fst_type::const_reverse_iterator itr = maSegments.rbegin(), itrEnd = maSegments.rend();
[ + - ][ + - ]
220 : : // Note that when searching in reverse direction, we need to skip the first
221 : : // node, since the right-most leaf node does not store a valid value.
222 [ + - ][ # # ]: 12 : for (++itr; itr != itrEnd; ++itr)
[ + - ][ - + ]
[ + - ][ # # ]
[ + - ][ - + ]
223 : : {
224 [ # # ][ # # ]: 0 : if (itr->second != nValue)
[ # # ][ # # ]
225 : : {
226 [ # # ][ # # ]: 0 : nPos = (--itr)->first - 1;
227 : 0 : break;
228 : : }
229 : : }
230 : 12 : return nPos;
231 : : }
232 : :
233 : : template<typename _ValueType, typename _ExtValueType>
234 : 0 : bool ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getFirst(RangeData& rData)
235 : : {
236 [ # # ]: 0 : maItr = maSegments.begin();
237 : 0 : return getNext(rData);
238 : : }
239 : :
240 : : template<typename _ValueType, typename _ExtValueType>
241 : 0 : bool ScFlatSegmentsImpl<_ValueType, _ExtValueType>::getNext(RangeData& rData)
242 : : {
243 [ # # ]: 0 : typename fst_type::const_iterator itrEnd = maSegments.end();
244 [ # # ]: 0 : if (maItr == itrEnd)
245 : 0 : return false;
246 : :
247 [ # # ]: 0 : rData.mnPos1 = maItr->first;
248 [ # # ]: 0 : rData.mnValue = maItr->second;
249 : :
250 [ # # ]: 0 : ++maItr;
251 [ # # ]: 0 : if (maItr == itrEnd)
252 : 0 : return false;
253 : :
254 [ # # ]: 0 : rData.mnPos2 = maItr->first - 1;
255 : 0 : return true;
256 : : }
257 : :
258 : : // ============================================================================
259 : :
260 : 1206 : class ScFlatUInt16SegmentsImpl : public ScFlatSegmentsImpl<sal_uInt16, sal_uInt32>
261 : : {
262 : : public:
263 : 1488 : explicit ScFlatUInt16SegmentsImpl(SCCOLROW nMax, sal_uInt16 nDefault) :
264 : 1488 : ScFlatSegmentsImpl<sal_uInt16, sal_uInt32>(nMax, nDefault)
265 : : {
266 : 1488 : }
267 : : };
268 : :
269 : : // ----------------------------------------------------------------------------
270 : :
271 : 16433 : class ScFlatBoolSegmentsImpl : public ScFlatSegmentsImpl<bool>
272 : : {
273 : : public:
274 : 17657 : explicit ScFlatBoolSegmentsImpl(SCCOLROW nMax) :
275 : 17657 : ScFlatSegmentsImpl<bool>(nMax, false)
276 : : {
277 : 17657 : }
278 : :
279 : : bool setTrue(SCCOLROW nPos1, SCCOLROW nPos2);
280 : : bool setFalse(SCCOLROW nPos1, SCCOLROW nPos2);
281 : : };
282 : :
283 : 5364009 : bool ScFlatBoolSegmentsImpl::setTrue(SCCOLROW nPos1, SCCOLROW nPos2)
284 : : {
285 : 5364009 : return setValue(nPos1, nPos2, true);
286 : : }
287 : :
288 : 44530 : bool ScFlatBoolSegmentsImpl::setFalse(SCCOLROW nPos1, SCCOLROW nPos2)
289 : : {
290 : 44530 : return setValue(nPos1, nPos2, false);
291 : : }
292 : :
293 : : // ============================================================================
294 : :
295 : 481 : ScFlatBoolRowSegments::ForwardIterator::ForwardIterator(ScFlatBoolRowSegments& rSegs) :
296 : 481 : mrSegs(rSegs), mnCurPos(0), mnLastPos(-1), mbCurValue(false)
297 : : {
298 : 481 : }
299 : :
300 : 9165761 : bool ScFlatBoolRowSegments::ForwardIterator::getValue(SCROW nPos, bool& rVal)
301 : : {
302 [ + - ]: 9165761 : if (nPos >= mnCurPos)
303 : : // It can only go in a forward direction.
304 : 9165761 : mnCurPos = nPos;
305 : :
306 [ + + ]: 9165761 : if (mnCurPos > mnLastPos)
307 : : {
308 : : // position not in the current segment. Update the current value.
309 : : ScFlatBoolRowSegments::RangeData aData;
310 [ + - ][ - + ]: 481 : if (!mrSegs.getRangeData(mnCurPos, aData))
311 : 0 : return false;
312 : :
313 : 481 : mbCurValue = aData.mbValue;
314 : 481 : mnLastPos = aData.mnRow2;
315 : : }
316 : :
317 : 9165761 : rVal = mbCurValue;
318 : 9165761 : return true;
319 : : }
320 : :
321 : 9165761 : SCROW ScFlatBoolRowSegments::ForwardIterator::getLastPos() const
322 : : {
323 : 9165761 : return mnLastPos;
324 : : }
325 : :
326 : : // ----------------------------------------------------------------------------
327 : :
328 : 0 : ScFlatBoolRowSegments::RangeIterator::RangeIterator(ScFlatBoolRowSegments& rSegs) :
329 : 0 : mrSegs(rSegs)
330 : : {
331 : 0 : }
332 : :
333 : 0 : bool ScFlatBoolRowSegments::RangeIterator::getFirst(RangeData& rRange)
334 : : {
335 : : ScFlatBoolSegmentsImpl::RangeData aData;
336 [ # # ][ # # ]: 0 : if (!mrSegs.mpImpl->getFirst(aData))
337 : 0 : return false;
338 : :
339 : 0 : rRange.mnRow1 = static_cast<SCROW>(aData.mnPos1);
340 : 0 : rRange.mnRow2 = static_cast<SCROW>(aData.mnPos2);
341 : 0 : rRange.mbValue = static_cast<bool>(aData.mnValue);
342 : 0 : return true;
343 : : }
344 : :
345 : 0 : bool ScFlatBoolRowSegments::RangeIterator::getNext(RangeData& rRange)
346 : : {
347 : : ScFlatBoolSegmentsImpl::RangeData aData;
348 [ # # ][ # # ]: 0 : if (!mrSegs.mpImpl->getNext(aData))
349 : 0 : return false;
350 : :
351 : 0 : rRange.mnRow1 = static_cast<SCROW>(aData.mnPos1);
352 : 0 : rRange.mnRow2 = static_cast<SCROW>(aData.mnPos2);
353 : 0 : rRange.mbValue = static_cast<bool>(aData.mnValue);
354 : 0 : return true;
355 : : }
356 : :
357 : : // ----------------------------------------------------------------------------
358 : :
359 : 12773 : ScFlatBoolRowSegments::ScFlatBoolRowSegments() :
360 [ + - ]: 12773 : mpImpl(new ScFlatBoolSegmentsImpl(static_cast<SCCOLROW>(MAXROW)))
361 : : {
362 : 12773 : }
363 : :
364 : 0 : ScFlatBoolRowSegments::ScFlatBoolRowSegments(const ScFlatBoolRowSegments& r) :
365 [ # # ]: 0 : mpImpl(new ScFlatBoolSegmentsImpl(*r.mpImpl))
366 : : {
367 : 0 : }
368 : :
369 : 12161 : ScFlatBoolRowSegments::~ScFlatBoolRowSegments()
370 : : {
371 : 12161 : }
372 : :
373 : 5241335 : bool ScFlatBoolRowSegments::setTrue(SCROW nRow1, SCROW nRow2)
374 : : {
375 : 5241335 : return mpImpl->setTrue(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2));
376 : : }
377 : :
378 : 332 : bool ScFlatBoolRowSegments::setFalse(SCROW nRow1, SCROW nRow2)
379 : : {
380 : 332 : return mpImpl->setFalse(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2));
381 : : }
382 : :
383 : 70 : bool ScFlatBoolRowSegments::getValue(SCROW nRow)
384 : : {
385 : 70 : return mpImpl->getValue(static_cast<SCCOLROW>(nRow));
386 : : }
387 : :
388 : 18314867 : bool ScFlatBoolRowSegments::getRangeData(SCROW nRow, RangeData& rData)
389 : : {
390 : : ScFlatBoolSegmentsImpl::RangeData aData;
391 [ + - ][ - + ]: 18314867 : if (!mpImpl->getRangeData(static_cast<SCCOLROW>(nRow), aData))
392 : 0 : return false;
393 : :
394 : 18314867 : rData.mbValue = aData.mnValue;
395 : 18314867 : rData.mnRow1 = static_cast<SCROW>(aData.mnPos1);
396 : 18314867 : rData.mnRow2 = static_cast<SCROW>(aData.mnPos2);
397 : 18314867 : return true;
398 : : }
399 : :
400 : 134 : bool ScFlatBoolRowSegments::getRangeDataLeaf(SCROW nRow, RangeData& rData)
401 : : {
402 : : ScFlatBoolSegmentsImpl::RangeData aData;
403 [ + - ][ - + ]: 134 : if (!mpImpl->getRangeDataLeaf(static_cast<SCCOLROW>(nRow), aData))
404 : 0 : return false;
405 : :
406 : 134 : rData.mbValue = aData.mnValue;
407 : 134 : rData.mnRow1 = static_cast<SCROW>(aData.mnPos1);
408 : 134 : rData.mnRow2 = static_cast<SCROW>(aData.mnPos2);
409 : 134 : return true;
410 : : }
411 : :
412 : 28 : void ScFlatBoolRowSegments::removeSegment(SCROW nRow1, SCROW nRow2)
413 : : {
414 : 28 : mpImpl->removeSegment(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2));
415 : 28 : }
416 : :
417 : 52 : void ScFlatBoolRowSegments::insertSegment(SCROW nRow, SCROW nSize, bool bSkipStartBoundary)
418 : : {
419 : 52 : mpImpl->insertSegment(static_cast<SCCOLROW>(nRow), static_cast<SCCOLROW>(nSize), bSkipStartBoundary);
420 : 52 : }
421 : :
422 : 8 : SCROW ScFlatBoolRowSegments::findLastNotOf(bool bValue) const
423 : : {
424 : 8 : return static_cast<SCROW>(mpImpl->findLastNotOf(bValue));
425 : : }
426 : :
427 : : // ============================================================================
428 : :
429 : 4884 : ScFlatBoolColSegments::ScFlatBoolColSegments() :
430 [ + - ]: 4884 : mpImpl(new ScFlatBoolSegmentsImpl(static_cast<SCCOLROW>(MAXCOL)))
431 : : {
432 : 4884 : }
433 : :
434 : 0 : ScFlatBoolColSegments::ScFlatBoolColSegments(const ScFlatBoolColSegments& r) :
435 [ # # ]: 0 : mpImpl(new ScFlatBoolSegmentsImpl(*r.mpImpl))
436 : : {
437 : 0 : }
438 : :
439 : 4272 : ScFlatBoolColSegments::~ScFlatBoolColSegments()
440 : : {
441 : 4272 : }
442 : :
443 : 122674 : bool ScFlatBoolColSegments::setTrue(SCCOL nCol1, SCCOL nCol2)
444 : : {
445 : 122674 : return mpImpl->setTrue(static_cast<SCCOLROW>(nCol1), static_cast<SCCOLROW>(nCol2));
446 : : }
447 : :
448 : 44198 : bool ScFlatBoolColSegments::setFalse(SCCOL nCol1, SCCOL nCol2)
449 : : {
450 : 44198 : return mpImpl->setFalse(static_cast<SCCOLROW>(nCol1), static_cast<SCCOLROW>(nCol2));
451 : : }
452 : :
453 : 111035870 : bool ScFlatBoolColSegments::getRangeData(SCCOL nCol, RangeData& rData)
454 : : {
455 : : ScFlatBoolSegmentsImpl::RangeData aData;
456 [ + - ][ - + ]: 111035870 : if (!mpImpl->getRangeData(static_cast<SCCOLROW>(nCol), aData))
457 : 0 : return false;
458 : :
459 : 111035870 : rData.mbValue = aData.mnValue;
460 : 111035870 : rData.mnCol1 = static_cast<SCCOL>(aData.mnPos1);
461 : 111035870 : rData.mnCol2 = static_cast<SCCOL>(aData.mnPos2);
462 : 111035870 : return true;
463 : : }
464 : :
465 : 6 : void ScFlatBoolColSegments::removeSegment(SCCOL nCol1, SCCOL nCol2)
466 : : {
467 : 6 : mpImpl->removeSegment(static_cast<SCCOLROW>(nCol1), static_cast<SCCOLROW>(nCol2));
468 : 6 : }
469 : :
470 : 6 : void ScFlatBoolColSegments::insertSegment(SCCOL nCol, SCCOL nSize, bool bSkipStartBoundary)
471 : : {
472 : 6 : mpImpl->insertSegment(static_cast<SCCOLROW>(nCol), static_cast<SCCOLROW>(nSize), bSkipStartBoundary);
473 : 6 : }
474 : :
475 : : // ============================================================================
476 : :
477 : 3342 : ScFlatUInt16RowSegments::ForwardIterator::ForwardIterator(ScFlatUInt16RowSegments& rSegs) :
478 : 3342 : mrSegs(rSegs), mnCurPos(0), mnLastPos(-1), mnCurValue(0)
479 : : {
480 : 3342 : }
481 : :
482 : 9168645 : bool ScFlatUInt16RowSegments::ForwardIterator::getValue(SCROW nPos, sal_uInt16& rVal)
483 : : {
484 [ + - ]: 9168645 : if (nPos >= mnCurPos)
485 : : // It can only go in a forward direction.
486 : 9168645 : mnCurPos = nPos;
487 : :
488 [ + + ]: 9168645 : if (mnCurPos > mnLastPos)
489 : : {
490 : : // position not in the current segment. Update the current value.
491 : : ScFlatUInt16RowSegments::RangeData aData;
492 [ + - ][ - + ]: 5171 : if (!mrSegs.getRangeData(mnCurPos, aData))
493 : 0 : return false;
494 : :
495 : 5171 : mnCurValue = aData.mnValue;
496 : 5171 : mnLastPos = aData.mnRow2;
497 : : }
498 : :
499 : 9168645 : rVal = mnCurValue;
500 : 9168645 : return true;
501 : : }
502 : :
503 : 9168021 : SCROW ScFlatUInt16RowSegments::ForwardIterator::getLastPos() const
504 : : {
505 : 9168021 : return mnLastPos;
506 : : }
507 : :
508 : : // ----------------------------------------------------------------------------
509 : :
510 : 1488 : ScFlatUInt16RowSegments::ScFlatUInt16RowSegments(sal_uInt16 nDefault) :
511 [ + - ]: 1488 : mpImpl(new ScFlatUInt16SegmentsImpl(static_cast<SCCOLROW>(MAXROW), nDefault))
512 : : {
513 : 1488 : }
514 : :
515 : 0 : ScFlatUInt16RowSegments::ScFlatUInt16RowSegments(const ScFlatUInt16RowSegments& r) :
516 [ # # ]: 0 : mpImpl(new ScFlatUInt16SegmentsImpl(*r.mpImpl))
517 : : {
518 : 0 : }
519 : :
520 : 1206 : ScFlatUInt16RowSegments::~ScFlatUInt16RowSegments()
521 : : {
522 : 1206 : }
523 : :
524 : 10904 : void ScFlatUInt16RowSegments::setValue(SCROW nRow1, SCROW nRow2, sal_uInt16 nValue)
525 : : {
526 : 10904 : mpImpl->setValue(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2), nValue);
527 : 10904 : }
528 : :
529 : 14725849 : sal_uInt16 ScFlatUInt16RowSegments::getValue(SCROW nRow)
530 : : {
531 : 14725849 : return mpImpl->getValue(static_cast<SCCOLROW>(nRow));
532 : : }
533 : :
534 : 108503 : sal_uInt32 ScFlatUInt16RowSegments::getSumValue(SCROW nRow1, SCROW nRow2)
535 : : {
536 : 108503 : return mpImpl->getSumValue(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2));
537 : : }
538 : :
539 : 1094577 : bool ScFlatUInt16RowSegments::getRangeData(SCROW nRow, RangeData& rData)
540 : : {
541 : : ScFlatUInt16SegmentsImpl::RangeData aData;
542 [ + - ][ - + ]: 1094577 : if (!mpImpl->getRangeData(static_cast<SCCOLROW>(nRow), aData))
543 : 0 : return false;
544 : :
545 : 1094577 : rData.mnRow1 = aData.mnPos1;
546 : 1094577 : rData.mnRow2 = aData.mnPos2;
547 : 1094577 : rData.mnValue = aData.mnValue;
548 : 1094577 : return true;
549 : : }
550 : :
551 : 14 : void ScFlatUInt16RowSegments::removeSegment(SCROW nRow1, SCROW nRow2)
552 : : {
553 : 14 : mpImpl->removeSegment(static_cast<SCCOLROW>(nRow1), static_cast<SCCOLROW>(nRow2));
554 : 14 : }
555 : :
556 : 26 : void ScFlatUInt16RowSegments::insertSegment(SCROW nRow, SCROW nSize, bool bSkipStartBoundary)
557 : : {
558 : 26 : mpImpl->insertSegment(static_cast<SCCOLROW>(nRow), static_cast<SCCOLROW>(nSize), bSkipStartBoundary);
559 : 26 : }
560 : :
561 : 4 : SCROW ScFlatUInt16RowSegments::findLastNotOf(sal_uInt16 nValue) const
562 : : {
563 : 4 : return static_cast<SCROW>(mpImpl->findLastNotOf(nValue));
564 : : }
565 : :
566 : 2418 : void ScFlatUInt16RowSegments::enableTreeSearch(bool bEnable)
567 : : {
568 : 2418 : mpImpl->enableTreeSearch(bEnable);
569 [ + - ][ + - ]: 2589 : }
570 : :
571 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|