]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/json/detail/digest.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / json / detail / digest.hpp
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 BOOST_JSON_NS_BEGIN
14 namespace detail {
15
16 // Calculate salted digest of string
17 inline
18 std::size_t
19 digest(
20 char const* s,
21 std::size_t n,
22 std::size_t salt) noexcept
23 {
24 #if BOOST_JSON_ARCH == 64
25 std::uint64_t const prime = 0x100000001B3ULL;
26 std::uint64_t hash = 0xcbf29ce484222325ULL;
27 #else
28 std::uint32_t const prime = 0x01000193UL;
29 std::uint32_t hash = 0x811C9DC5UL;
30 #endif
31 hash += salt;
32 for(;n--;++s)
33 hash = (*s ^ hash) * prime;
34 return hash;
35 }
36
37 } // detail
38 BOOST_JSON_NS_END
39
40 #endif