| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/boostorg/json | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_JSON_DETAIL_DIGEST_HPP | ||
| 11 | #define BOOST_JSON_DETAIL_DIGEST_HPP | ||
| 12 | |||
| 13 | namespace boost { | ||
| 14 | namespace json { | ||
| 15 | namespace detail { | ||
| 16 | |||
| 17 | // Calculate salted digest of string | ||
| 18 | template<class ForwardIterator> | ||
| 19 | std::size_t | ||
| 20 | 10779 | digest( | |
| 21 | ForwardIterator b, | ||
| 22 | ForwardIterator e, | ||
| 23 | std::size_t salt) noexcept | ||
| 24 | { | ||
| 25 | #if BOOST_JSON_ARCH == 64 | ||
| 26 | 10779 | std::uint64_t const prime = 0x100000001B3ULL; | |
| 27 | 10779 | std::uint64_t hash = 0xcbf29ce484222325ULL; | |
| 28 | #else | ||
| 29 | std::uint32_t const prime = 0x01000193UL; | ||
| 30 | std::uint32_t hash = 0x811C9DC5UL; | ||
| 31 | #endif | ||
| 32 | 10779 | hash += salt; | |
| 33 |
2/2✓ Branch 0 taken 2887 times.
✓ Branch 1 taken 2241 times.
|
30238 | for(; b != e; ++b) |
| 34 | 19459 | hash = (*b ^ hash) * prime; | |
| 35 | 10779 | return hash; | |
| 36 | } | ||
| 37 | |||
| 38 | } // detail | ||
| 39 | } // namespace json | ||
| 40 | } // namespace boost | ||
| 41 | |||
| 42 | #endif | ||
| 43 |