Kaydet (Commit) 7be675cd authored tarafından Noel Grandin's avatar Noel Grandin

improve combining in hash functions

specifically, use boost::hash_combine to combine values in hash
functions, except for a couple of places where I use the
small-prime-number strategy popular in the Java world, to avoid
including boost in header files that are widely shared.

Change-Id: I0e184c9ec8803bf09fc6e84fe20131b203e1652a
Reviewed-on: https://gerrit.libreoffice.org/70384
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 1d556ff8
......@@ -36,6 +36,7 @@
#include <svl/srchdefs.hxx>
#include <vcl/weld.hxx>
#include <tools/stream.hxx>
#include <boost/functional/hash.hpp>
namespace basctl
{
......@@ -693,7 +694,10 @@ bool LibInfo::Key::operator == (Key const& rKey) const
size_t LibInfo::Key::Hash::operator () (Key const& rKey) const
{
return rKey.m_aDocument.hashCode() + rKey.m_aLibName.hashCode();
std::size_t seed = 0;
boost::hash_combine(seed, rKey.m_aDocument.hashCode());
boost::hash_combine(seed, rKey.m_aLibName.hashCode());
return seed;
}
LibInfo::Item::Item (
......
......@@ -16,6 +16,7 @@
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <boost/functional/hash.hpp>
namespace svgi
{
......@@ -264,53 +265,55 @@ namespace std
using argument_type = svgi::State;
std::size_t operator()(const svgi::State& rState ) const
{
return std::hash<double>()(rState.maCTM.get( 0, 0 ))
^ std::hash<double>()(rState.maCTM.get( 1, 0 ))
^ std::hash<double>()(rState.maCTM.get( 0, 1 ))
^ std::hash<double>()(rState.maCTM.get( 1, 1 ))
^ std::hash<double>()(rState.maCTM.get( 0, 2 ))
^ std::hash<double>()(rState.maCTM.get( 1, 2 ))
^ std::hash<double>()(rState.maViewport.getWidth())
^ std::hash<double>()(rState.maViewport.getHeight())
^ std::hash<double>()(rState.maViewBox.getWidth())
^ std::hash<double>()(rState.maViewBox.getHeight())
^ size_t(rState.mbIsText)
^ size_t(rState.maFontFamily.hashCode())
^ std::hash<double>()(rState.mnFontSize)
^ std::hash<double>()(rState.mnParentFontSize)
^ size_t(rState.maFontStyle.hashCode())
^ size_t(rState.maFontVariant.hashCode())
^ std::hash<double>()(rState.mnFontWeight)
^ size_t(rState.meTextAnchor)
^ size_t(rState.mbVisibility)
^ size_t(rState.meFillType)
^ std::hash<double>()(rState.mnFillOpacity)
^ std::hash<double>()(rState.mnOpacity)
^ size_t(rState.meStrokeType)
^ std::hash<double>()(rState.mnStrokeOpacity)
^ std::hash<double>()(rState.mnViewportFillOpacity)
^ size_t(rState.maFillColor.a)
^ size_t(rState.maFillColor.r)
^ size_t(rState.maFillColor.g)
^ size_t(rState.maFillColor.b)
^ size_t(rState.maFillGradient.maStops.size())
^ size_t(rState.meFillRule)
^ size_t(rState.maStrokeColor.a)
^ size_t(rState.maStrokeColor.r)
^ size_t(rState.maStrokeColor.g)
^ size_t(rState.maStrokeColor.b)
^ size_t(rState.maStrokeGradient.maStops.size())
^ size_t(rState.maDashArray.size())
^ std::hash<double>()(rState.mnDashOffset)
^ size_t(rState.meLineCap)
^ size_t(rState.meLineJoin)
^ std::hash<double>()(rState.mnMiterLimit)
^ std::hash<double>()(rState.mnStrokeWidth)
^ size_t(rState.maViewportFillColor.a)
^ size_t(rState.maViewportFillColor.r)
^ size_t(rState.maViewportFillColor.g)
^ size_t(rState.maViewportFillColor.b)
^ size_t(rState.maViewportFillGradient.maStops.size());
std::size_t seed = 0;
boost::hash_combine(seed, rState.maCTM.get( 0, 0 ));
boost::hash_combine(seed, rState.maCTM.get( 1, 0 ));
boost::hash_combine(seed, rState.maCTM.get( 0, 1 ));
boost::hash_combine(seed, rState.maCTM.get( 1, 1 ));
boost::hash_combine(seed, rState.maCTM.get( 0, 2 ));
boost::hash_combine(seed, rState.maCTM.get( 1, 2 ));
boost::hash_combine(seed, rState.maViewport.getWidth());
boost::hash_combine(seed, rState.maViewport.getHeight());
boost::hash_combine(seed, rState.maViewBox.getWidth());
boost::hash_combine(seed, rState.maViewBox.getHeight());
boost::hash_combine(seed, rState.mbIsText);
boost::hash_combine(seed, rState.maFontFamily);
boost::hash_combine(seed, rState.mnFontSize);
boost::hash_combine(seed, rState.mnParentFontSize);
boost::hash_combine(seed, rState.maFontStyle);
boost::hash_combine(seed, rState.maFontVariant);
boost::hash_combine(seed, rState.mnFontWeight);
boost::hash_combine(seed, rState.meTextAnchor);
boost::hash_combine(seed, rState.mbVisibility);
boost::hash_combine(seed, rState.meFillType)
boost::hash_combine(seed, rState.mnFillOpacity);
boost::hash_combine(seed, rState.mnOpacity);
boost::hash_combine(seed, rState.meStrokeType);
boost::hash_combine(seed, rState.mnStrokeOpacity);
boost::hash_combine(seed, rState.mnViewportFillOpacity);
boost::hash_combine(seed, rState.maFillColor.a);
boost::hash_combine(seed, rState.maFillColor.r);
boost::hash_combine(seed, rState.maFillColor.g);
boost::hash_combine(seed, rState.maFillColor.b);
boost::hash_combine(seed, rState.maFillGradient.maStops.size());
boost::hash_combine(seed, rState.meFillRule);
boost::hash_combine(seed, rState.maStrokeColor.a);
boost::hash_combine(seed, rState.maStrokeColor.r);
boost::hash_combine(seed, rState.maStrokeColor.g);
boost::hash_combine(seed, rState.maStrokeColor.b);
boost::hash_combine(seed, rState.maStrokeGradient.maStops.size());
boost::hash_combine(seed, rState.maDashArray.size());
boost::hash_combine(seed, rState.mnDashOffset);
boost::hash_combine(seed, rState.meLineCap);
boost::hash_combine(seed, rState.meLineJoin);
boost::hash_combine(seed, rState.mnMiterLimit);
boost::hash_combine(seed, rState.mnStrokeWidth);
boost::hash_combine(seed, rState.maViewportFillColor.a);
boost::hash_combine(seed, rState.maViewportFillColor.r);
boost::hash_combine(seed, rState.maViewportFillColor.g);
boost::hash_combine(seed, rState.maViewportFillColor.b);
boost::hash_combine(seed, rState.maViewportFillGradient.maStops.size());
return seed;
}
};
}
......
......@@ -89,7 +89,10 @@ inline SdrOnOffItem makeSdrTextWordWrapItem( bool bAuto ) {
inline size_t SdrCustomShapeGeometryItem::PropertyPairHash::operator()( const SdrCustomShapeGeometryItem::PropertyPair &r1 ) const
{
return static_cast<size_t>(r1.first.hashCode()) + r1.second.hashCode();
size_t hash = 17;
hash = hash * 37 + r1.first.hashCode();
hash = hash * 37 + r1.second.hashCode();
return hash;
};
#endif
......
......@@ -56,7 +56,10 @@ struct QNamePairHash
{
size_t operator()( const QNamePair &r1 ) const
{
return static_cast<size_t>(r1.second.hashCode()) + r1.first;
size_t hash = 17;
hash = hash * 37 + r1.first;
hash = hash * 37 + r1.second.hashCode();
return hash;
}
};
......
......@@ -305,7 +305,14 @@ private:
{
const ScAddress& s = rRange.aStart;
const ScAddress& e = rRange.aEnd;
return s.Tab() + s.Col() + s.Row() + e.Tab() + e.Col() + e.Row();
size_t hash = 17;
hash = hash * 37 + s.Tab();
hash = hash * 37 + s.Col();
hash = hash * 37 + s.Row();
hash = hash * 37 + e.Tab();
hash = hash * 37 + e.Col();
hash = hash * 37 + e.Row();
return hash;
}
};
......
......@@ -13,6 +13,7 @@
#include <unotools/charclass.hxx>
#include <rtl/math.hxx>
#include <sal/log.hxx>
#include <boost/functional/hash.hpp>
#include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
#include <com/sun/star/uno/Sequence.hxx>
......@@ -28,8 +29,10 @@ ScDPResultFilterContext::ScDPResultFilterContext() :
size_t ScDPResultTree::NamePairHash::operator() (const NamePairType& rPair) const
{
OUStringHash aHash;
return aHash(rPair.first) + aHash(rPair.second);
std::size_t seed = 0;
boost::hash_combine(seed, rPair.first.hashCode());
boost::hash_combine(seed, rPair.second.hashCode());
return seed;
}
ScDPResultTree::DimensionNode::DimensionNode() {}
......
......@@ -8,15 +8,16 @@
*/
#include <spellcheckcontext.hxx>
#include <boost/functional/hash.hpp>
namespace sc {
size_t SpellCheckContext::CellPos::Hash::operator() (const CellPos& rPos) const
{
size_t nVal = rPos.mnCol;
nVal = nVal << 4;
nVal += rPos.mnRow;
return nVal;
std::size_t seed = 0;
boost::hash_combine(seed, rPos.mnCol);
boost::hash_combine(seed, rPos.mnRow);
return seed;
}
SpellCheckContext::CellPos::CellPos() : mnCol(0), mnRow(0) {}
......
......@@ -82,13 +82,14 @@ namespace pdfi
{
size_t operator()(const FontAttributes& rFont ) const
{
return static_cast<size_t>(rFont.familyName.hashCode())
^ size_t(rFont.isBold ? 0xd47be593 : 0)
^ size_t(rFont.isItalic ? 0x1efd51a1 : 0)
^ size_t(rFont.isUnderline ? 0xf6bd325a : 0)
^ size_t(rFont.isOutline ? 0x12345678 : 0)
^ size_t(rFont.size)
;
std::size_t seed = 0;
boost::hash_combine(seed, rFont.familyName.hashCode());
boost::hash_combine(seed, rFont.isBold);
boost::hash_combine(seed, rFont.isItalic);
boost::hash_combine(seed, rFont.isUnderline);
boost::hash_combine(seed, rFont.isOutline);
boost::hash_combine(seed, rFont.size);
return seed;
}
};
......@@ -184,31 +185,32 @@ namespace pdfi
{
size_t operator()(const GraphicsContext& rGC ) const
{
return boost::hash_value(rGC.LineColor.Red)
^ boost::hash_value(rGC.LineColor.Green)
^ boost::hash_value(rGC.LineColor.Blue)
^ boost::hash_value(rGC.LineColor.Alpha)
^ boost::hash_value(rGC.FillColor.Red)
^ boost::hash_value(rGC.FillColor.Green)
^ boost::hash_value(rGC.FillColor.Blue)
^ boost::hash_value(rGC.FillColor.Alpha)
^ boost::hash_value(rGC.LineJoin)
^ boost::hash_value(rGC.LineCap)
^ boost::hash_value(rGC.BlendMode)
^ boost::hash_value(rGC.LineWidth)
^ boost::hash_value(rGC.Flatness)
^ boost::hash_value(rGC.MiterLimit)
^ rGC.DashArray.size()
^ boost::hash_value(rGC.FontId)
^ boost::hash_value(rGC.TextRenderMode)
^ boost::hash_value(rGC.Transformation.get( 0, 0 ))
^ boost::hash_value(rGC.Transformation.get( 1, 0 ))
^ boost::hash_value(rGC.Transformation.get( 0, 1 ))
^ boost::hash_value(rGC.Transformation.get( 1, 1 ))
^ boost::hash_value(rGC.Transformation.get( 0, 2 ))
^ boost::hash_value(rGC.Transformation.get( 1, 2 ))
^ boost::hash_value(rGC.Clip.count() ? rGC.Clip.getB2DPolygon(0).count() : 0)
;
std::size_t seed = 0;
boost::hash_combine(seed, rGC.LineColor.Red);
boost::hash_combine(seed, rGC.LineColor.Green);
boost::hash_combine(seed, rGC.LineColor.Blue);
boost::hash_combine(seed, rGC.LineColor.Alpha);
boost::hash_combine(seed, rGC.FillColor.Red);
boost::hash_combine(seed, rGC.FillColor.Green);
boost::hash_combine(seed, rGC.FillColor.Blue);
boost::hash_combine(seed, rGC.FillColor.Alpha);
boost::hash_combine(seed, rGC.LineJoin);
boost::hash_combine(seed, rGC.LineCap);
boost::hash_combine(seed, rGC.BlendMode);
boost::hash_combine(seed, rGC.LineWidth);
boost::hash_combine(seed, rGC.Flatness);
boost::hash_combine(seed, rGC.MiterLimit);
boost::hash_combine(seed, rGC.DashArray.size());
boost::hash_combine(seed, rGC.FontId);
boost::hash_combine(seed, rGC.TextRenderMode);
boost::hash_combine(seed, rGC.Transformation.get( 0, 0 ));
boost::hash_combine(seed, rGC.Transformation.get( 1, 0 ));
boost::hash_combine(seed, rGC.Transformation.get( 0, 1 ));
boost::hash_combine(seed, rGC.Transformation.get( 1, 1 ));
boost::hash_combine(seed, rGC.Transformation.get( 0, 2 ));
boost::hash_combine(seed, rGC.Transformation.get( 1, 2 ));
boost::hash_combine(seed, rGC.Clip.count() ? rGC.Clip.getB2DPolygon(0).count() : 0);
return seed;
}
};
......
......@@ -50,6 +50,7 @@
#include "vbacommandbars.hxx"
#include <boost/functional/hash.hpp>
#include <unordered_map>
using namespace ::com::sun::star;
......@@ -139,9 +140,11 @@ struct VbaTimerInfoHash
{
size_t operator()( const VbaTimerInfo& rTimerInfo ) const
{
return static_cast<size_t>(rTimerInfo.first.hashCode())
+ static_cast<size_t>(rtl_str_hashCode_WithLength( reinterpret_cast<char const *>(&rTimerInfo.second.first), sizeof( double ) ))
+ static_cast<size_t>(rtl_str_hashCode_WithLength( reinterpret_cast<char const *>(&rTimerInfo.second.second), sizeof( double ) ));
std::size_t seed = 0;
boost::hash_combine(seed, rTimerInfo.first.hashCode());
boost::hash_combine(seed, rTimerInfo.second.first);
boost::hash_combine(seed, rTimerInfo.second.second);
return seed;
}
};
......
......@@ -32,9 +32,10 @@ namespace std
{
size_t operator()(const pair< sal_UCS4, FontWeight >& rData) const
{
size_t h1 = hash<sal_UCS4>()(rData.first);
size_t h2 = hash<int>()(rData.second);
return h1 ^ h2;
std::size_t seed = 0;
boost::hash_combine(seed, rData.first);
boost::hash_combine(seed, rData.second);
return seed;
}
};
}
......
......@@ -85,15 +85,15 @@ size_t GlyphCache::IFSD_Hash::operator()(const rtl::Reference<LogicalFontInstanc
nFontId ^= aFeatName.hashCode();
}
size_t nHash = nFontId << 8;
nHash += rFontSelData.mnHeight;
nHash += rFontSelData.mnOrientation;
nHash += size_t(rFontSelData.mbVertical);
nHash += rFontSelData.GetItalic();
nHash += rFontSelData.GetWeight();
nHash += static_cast<sal_uInt16>(rFontSelData.meLanguage);
return nHash;
std::size_t seed = 0;
boost::hash_combine(seed, nFontId);
boost::hash_combine(seed, rFontSelData.mnHeight);
boost::hash_combine(seed, rFontSelData.mnOrientation);
boost::hash_combine(seed, size_t(rFontSelData.mbVertical));
boost::hash_combine(seed, rFontSelData.GetItalic());
boost::hash_combine(seed, rFontSelData.GetWeight());
boost::hash_combine(seed, static_cast<sal_uInt16>(rFontSelData.meLanguage));
return seed;
}
bool GlyphCache::IFSD_Equal::operator()(const rtl::Reference<LogicalFontInstance>& rAFontInstance,
......
......@@ -54,6 +54,7 @@
#include <config_dbus.h>
#include <config_gio.h>
#include <boost/functional/hash.hpp>
namespace psp
{
......@@ -73,11 +74,12 @@ namespace psp
struct LocaleHash
{
size_t operator()(const css::lang::Locale& rLocale) const
{ return
static_cast<size_t>(rLocale.Language.hashCode())
^ static_cast<size_t>(rLocale.Country.hashCode())
^ static_cast<size_t>(rLocale.Variant.hashCode())
;
{
std::size_t seed = 0;
boost::hash_combine(seed, rLocale.Language.hashCode());
boost::hash_combine(seed, rLocale.Country.hashCode());
boost::hash_combine(seed, rLocale.Variant.hashCode());
return seed;
}
};
......
......@@ -22,6 +22,7 @@
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <cppuhelper/implbase.hxx>
#include <boost/functional/hash.hpp>
#include <unordered_map>
struct StyleNameKey_Impl
......@@ -46,8 +47,10 @@ struct StyleNameHash_Impl
inline size_t StyleNameHash_Impl::operator()( const StyleNameKey_Impl& r ) const
{
return static_cast< size_t >( r.m_nFamily ) +
static_cast< size_t >( r.m_aName.hashCode() );
std::size_t seed = 0;
boost::hash_combine(seed, r.m_nFamily);
boost::hash_combine(seed, r.m_aName.hashCode());
return seed;
}
inline bool StyleNameHash_Impl::operator()(
......
......@@ -20,6 +20,7 @@
#include <rtl/ustring.hxx>
#include <xmloff/xmltkmap.hxx>
#include <xmloff/xmltoken.hxx>
#include <boost/functional/hash.hpp>
#include <unordered_map>
#include <utility>
......@@ -33,7 +34,10 @@ private:
{
std::size_t operator()(const std::pair<sal_uInt16,OUString> &pair) const
{
return static_cast<std::size_t>( pair.first | pair.second.hashCode() );
std::size_t seed = 0;
boost::hash_combine(seed, pair.first);
boost::hash_combine(seed, pair.second.hashCode());
return seed;
}
};
std::unordered_map< std::pair<sal_uInt16, OUString>,
......
......@@ -24,6 +24,7 @@
#include <xmloff/xmltoken.hxx>
#include <xmloff/xmlnmspe.hxx>
#include <boost/functional/hash.hpp>
#include <tools/debug.hxx>
#include <osl/diagnose.h>
#include <sal/log.hxx>
......@@ -128,7 +129,10 @@ namespace xmloff { namespace metadata
{
size_t operator()( const AttributeDescription& i_attribute ) const
{
return size_t( i_attribute.attributeToken * 100 ) + size_t( i_attribute.namespacePrefix );
std::size_t seed = 0;
boost::hash_combine(seed, i_attribute.attributeToken);
boost::hash_combine(seed, i_attribute.namespacePrefix);
return seed;
}
};
......
......@@ -24,6 +24,7 @@
#include <xmloff/nmspmap.hxx>
#include "TransformerActionInit.hxx"
#include "TransformerAction.hxx"
#include <boost/functional/hash.hpp>
#include <unordered_map>
struct NameKey_Impl
......@@ -57,8 +58,10 @@ struct NameHash_Impl
inline size_t NameHash_Impl::operator()( const NameKey_Impl& r ) const
{
return static_cast< size_t >( r.m_nPrefix ) +
static_cast< size_t >( r.m_aLocalName.hashCode() );
std::size_t seed = 0;
boost::hash_combine(seed, r.m_nPrefix);
boost::hash_combine(seed, r.m_aLocalName.hashCode());
return seed;
}
inline bool NameHash_Impl::operator()(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment