1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: compressedarray.hxx,v $
10 * $Revision: 1.7.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "segmenttree.hxx"
35 #include "mdds/flatsegmenttree.hxx"
37 #define USE_TREE_SEARCH 1
39 class ScFlatBoolSegmentsImpl
48 ScFlatBoolSegmentsImpl(SCCOLROW nMax
);
49 ~ScFlatBoolSegmentsImpl();
51 void setTrue(SCCOLROW nPos1
, SCCOLROW nPos2
);
52 void setFalse(SCCOLROW nPos1
, SCCOLROW nPos2
);
53 bool getValue(SCCOLROW nPos
);
54 bool getRangeData(SCCOLROW nPos
, RangeData
& rData
);
57 ScFlatBoolSegmentsImpl();
58 ScFlatBoolSegmentsImpl(const ScFlatBoolSegmentsImpl
&);
60 ::mdds::flat_segment_tree
<SCCOLROW
, bool> maSegments
;
63 ScFlatBoolSegmentsImpl::ScFlatBoolSegmentsImpl(SCCOLROW nMax
) :
64 maSegments(0, nMax
+1, false)
68 ScFlatBoolSegmentsImpl::~ScFlatBoolSegmentsImpl()
72 void ScFlatBoolSegmentsImpl::setTrue(SCCOLROW nPos1
, SCCOLROW nPos2
)
74 maSegments
.insert_segment(nPos1
, nPos2
+1, true);
77 void ScFlatBoolSegmentsImpl::setFalse(SCCOLROW nPos1
, SCCOLROW nPos2
)
79 maSegments
.insert_segment(nPos1
, nPos2
+1, false);
82 bool ScFlatBoolSegmentsImpl::getValue(SCCOLROW nPos
)
86 if (!maSegments
.is_tree_valid())
87 maSegments
.build_tree();
89 maSegments
.search_tree(nPos
, bValue
);
91 maSegments
.search(nPos
, bValue
);
96 bool ScFlatBoolSegmentsImpl::getRangeData(SCCOLROW nPos
, RangeData
& rData
)
99 if (!maSegments
.is_tree_valid())
100 maSegments
.build_tree();
104 SCCOLROW nPos1
, nPos2
;
106 if (!maSegments
.search_tree(nPos
, bValue
, &nPos1
, &nPos2
))
109 if (!maSegments
.search(nPos
, bValue
, &nPos1
, &nPos2
))
113 rData
.mnPos1
= nPos1
;
114 rData
.mnPos2
= nPos2
-1; // end point is not inclusive.
115 rData
.mbValue
= bValue
;
119 // ============================================================================
121 ScFlatBoolRowSegments::ScFlatBoolRowSegments() :
122 mpImpl(new ScFlatBoolSegmentsImpl(static_cast<SCCOLROW
>(MAXROW
)))
126 ScFlatBoolRowSegments::~ScFlatBoolRowSegments()
130 void ScFlatBoolRowSegments::setTrue(SCROW nRow1
, SCROW nRow2
)
132 mpImpl
->setTrue(static_cast<SCCOLROW
>(nRow1
), static_cast<SCCOLROW
>(nRow2
));
135 void ScFlatBoolRowSegments::setFalse(SCROW nRow1
, SCROW nRow2
)
137 mpImpl
->setFalse(static_cast<SCCOLROW
>(nRow1
), static_cast<SCCOLROW
>(nRow2
));
140 bool ScFlatBoolRowSegments::getValue(SCROW nRow
)
142 return mpImpl
->getValue(static_cast<SCCOLROW
>(nRow
));
145 bool ScFlatBoolRowSegments::getRangeData(SCROW nRow
, RangeData
& rData
)
147 ScFlatBoolSegmentsImpl::RangeData aData
;
148 if (!mpImpl
->getRangeData(static_cast<SCCOLROW
>(nRow
), aData
))
151 rData
.mbValue
= aData
.mbValue
;
152 rData
.mnRow1
= static_cast<SCROW
>(aData
.mnPos1
);
153 rData
.mnRow2
= static_cast<SCROW
>(aData
.mnPos2
);
157 // ============================================================================
159 ScFlatBoolColSegments::ScFlatBoolColSegments() :
160 mpImpl(new ScFlatBoolSegmentsImpl(static_cast<SCCOLROW
>(MAXCOL
)))
164 ScFlatBoolColSegments::~ScFlatBoolColSegments()
168 void ScFlatBoolColSegments::setTrue(SCCOL nCol1
, SCCOL nCol2
)
170 mpImpl
->setTrue(static_cast<SCCOLROW
>(nCol1
), static_cast<SCCOLROW
>(nCol2
));
173 void ScFlatBoolColSegments::setFalse(SCCOL nCol1
, SCCOL nCol2
)
175 mpImpl
->setFalse(static_cast<SCCOLROW
>(nCol1
), static_cast<SCCOLROW
>(nCol2
));
178 bool ScFlatBoolColSegments::getValue(SCCOL nCol
)
180 return mpImpl
->getValue(static_cast<SCCOLROW
>(nCol
));
183 bool ScFlatBoolColSegments::getRangeData(SCCOL nCol
, RangeData
& rData
)
185 ScFlatBoolSegmentsImpl::RangeData aData
;
186 if (!mpImpl
->getRangeData(static_cast<SCCOLROW
>(nCol
), aData
))
189 rData
.mbValue
= aData
.mbValue
;
190 rData
.mnCol1
= static_cast<SCCOL
>(aData
.mnPos1
);
191 rData
.mnCol2
= static_cast<SCCOL
>(aData
.mnPos2
);