From 7ce8d0a50c333c23679648bf2ffa95b28e6445da Mon Sep 17 00:00:00 2001 From: xy Date: Fri, 22 Jun 2012 14:19:48 +0800 Subject: [PATCH] Stored hash value in with objects.[Part 5] --- src/subtitles/cache_manager.cpp | 23 +++++++++++------------ src/subtitles/cache_manager.h | 24 +++++++++++++----------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/subtitles/cache_manager.cpp b/src/subtitles/cache_manager.cpp index cddd0d9..dc1b604 100644 --- a/src/subtitles/cache_manager.cpp +++ b/src/subtitles/cache_manager.cpp @@ -10,17 +10,6 @@ ULONG PathDataCacheKeyTraits::Hash( const PathDataCacheKey& key ) return( CStringElementTraits::Hash(key.m_str) ); } -ULONG ScanLineData2CacheKeyTraits::Hash( const ScanLineData2CacheKey& key ) -{ - //return hash_value(static_cast(key)) ^ key.m_org.x ^ key.m_org.y; - size_t hash = PathDataCacheKeyTraits::Hash(static_cast(key)); - hash += (hash<<5); - hash += key.m_org.x; - hash += (hash<<5); - hash += key.m_org.y; - return hash; -} - ULONG PathDataTraits::Hash( const PathData& key ) { ULONG hash = 515; @@ -206,6 +195,16 @@ bool ScanLineData2CacheKey::operator==( const ScanLineData2CacheKey& key ) const && (m_org.x==key.m_org.x) && (m_org.y==key.m_org.y); } +ULONG ScanLineData2CacheKey::UpdateHashValue() +{ + m_hash_value = PathDataCacheKeyTraits::Hash(*this); + m_hash_value += (m_hash_value<<5); + m_hash_value += m_org.x; + m_hash_value += (m_hash_value<<5); + m_hash_value += m_org.y; + return m_hash_value; +} + ////////////////////////////////////////////////////////////////////////////////////////////// // OverlayNoBlurKey @@ -220,7 +219,7 @@ bool OverlayNoBlurKey::operator==( const OverlayNoBlurKey& key ) const ULONG OverlayNoBlurKey::UpdateHashValue() { - m_hash_value = ScanLineData2CacheKeyTraits::Hash(*this); + m_hash_value = __super::UpdateHashValue(); m_hash_value += (m_hash_value<<5); m_hash_value += m_p.x; m_hash_value += (m_hash_value<<5); diff --git a/src/subtitles/cache_manager.h b/src/subtitles/cache_manager.h index 0fc0a9a..3f54f8c 100644 --- a/src/subtitles/cache_manager.h +++ b/src/subtitles/cache_manager.h @@ -74,14 +74,22 @@ class ScanLineData2CacheKey: public PathDataCacheKey { public: ScanLineData2CacheKey(const CWord& word, const POINT& org):PathDataCacheKey(word),m_org(org) { } - ScanLineData2CacheKey(const ScanLineData2CacheKey& key):PathDataCacheKey(key),m_org(key.m_org) { } + ScanLineData2CacheKey(const ScanLineData2CacheKey& key) + :PathDataCacheKey(key) + ,m_org(key.m_org) + ,m_hash_value(key.m_hash_value) { } ScanLineData2CacheKey(const FwSTSStyle& style, const CStringW& str, const POINT& org) :PathDataCacheKey(style, str),m_org(org) { } bool operator==(const ScanLineData2CacheKey& key)const; - + + ULONG UpdateHashValue(); + ULONG GetHashValue()const + { + return m_hash_value; + } +public: + ULONG m_hash_value; POINT m_org; - - friend class ScanLineData2CacheKeyTraits; }; class OverlayNoBlurKey: public ScanLineData2CacheKey @@ -165,12 +173,6 @@ class PathDataCacheKeyTraits:public CElementTraits { public: static ULONG Hash(const PathDataCacheKey& key); -}; - -class ScanLineData2CacheKeyTraits:public CElementTraits -{ -public: - static ULONG Hash(const ScanLineData2CacheKey& key); }; class ScanLineDataCacheKeyTraits:public CElementTraits @@ -214,7 +216,7 @@ typedef EnhancedXyMru PathDataMruCache; -typedef EnhancedXyMru ScanLineData2MruCache; +typedef EnhancedXyMru> ScanLineData2MruCache; typedef EnhancedXyMru> OverlayNoBlurMruCache; -- 2.11.4.GIT