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