You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hist.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* ******************************************************************
  2. * hist : Histogram functions
  3. * part of Finite State Entropy project
  4. * Copyright (c) Meta Platforms, Inc. and affiliates.
  5. *
  6. * You can contact the author at :
  7. * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
  8. * - Public forum : https://groups.google.com/forum/#!forum/lz4c
  9. *
  10. * This source code is licensed under both the BSD-style license (found in the
  11. * LICENSE file in the root directory of this source tree) and the GPLv2 (found
  12. * in the COPYING file in the root directory of this source tree).
  13. * You may select, at your option, one of the above-listed licenses.
  14. ****************************************************************** */
  15. /* --- dependencies --- */
  16. #include "zstd_deps.h" /* size_t */
  17. /* --- simple histogram functions --- */
  18. /*! HIST_count():
  19. * Provides the precise count of each byte within a table 'count'.
  20. * 'count' is a table of unsigned int, of minimum size (*maxSymbolValuePtr+1).
  21. * Updates *maxSymbolValuePtr with actual largest symbol value detected.
  22. * @return : count of the most frequent symbol (which isn't identified).
  23. * or an error code, which can be tested using HIST_isError().
  24. * note : if return == srcSize, there is only one symbol.
  25. */
  26. size_t HIST_count(unsigned* count, unsigned* maxSymbolValuePtr,
  27. const void* src, size_t srcSize);
  28. unsigned HIST_isError(size_t code); /**< tells if a return value is an error code */
  29. /* --- advanced histogram functions --- */
  30. #define HIST_WKSP_SIZE_U32 1024
  31. #define HIST_WKSP_SIZE (HIST_WKSP_SIZE_U32 * sizeof(unsigned))
  32. /** HIST_count_wksp() :
  33. * Same as HIST_count(), but using an externally provided scratch buffer.
  34. * Benefit is this function will use very little stack space.
  35. * `workSpace` is a writable buffer which must be 4-bytes aligned,
  36. * `workSpaceSize` must be >= HIST_WKSP_SIZE
  37. */
  38. size_t HIST_count_wksp(unsigned* count, unsigned* maxSymbolValuePtr,
  39. const void* src, size_t srcSize,
  40. void* workSpace, size_t workSpaceSize);
  41. /** HIST_countFast() :
  42. * same as HIST_count(), but blindly trusts that all byte values within src are <= *maxSymbolValuePtr.
  43. * This function is unsafe, and will segfault if any value within `src` is `> *maxSymbolValuePtr`
  44. */
  45. size_t HIST_countFast(unsigned* count, unsigned* maxSymbolValuePtr,
  46. const void* src, size_t srcSize);
  47. /** HIST_countFast_wksp() :
  48. * Same as HIST_countFast(), but using an externally provided scratch buffer.
  49. * `workSpace` is a writable buffer which must be 4-bytes aligned,
  50. * `workSpaceSize` must be >= HIST_WKSP_SIZE
  51. */
  52. size_t HIST_countFast_wksp(unsigned* count, unsigned* maxSymbolValuePtr,
  53. const void* src, size_t srcSize,
  54. void* workSpace, size_t workSpaceSize);
  55. /*! HIST_count_simple() :
  56. * Same as HIST_countFast(), this function is unsafe,
  57. * and will segfault if any value within `src` is `> *maxSymbolValuePtr`.
  58. * It is also a bit slower for large inputs.
  59. * However, it does not need any additional memory (not even on stack).
  60. * @return : count of the most frequent symbol.
  61. * Note this function doesn't produce any error (i.e. it must succeed).
  62. */
  63. unsigned HIST_count_simple(unsigned* count, unsigned* maxSymbolValuePtr,
  64. const void* src, size_t srcSize);