[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/qa sc/source
Michael Meeks
michael.meeks at suse.com
Tue Mar 19 04:54:06 PDT 2013
sc/qa/unit/ucalc.cxx | 25 ++++++++++++++++---------
sc/source/core/data/cell2.cxx | 7 +++----
sc/source/core/tool/token.cxx | 11 ++++-------
3 files changed, 23 insertions(+), 20 deletions(-)
New commits:
commit 03fccc665131ba60bd6f757043e9da62417a50b7
Author: Michael Meeks <michael.meeks at suse.com>
Date: Tue Mar 19 11:52:14 2013 +0000
use cell hashing algorithm for computing groups.
Update unit tests, dumb-down hashing to compare more for similiarity
rather than identicality - we want to use this down columns.
Change-Id: Icea731daeb301e1febb2df48b6b46c9faba74e9d
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 63b740b..81fa1ea 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1222,6 +1222,13 @@ void Test::testFormulaHashAndTag()
{ "=X20", "=X$20", false }, // absolute vs relative
{ "=X20", "=$X20", false }, // absolute vs relative
{ "=X$20", "=$X20", false }, // column absolute vs row absolute
+ // similar enough for merging ...
+ { "=A1", "=B1", true },
+ { "=$A$1", "=$B$1", true },
+ { "=A1", "=C2", true },
+ { "=SUM(A1)", "=SUM(B1)", true },
+ { "=A1+3", "=B1+3", true },
+ { "=A1+7", "=B1+42", false },
};
for (size_t i = 0; i < SAL_N_ELEMENTS(aHashTests); ++i)
@@ -6221,14 +6228,14 @@ void Test::testFormulaGrouping()
const char *pFormula[3];
const bool bGroup[3];
} aGroupTests[] = {
- { { "=B1", "=C1", "" }, // single increments
- { true, true, false } },
- { { "=B1", "=D1", "=F1" }, // tripple increments
- { true, true, true } },
- { { "=B1", "", "=C1" }, // a gap
- { false, false, false } },
- { { "=B1", "=C1+3", "=C1+D1" }, // confusion: FIXME: =C1+7
- { false, false, false } },
+ { { "=SUM(B1)", "=SUM(C1)", "" }, // single increments
+ { true, true, false } },
+ { { "=SUM(B1)", "=SUM(D1)", "=SUM(F1)" }, // tripple increments
+ { true, true, true } },
+ { { "=SUM(B1)", "", "=SUM(C1)" }, // a gap
+ { false, false, false } },
+ { { "=SUM(B1)", "=SUM(C1;3)", "=SUM(D1;3)" }, // similar foo
+ { false, true, true } },
};
m_pDoc->InsertTab( 0, "sheet" );
@@ -6259,7 +6266,7 @@ void Test::testFormulaGrouping()
if( !!pCur->GetCellGroup().get() ^ aGroupTests[i].bGroup[j] )
{
printf("expected group test %d at row %d to be %d but is %d\n",
- i, j, !!pCur->GetCellGroup().get(), aGroupTests[i].bGroup[j]);
+ i, j, aGroupTests[i].bGroup[j], !!pCur->GetCellGroup().get());
CPPUNIT_ASSERT_MESSAGE("Failed", false);
}
}
diff --git a/sc/source/core/data/cell2.cxx b/sc/source/core/data/cell2.cxx
index 412f85d..f450f75 100644
--- a/sc/source/core/data/cell2.cxx
+++ b/sc/source/core/data/cell2.cxx
@@ -1722,10 +1722,9 @@ bool ScFormulaCellGroup::IsCompatible( ScSimilarFormulaDelta *pDelta )
/// formulae should produce pOther
ScSimilarFormulaDelta *ScFormulaCell::BuildDeltaTo( ScFormulaCell *pOtherCell )
{
-
-// FIXME: TODO - M1
-// if ( kohei_comparison_hash_not_equal( mnHash, pOther->mnHash )
-// return NULL;
+ // are these formule at all similar ?
+ if ( GetHash() != pOtherCell->GetHash() )
+ return NULL;
FormulaToken **pThis = pCode->GetCode();
sal_uInt16 pThisLen = pCode->GetCodeLen();
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 23a2241..6368ba7 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1348,19 +1348,16 @@ bool ScTokenArray::ImplGetReference( ScRange& rRange, bool bValidOnly ) const
namespace {
+// we want to compare for similar not identical formulae
+// so we can't use actual row & column indices.
size_t HashSingleRef( const ScSingleRefData& rRef )
{
- SCsCOL nCol = rRef.Flags.bColRel ? rRef.nRelCol : rRef.nCol;
- SCsROW nRow = rRef.Flags.bRowRel ? rRef.nRelRow : rRef.nRow;
- SCsTAB nTab = rRef.Flags.bTabRel ? rRef.nRelTab : rRef.nTab;
- size_t nVal = nCol;
- nVal += (nRow << 8);
- nVal += (nTab << 16);
+ size_t nVal = 0;
- // Embed flag values too.
nVal += rRef.Flags.bColRel;
nVal += (rRef.Flags.bRowRel << 1);
nVal += (rRef.Flags.bTabRel << 2);
+
return nVal;
}
More information about the Libreoffice-commits
mailing list