make it obvious which column BinarySearch() operates on

It was setting the column to ScQueryParams.nCol1, which
was somewhat confusing.

Change-Id: I3ab2207f507a4dc3782ea78682dacb0b08c36b19
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134123
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
This commit is contained in:
Luboš Luňák
2022-05-11 11:45:52 +02:00
parent 4348d11156
commit 976a07a1df
3 changed files with 27 additions and 27 deletions
+1 -1
View File
@@ -148,7 +148,7 @@ protected:
or if the range is not properly sorted, with nRow in that case set to the first row or after
the last row. In that case use GetFirst().
*/
bool BinarySearch();
bool BinarySearch( SCCOL col );
public:
ScQueryCellIteratorBase(ScDocument& rDocument, const ScInterpreterContext& rContext, SCTAB nTable,
+23 -23
View File
@@ -2099,19 +2099,19 @@ void TestSort::testQueryBinarySearch()
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_LESS_EQUAL, 5 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(8), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_LESS, 5 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(2), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_EQUAL, 5 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(8), it.GetRow());
}
@@ -2123,13 +2123,13 @@ void TestSort::testQueryBinarySearch()
ScQueryParam param = makeSearchParam( range, descendingCol, SC_GREATER_EQUAL, 5 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( descendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(6), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, descendingCol, SC_GREATER, 5 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( descendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(1), it.GetRow());
}
@@ -2141,19 +2141,19 @@ void TestSort::testQueryBinarySearch()
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_LESS_EQUAL, 6 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(8), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_LESS, 6 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(8), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_EQUAL, 6 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(8), it.GetRow());
}
@@ -2165,13 +2165,13 @@ void TestSort::testQueryBinarySearch()
ScQueryParam param = makeSearchParam( range, descendingCol, SC_GREATER_EQUAL, 6 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( descendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(1), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, descendingCol, SC_GREATER, 6 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( descendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(1), it.GetRow());
}
@@ -2183,19 +2183,19 @@ void TestSort::testQueryBinarySearch()
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_LESS_EQUAL, 0 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(!it.BinarySearch());
CPPUNIT_ASSERT(!it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(0), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_LESS, 0 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(!it.BinarySearch());
CPPUNIT_ASSERT(!it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(0), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_EQUAL, 0 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(!it.BinarySearch());
CPPUNIT_ASSERT(!it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(0), it.GetRow());
}
@@ -2207,13 +2207,13 @@ void TestSort::testQueryBinarySearch()
ScQueryParam param = makeSearchParam( range, descendingCol, SC_GREATER_EQUAL, 0 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( descendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(10), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, descendingCol, SC_GREATER, 0 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( descendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(10), it.GetRow());
}
@@ -2225,19 +2225,19 @@ void TestSort::testQueryBinarySearch()
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_LESS_EQUAL, 10 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(10), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_LESS, 10 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(10), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_EQUAL, 10 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(it.BinarySearch());
CPPUNIT_ASSERT(it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(10), it.GetRow());
}
@@ -2249,13 +2249,13 @@ void TestSort::testQueryBinarySearch()
ScQueryParam param = makeSearchParam( range, descendingCol, SC_GREATER_EQUAL, 10 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(!it.BinarySearch());
CPPUNIT_ASSERT(!it.BinarySearch( descendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(0), it.GetRow());
}
{
ScQueryParam param = makeSearchParam( range, descendingCol, SC_GREATER, 10 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(!it.BinarySearch());
CPPUNIT_ASSERT(!it.BinarySearch( descendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(0), it.GetRow());
}
@@ -2263,7 +2263,7 @@ void TestSort::testQueryBinarySearch()
// Search as ascending but use descending range, will return no match.
ScQueryParam param = makeSearchParam( range, descendingCol, SC_LESS_EQUAL, 1 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(!it.BinarySearch());
CPPUNIT_ASSERT(!it.BinarySearch( descendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(0), it.GetRow());
}
@@ -2271,7 +2271,7 @@ void TestSort::testQueryBinarySearch()
// Search as descending but use ascending range, will return no match.
ScQueryParam param = makeSearchParam( range, ascendingCol, SC_GREATER_EQUAL, 9 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(!it.BinarySearch());
CPPUNIT_ASSERT(!it.BinarySearch( ascendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(0), it.GetRow());
}
@@ -2279,7 +2279,7 @@ void TestSort::testQueryBinarySearch()
// SC_EQUAL with descending is considered an error, will return no match.
ScQueryParam param = makeSearchParam( range, descendingCol, SC_EQUAL, 9 );
TestQueryIterator it( *m_pDoc, m_pDoc->GetNonThreadedContext(), 0, param, false );
CPPUNIT_ASSERT(!it.BinarySearch());
CPPUNIT_ASSERT(!it.BinarySearch( descendingCol ));
CPPUNIT_ASSERT_EQUAL(SCROW(0), it.GetRow());
}
+3 -3
View File
@@ -275,7 +275,7 @@ void decBlock(std::pair<Iter, size_t>& rPos)
}
template< ScQueryCellIteratorAccess accessType, ScQueryCellIteratorType queryType >
bool ScQueryCellIteratorBase< accessType, queryType >::BinarySearch()
bool ScQueryCellIteratorBase< accessType, queryType >::BinarySearch( SCCOL col )
{
assert(maParam.GetEntry(0).bDoQuery && !maParam.GetEntry(1).bDoQuery
&& maParam.GetEntry(0).GetQueryItems().size() == 1 );
@@ -290,7 +290,7 @@ bool ScQueryCellIteratorBase< accessType, queryType >::BinarySearch()
// TODO: This will be extremely slow with mdds::multi_type_vector.
assert(nTab < rDoc.GetTableCount() && "index out of bounds, FIX IT");
nCol = maParam.nCol1;
nCol = col;
nRow = maParam.nRow1;
if (nCol >= rDoc.maTabs[nTab]->GetAllocatedColumnsCount())
@@ -632,7 +632,7 @@ bool ScQueryCellIterator< accessType >::FindEqualOrSortedLastInRange( SCCOL& nFo
bool bFound = false;
if (bBinary)
{
if (BinarySearch())
if (BinarySearch( maParam.nCol1 ))
{
// BinarySearch() already positions correctly and only needs real
// query comparisons afterwards, skip the verification check below.