catch_test_case_info_hasher.cpp
1 2 // Copyright Catch2 Authors 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE.txt or copy at 5 // https://www.boost.org/LICENSE_1_0.txt) 6 7 // SPDX-License-Identifier: BSL-1.0 8 9 #include <catch2/catch_test_case_info.hpp> 10 #include <catch2/internal/catch_test_case_info_hasher.hpp> 11 12 namespace Catch { 13 TestCaseInfoHasher::TestCaseInfoHasher( hash_t seed ): m_seed( seed ) {} 14 15 uint32_t TestCaseInfoHasher::operator()( TestCaseInfo const& t ) const { 16 // FNV-1a hash algorithm that is designed for uniqueness: 17 const hash_t prime = 1099511628211u; 18 hash_t hash = 14695981039346656037u; 19 for ( const char c : t.name ) { 20 hash ^= c; 21 hash *= prime; 22 } 23 for ( const char c : t.className ) { 24 hash ^= c; 25 hash *= prime; 26 } 27 for ( const Tag& tag : t.tags ) { 28 for ( const char c : tag.original ) { 29 hash ^= c; 30 hash *= prime; 31 } 32 } 33 hash ^= m_seed; 34 hash *= prime; 35 const uint32_t low{ static_cast<uint32_t>( hash ) }; 36 const uint32_t high{ static_cast<uint32_t>( hash >> 32 ) }; 37 return low * high; 38 } 39 } // namespace Catch