diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-03-18 14:19:52 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-03-19 13:40:22 -0400 |
commit | 6433ab29afa4d19000c14bdc0b64c0062972427e (patch) | |
tree | fb70ea164f36e9935ed05a682e4a1f6b1893a268 /formula | |
parent | 6000c8d15510b77a02d517afb81e3d2e164b318c (diff) |
Implement (partially?) and test formula token array hash function.
For now, we don't factor in any differences in reference tokens in the
generated hash values.
Change-Id: Ie9836228eaad9c74edd884c3e8c4b273979760fd
Diffstat (limited to 'formula')
-rw-r--r-- | formula/source/core/api/token.cxx | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index f331c1e4bff5..5a47d2e43934 100644 --- a/formula/source/core/api/token.cxx +++ b/formula/source/core/api/token.cxx @@ -687,7 +687,54 @@ FormulaTokenArray* FormulaTokenArray::Clone() const size_t FormulaTokenArray::GetHash() const { - return 0; + static OUStringHash aHasher; + + size_t nHash = 1; + OpCode eOp; + StackVar eType; + const FormulaToken* p; + sal_uInt16 n = std::min<sal_uInt16>(nLen, 20); + for (sal_uInt16 i = 0; i < n; ++i) + { + p = pCode[i]; + eOp = p->GetOpCode(); + if (eOp == ocPush) + { + // This is stack variable. Do additional differentiation. + eType = p->GetType(); + switch (eType) + { + case svByte: + { + // Constant value. + sal_uInt8 nVal = p->GetByte(); + nHash += (static_cast<size_t>(nVal) << i); + continue; + } + case svDouble: + { + // Constant value. + double fVal = p->GetDouble(); + nHash += (static_cast<size_t>(fVal) << i); + continue; + } + case svString: + { + // Constant string. + const String& rStr = p->GetString(); + nHash += (aHasher(rStr) << i); + continue; + } + default: + // TODO: Decide later if we should generate hash from references as well. + ; + } + } + + // Use the opcode value in all the other cases. + nHash += (static_cast<size_t>(eOp) << i); + } + return nHash; } void FormulaTokenArray::Clear() |