Skip to content

Commit 4cca7a9

Browse files
authored
Merge pull request #45 from cmazakas/xxh3-docs
add xxh3-128 reference docs
2 parents d35b8b7 + 110128a commit 4cca7a9

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

doc/hash2/reference.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ https://www.boost.org/LICENSE_1_0.txt
1515

1616
include::reference/fnv1a.adoc[]
1717
include::reference/xxhash.adoc[]
18+
include::reference/xxh3.adoc[]
1819
include::reference/siphash.adoc[]
1920
include::reference/hmac.adoc[]
2021
include::reference/md5.adoc[]

doc/hash2/reference/xxh3.adoc

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
////
2+
Copyright 2025 Christian Mazakas
3+
Distributed under the Boost Software License, Version 1.0.
4+
https://www.boost.org/LICENSE_1_0.txt
5+
////
6+
7+
[#ref_xxh3]
8+
# <boost/hash2/xxh3.hpp>
9+
:idprefix: ref_xxh3_
10+
11+
```
12+
#include <boost/hash2/digest.hpp>
13+
14+
namespace boost {
15+
namespace hash2 {
16+
17+
class xxh3_128;
18+
19+
} // namespace hash2
20+
} // namespace boost
21+
```
22+
23+
This header implements the https://xxhash.com/[XXH3-128 algorithm], defined https://github.com/Cyan4973/xxHash/blob/dev/doc/xxhash_spec.md[here].
24+
25+
## xxh3_128
26+
27+
```
28+
class xxh3_128
29+
{
30+
public:
31+
32+
using result_type = digest<16>;
33+
34+
constexpr xxh3_128();
35+
explicit constexpr xxh3_128( std::uint64_t seed );
36+
xxh3_128( void const* p, std::size_t n );
37+
constexpr xxh3_128( unsigned char const* p, std::size_t n );
38+
39+
// XXH3-specific named constructors, matching the reference implementation
40+
41+
static constexpr xxh3_128 with_seed( std::uint64_t seed );
42+
43+
static xxh3_128 with_secret( void const* p, std::size_t n );
44+
static constexpr xxh3_128 with_secret( unsigned char const* p, std::size_t n );
45+
46+
static xxh3_128 with_secret_and_seed( void const* p, std::size_t n, std::uint64_t seed );
47+
static constexpr xxh3_128 with_secret_and_seed( unsigned char const* p, std::size_t n, std::uint64_t seed );
48+
49+
void update( void const* p, std::size_t n );
50+
constexpr void update( unsigned char const* p, std::size_t n );
51+
52+
constexpr result_type result();
53+
};
54+
```
55+
56+
### Constructors
57+
58+
```
59+
constexpr xxh3_128();
60+
```
61+
62+
Default constructor.
63+
64+
Effects: ::
65+
Initializes the internal state of the XXH3-128 algorithm to its initial values.
66+
67+
```
68+
explicit constexpr xxh3_128( std::uint64_t seed );
69+
```
70+
71+
Constructor taking an integer seed value.
72+
73+
Effects: ::
74+
Initializes the internal state of the XXH3 algorithm using the given `seed`.
75+
76+
Remarks: ::
77+
By convention, if `seed` is zero, the effect of this constructor is the same as default construction.
78+
79+
```
80+
xxh3_128( void const* p, std::size_t n );
81+
constexpr xxh3_128( unsigned char const* p, std::size_t n );
82+
```
83+
84+
Constructor taking a byte sequence seed.
85+
86+
Effects: ::
87+
Initializes the state as if by default construction, then if `n` is not zero, a secret and seed are both derived from the input and are used internally by the algorithm.
88+
89+
Remarks: ::
90+
By convention, if `n` is zero, the effect of this constructor is the same as default construction.
91+
92+
### Named Constructors
93+
94+
```
95+
static constexpr xxh3_128 with_seed( std::uint64_t seed );
96+
```
97+
98+
An alias for the seed constructor, provided for compatibility with the specification.
99+
100+
Effects: ::
101+
Initializes the internal state of the XXH3 algorithm using the given `seed`.
102+
103+
Remarks: ::
104+
By convention, if `seed` is zero, the effect of this constructor is the same as default construction.
105+
106+
```
107+
static xxh3_128 with_secret( void const* p, std::size_t n );
108+
static constexpr xxh3_128 with_secret( unsigned char const* p, std::size_t n );
109+
```
110+
111+
Effects: ::
112+
+
113+
--
114+
Initializes the state of the algorithm using the provided key in a way that maximizes adherence to the XXH3 spec.
115+
116+
If `n` is less than the minimum default secret length of 136 bytes, the default secret is used. If `n` is larger than the size of the default key (192 bytes) then a secret is synthesized by accumulating the supplied byte sequence into a 192 byte block. Otherwise, the provided secret is used as is specified in the https://github.com/Cyan4973/xxHash/blob/dev/doc/xxhash_spec.md[XXH3 spec].
117+
--
118+
119+
```
120+
static xxh3_128 with_secret_and_seed( void const* p, std::size_t n, std::uint64_t seed );
121+
static constexpr xxh3_128 with_secret_and_seed( unsigned char const* p, std::size_t n, std::uint64_t seed );
122+
```
123+
124+
Effects: ::
125+
+
126+
--
127+
Initializes the algorithm using both the provided seed and secret.
128+
129+
Because of how the algorithm is defined, this is equivalent to using `with_seed` for all inputs &le; 240 bytes and `with_secret` for all inputs larger than 240 bytes.
130+
--
131+
132+
### update
133+
134+
```
135+
void update( void const* p, std::size_t n );
136+
constexpr void update( unsigned char const* p, std::size_t n );
137+
```
138+
139+
Effects: ::
140+
Updates the internal state of the XXH3-128 algorithm from the byte sequence `[p, p+n)`.
141+
142+
Remarks: ::
143+
Consecutive calls to `update` are equivalent to a single call with the concatenated byte sequences of the individual calls.
144+
145+
### result
146+
147+
```
148+
constexpr result_type result();
149+
```
150+
151+
Effects: ::
152+
Obtains a 128 bit hash value from the state as specified by XXH3-128, then updates the state.
153+
154+
Returns: ::
155+
The obtained hash value.
156+
157+
Remarks: ::
158+
The state is updated to allow repeated calls to `result()` to return a pseudorandom sequence of `result_type` values, effectively extending the output.

0 commit comments

Comments
 (0)