Add combine_hashes function.

This commit is contained in:
levlam 2023-07-27 19:05:15 +03:00
parent 5c8b12b105
commit 070399c89a
7 changed files with 14 additions and 10 deletions

View File

@ -136,8 +136,8 @@ struct ContactEqual {
struct ContactHash { struct ContactHash {
uint32 operator()(const Contact &contact) const { uint32 operator()(const Contact &contact) const {
return (Hash<string>()(contact.phone_number_) * 2023654985u + Hash<string>()(contact.first_name_)) * 2023654985u + return combine_hashes(combine_hashes(Hash<string>()(contact.phone_number_), Hash<string>()(contact.first_name_)),
Hash<string>()(contact.last_name_); Hash<string>()(contact.last_name_));
} }
}; };

View File

@ -1922,7 +1922,7 @@ class ContactsManager final : public Actor {
WaitFreeHashMap<UserId, tl_object_ptr<telegram_api::UserProfilePhoto>, UserIdHash> pending_user_photos_; WaitFreeHashMap<UserId, tl_object_ptr<telegram_api::UserProfilePhoto>, UserIdHash> pending_user_photos_;
struct UserIdPhotoIdHash { struct UserIdPhotoIdHash {
uint32 operator()(const std::pair<UserId, int64> &pair) const { uint32 operator()(const std::pair<UserId, int64> &pair) const {
return UserIdHash()(pair.first) * 2023654985u + Hash<int64>()(pair.second); return combine_hashes(UserIdHash()(pair.first), Hash<int64>()(pair.second));
} }
}; };
WaitFreeHashMap<std::pair<UserId, int64>, FileSourceId, UserIdPhotoIdHash> user_profile_photo_file_source_ids_; WaitFreeHashMap<std::pair<UserId, int64>, FileSourceId, UserIdPhotoIdHash> user_profile_photo_file_source_ids_;

View File

@ -62,7 +62,7 @@ const int64 DEFAULT_ORDER = -1;
struct DialogDateHash { struct DialogDateHash {
uint32 operator()(const DialogDate &dialog_date) const { uint32 operator()(const DialogDate &dialog_date) const {
return Hash<int64>()(dialog_date.get_order()) * 2023654985u + DialogIdHash()(dialog_date.get_dialog_id()); return combine_hashes(Hash<int64>()(dialog_date.get_order()), DialogIdHash()(dialog_date.get_dialog_id()));
} }
}; };

View File

@ -62,8 +62,8 @@ struct FullMessageId {
struct FullMessageIdHash { struct FullMessageIdHash {
uint32 operator()(FullMessageId full_message_id) const { uint32 operator()(FullMessageId full_message_id) const {
return DialogIdHash()(full_message_id.get_dialog_id()) * 2023654985u + return combine_hashes(DialogIdHash()(full_message_id.get_dialog_id()),
MessageIdHash()(full_message_id.get_message_id()); MessageIdHash()(full_message_id.get_message_id()));
} }
}; };

View File

@ -135,9 +135,9 @@ struct FormattedTextHash {
uint32 operator()(const FormattedText &formatted_text) const { uint32 operator()(const FormattedText &formatted_text) const {
auto hash = Hash<string>()(formatted_text.text); auto hash = Hash<string>()(formatted_text.text);
for (auto &entity : formatted_text.entities) { for (auto &entity : formatted_text.entities) {
hash = hash * 2023654985u + Hash<int32>()(static_cast<int32>(entity.type)); hash = combine_hashes(hash, Hash<int32>()(static_cast<int32>(entity.type)));
hash = hash * 2023654985u + Hash<int32>()(entity.length); hash = combine_hashes(hash, Hash<int32>()(entity.length));
hash = hash * 2023654985u + Hash<int32>()(entity.offset); hash = combine_hashes(hash, Hash<int32>()(entity.offset));
} }
return hash; return hash;
} }

View File

@ -61,7 +61,7 @@ struct StoryFullId {
struct StoryFullIdHash { struct StoryFullIdHash {
uint32 operator()(StoryFullId story_full_id) const { uint32 operator()(StoryFullId story_full_id) const {
return DialogIdHash()(story_full_id.get_dialog_id()) * 2023654985u + StoryIdHash()(story_full_id.get_story_id()); return combine_hashes(DialogIdHash()(story_full_id.get_dialog_id()), StoryIdHash()(story_full_id.get_story_id()));
} }
}; };

View File

@ -69,4 +69,8 @@ inline uint32 Hash<string>::operator()(const string &value) const {
return static_cast<uint32>(std::hash<string>()(value)); return static_cast<uint32>(std::hash<string>()(value));
} }
inline uint32 combine_hashes(uint32 first_hash, uint32 second_hash) {
return first_hash * 2023654985u + second_hash;
}
} // namespace td } // namespace td