xref: /aosp_15_r20/external/zstd/tests/seqgen.h (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin Cui /*
2*01826a49SYabin Cui  * Copyright (c) Meta Platforms, Inc. and affiliates.
3*01826a49SYabin Cui  * All rights reserved.
4*01826a49SYabin Cui  *
5*01826a49SYabin Cui  * This source code is licensed under both the BSD-style license (found in the
6*01826a49SYabin Cui  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7*01826a49SYabin Cui  * in the COPYING file in the root directory of this source tree).
8*01826a49SYabin Cui  * You may select, at your option, one of the above-listed licenses.
9*01826a49SYabin Cui  */
10*01826a49SYabin Cui 
11*01826a49SYabin Cui #ifndef SEQGEN_H
12*01826a49SYabin Cui #define SEQGEN_H
13*01826a49SYabin Cui 
14*01826a49SYabin Cui #define XXH_STATIC_LINKING_ONLY
15*01826a49SYabin Cui 
16*01826a49SYabin Cui #include "xxhash.h"
17*01826a49SYabin Cui #include <stddef.h>   /* size_t */
18*01826a49SYabin Cui 
19*01826a49SYabin Cui typedef enum {
20*01826a49SYabin Cui     SEQ_gen_ml = 0,
21*01826a49SYabin Cui     SEQ_gen_ll,
22*01826a49SYabin Cui     SEQ_gen_of,
23*01826a49SYabin Cui     SEQ_gen_max /* Must be the last value */
24*01826a49SYabin Cui } SEQ_gen_type;
25*01826a49SYabin Cui 
26*01826a49SYabin Cui /* Internal state, do not use */
27*01826a49SYabin Cui typedef struct {
28*01826a49SYabin Cui     XXH64_state_t xxh; /* xxh state for all the data produced so far (seed=0) */
29*01826a49SYabin Cui     unsigned seed;
30*01826a49SYabin Cui     int state; /* enum to control state machine (clean=0) */
31*01826a49SYabin Cui     unsigned saved;
32*01826a49SYabin Cui     size_t bytesLeft;
33*01826a49SYabin Cui } SEQ_stream;
34*01826a49SYabin Cui 
35*01826a49SYabin Cui SEQ_stream SEQ_initStream(unsigned seed);
36*01826a49SYabin Cui 
37*01826a49SYabin Cui typedef struct {
38*01826a49SYabin Cui     void* dst;
39*01826a49SYabin Cui     size_t size;
40*01826a49SYabin Cui     size_t pos;
41*01826a49SYabin Cui } SEQ_outBuffer;
42*01826a49SYabin Cui 
43*01826a49SYabin Cui /* Returns non-zero until the current type/value has been generated.
44*01826a49SYabin Cui  * Must pass the same type/value until it returns 0.
45*01826a49SYabin Cui  *
46*01826a49SYabin Cui  * Recommended to pick a value in the middle of the range you want, since there
47*01826a49SYabin Cui  * may be some noise that causes actual results to be slightly different.
48*01826a49SYabin Cui  * We try to be more accurate for smaller values.
49*01826a49SYabin Cui  *
50*01826a49SYabin Cui  * NOTE: Very small values don't work well (< 6).
51*01826a49SYabin Cui  */
52*01826a49SYabin Cui size_t SEQ_gen(SEQ_stream* stream, SEQ_gen_type type, unsigned value,
53*01826a49SYabin Cui                SEQ_outBuffer* out);
54*01826a49SYabin Cui 
55*01826a49SYabin Cui /* Returns the xxhash of the data produced so far */
56*01826a49SYabin Cui XXH64_hash_t SEQ_digest(SEQ_stream const* stream);
57*01826a49SYabin Cui 
58*01826a49SYabin Cui #endif /* SEQGEN_H */
59