seqgen.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2017-2021, 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. #ifndef SEQGEN_H
  11. #define SEQGEN_H
  12. #define XXH_STATIC_LINKING_ONLY
  13. #include "xxhash.h"
  14. #include <stddef.h> /* size_t */
  15. typedef enum {
  16. SEQ_gen_ml = 0,
  17. SEQ_gen_ll,
  18. SEQ_gen_of,
  19. SEQ_gen_max /* Must be the last value */
  20. } SEQ_gen_type;
  21. /* Internal state, do not use */
  22. typedef struct {
  23. XXH64_state_t xxh; /* xxh state for all the data produced so far (seed=0) */
  24. unsigned seed;
  25. int state; /* enum to control state machine (clean=0) */
  26. unsigned saved;
  27. size_t bytesLeft;
  28. } SEQ_stream;
  29. SEQ_stream SEQ_initStream(unsigned seed);
  30. typedef struct {
  31. void* dst;
  32. size_t size;
  33. size_t pos;
  34. } SEQ_outBuffer;
  35. /* Returns non-zero until the current type/value has been generated.
  36. * Must pass the same type/value until it returns 0.
  37. *
  38. * Recommended to pick a value in the middle of the range you want, since there
  39. * may be some noise that causes actual results to be slightly different.
  40. * We try to be more accurate for smaller values.
  41. *
  42. * NOTE: Very small values don't work well (< 6).
  43. */
  44. size_t SEQ_gen(SEQ_stream* stream, SEQ_gen_type type, unsigned value,
  45. SEQ_outBuffer* out);
  46. /* Returns the xxhash of the data produced so far */
  47. XXH64_hash_t SEQ_digest(SEQ_stream const* stream);
  48. #endif /* SEQGEN_H */