100.00% Lines (13/13) 100.00% Functions (4/4)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) 2   // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3   // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) 3   // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 5   // Distributed under the Boost Software License, Version 1.0. (See accompanying
6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/boostorg/url 8   // Official repository: https://github.com/boostorg/url
9   // 9   //
10   10  
11   #ifndef BOOST_URL_DETAIL_FNV_1A_HPP 11   #ifndef BOOST_URL_DETAIL_FNV_1A_HPP
12   #define BOOST_URL_DETAIL_FNV_1A_HPP 12   #define BOOST_URL_DETAIL_FNV_1A_HPP
13   13  
14   #include <boost/url/detail/config.hpp> 14   #include <boost/url/detail/config.hpp>
15   #include <boost/core/detail/string_view.hpp> 15   #include <boost/core/detail/string_view.hpp>
16   #include <cstddef> 16   #include <cstddef>
17   17  
18   namespace boost { 18   namespace boost {
19   namespace urls { 19   namespace urls {
20   namespace detail { 20   namespace detail {
21   21  
22   class fnv_1a 22   class fnv_1a
23   { 23   {
24   public: 24   public:
25   using digest_type = std::size_t; 25   using digest_type = std::size_t;
26   26  
27   #if BOOST_URL_ARCH == 64 27   #if BOOST_URL_ARCH == 64
28   static constexpr std::size_t const prime = 28   static constexpr std::size_t const prime =
29   static_cast<std::size_t>(0x100000001B3ULL); 29   static_cast<std::size_t>(0x100000001B3ULL);
30   static constexpr std::size_t init_hash = 30   static constexpr std::size_t init_hash =
31   static_cast<std::size_t>(0xcbf29ce484222325ULL); 31   static_cast<std::size_t>(0xcbf29ce484222325ULL);
32   #else 32   #else
33   static constexpr std::size_t const prime = 33   static constexpr std::size_t const prime =
34   static_cast<std::size_t>(0x01000193UL); 34   static_cast<std::size_t>(0x01000193UL);
35   static constexpr std::size_t init_hash = 35   static constexpr std::size_t init_hash =
36   static_cast<std::size_t>(0x811C9DC5UL); 36   static_cast<std::size_t>(0x811C9DC5UL);
37   #endif 37   #endif
38   38  
39   explicit 39   explicit
HITCBC 40   304 fnv_1a(std::size_t salt) noexcept 40   304 fnv_1a(std::size_t salt) noexcept
HITCBC 41   304 : h_(init_hash + salt) 41   304 : h_(init_hash + salt)
42   { 42   {
HITCBC 43   304 } 43   304 }
44   44  
45   void 45   void
HITCBC 46   4550 put(char c) noexcept 46   4550 put(char c) noexcept
47   { 47   {
HITCBC 48   4550 h_ ^= c; 48   4550 h_ ^= c;
HITCBC 49   4550 h_ *= prime; 49   4550 h_ *= prime;
HITCBC 50   4550 } 50   4550 }
51   51  
52   void 52   void
HITCBC 53   304 put(core::string_view s) noexcept 53   304 put(core::string_view s) noexcept
54   { 54   {
HITCBC 55   400 for (char c: s) 55   400 for (char c: s)
56   { 56   {
HITCBC 57   96 put(c); 57   96 put(c);
58   } 58   }
HITCBC 59   304 } 59   304 }
60   60  
61   digest_type 61   digest_type
HITCBC 62   304 digest() const noexcept 62   304 digest() const noexcept
63   { 63   {
HITCBC 64   304 return h_; 64   304 return h_;
65   } 65   }
66   66  
67   private: 67   private:
68   std::size_t h_; 68   std::size_t h_;
69   }; 69   };
70   70  
71   } // detail 71   } // detail
72   } // urls 72   } // urls
73   } // boost 73   } // boost
74   74  
75   #endif 75   #endif