summaryrefslogtreecommitdiff
path: root/sc/inc/fstalgorithm.hxx
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-04-22 00:36:40 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-04-23 21:08:24 -0400
commit94cf534a89634290201141a08e19d156bb3b9a19 (patch)
tree8a8aa794f7bddbaaa0870c459263c7dae5ebdedc /sc/inc/fstalgorithm.hxx
parentaa3e2b7ae90c0fdad28dfd097a230e8ab4cb2565 (diff)
Handle reordering of row hidden and filtered flags during sort.
Only when the "keep query" flag is set. Change-Id: Ia799f62ec53a08cfd92e93c546965002c030b324
Diffstat (limited to 'sc/inc/fstalgorithm.hxx')
-rw-r--r--sc/inc/fstalgorithm.hxx60
1 files changed, 49 insertions, 11 deletions
diff --git a/sc/inc/fstalgorithm.hxx b/sc/inc/fstalgorithm.hxx
index 20972ef05641..8a50ae0f4a45 100644
--- a/sc/inc/fstalgorithm.hxx
+++ b/sc/inc/fstalgorithm.hxx
@@ -15,6 +15,35 @@
namespace sc {
+template<typename _Key, typename _Span>
+void buildSpan(
+ std::vector<_Span>& rSpans,
+ typename mdds::flat_segment_tree<_Key,bool>::const_iterator it,
+ typename mdds::flat_segment_tree<_Key,bool>::const_iterator itEnd, const _Key* pStart )
+{
+ _Key nLastPos = it->first;
+ bool bLastVal = it->second;
+ for (++it; it != itEnd; ++it)
+ {
+ _Key nThisPos = it->first;
+ bool bThisVal = it->second;
+
+ if (bLastVal)
+ {
+ _Key nIndex1 = nLastPos;
+ _Key nIndex2 = nThisPos-1;
+
+ if (!pStart || *pStart < nIndex1)
+ rSpans.push_back(_Span(nIndex1, nIndex2));
+ else if (*pStart <= nIndex2)
+ rSpans.push_back(_Span(*pStart, nIndex2));
+ }
+
+ nLastPos = nThisPos;
+ bLastVal = bThisVal;
+ }
+}
+
/**
* Convert a flat_segment_tree structure whose value type is boolean, into
* an array of ranges that corresponds with the segments that have a 'true'
@@ -28,20 +57,29 @@ std::vector<_Span> toSpanArray( const mdds::flat_segment_tree<_Key,bool>& rTree
std::vector<_Span> aSpans;
typename FstType::const_iterator it = rTree.begin(), itEnd = rTree.end();
- _Key nLastPos = it->first;
- bool bLastVal = it->second;
- for (++it; it != itEnd; ++it)
- {
- _Key nThisPos = it->first;
- bool bThisVal = it->second;
+ buildSpan<_Key,_Span>(aSpans, it, itEnd, NULL);
+ return aSpans;
+}
- if (bLastVal)
- aSpans.push_back(_Span(nLastPos, nThisPos-1));
+template<typename _Key, typename _Span>
+std::vector<_Span> toSpanArray( const mdds::flat_segment_tree<_Key,bool>& rTree, _Key nStartPos )
+{
+ typedef mdds::flat_segment_tree<_Key,bool> FstType;
- nLastPos = nThisPos;
- bLastVal = bThisVal;
- }
+ std::vector<_Span> aSpans;
+ if (!rTree.is_tree_valid())
+ return aSpans;
+
+ bool bThisVal = false;
+ std::pair<typename FstType::const_iterator, bool> r =
+ rTree.search_tree(nStartPos, bThisVal);
+
+ if (!r.second)
+ // Tree search failed.
+ return aSpans;
+ typename FstType::const_iterator it = r.first, itEnd = rTree.end();
+ buildSpan<_Key,_Span>(aSpans, it, itEnd, &nStartPos);
return aSpans;
}