mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 09:15:29 +01:00 
			
		
		
		
	Improve std::hash<SMaterial> implementation
This commit is contained in:
		@@ -483,9 +483,15 @@ struct std::hash<irr::video::SMaterial>
 | 
			
		||||
	/// @brief std::hash specialization for video::SMaterial
 | 
			
		||||
	std::size_t operator()(const irr::video::SMaterial &m) const noexcept
 | 
			
		||||
	{
 | 
			
		||||
		// basic implementation that hashes the two things most likely to differ
 | 
			
		||||
		auto h1 = std::hash<irr::video::ITexture*>{}(m.getTexture(0));
 | 
			
		||||
		auto h2 = std::hash<int>{}(m.MaterialType);
 | 
			
		||||
		return (h1 << 1) ^ h2;
 | 
			
		||||
		std::size_t ret = 0;
 | 
			
		||||
		for (auto h : { // the three members most likely to differ
 | 
			
		||||
			std::hash<irr::video::ITexture*>{}(m.getTexture(0)),
 | 
			
		||||
			std::hash<int>{}(m.MaterialType),
 | 
			
		||||
			std::hash<irr::u32>{}(m.ColorParam.color)
 | 
			
		||||
		}) {
 | 
			
		||||
			ret += h;
 | 
			
		||||
			ret ^= (ret << 6) + (ret >> 2); // distribute bits
 | 
			
		||||
		}
 | 
			
		||||
		return ret;
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user