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