ReactOS  0.4.14-dev-998-g623dd26
hist.h File Reference
#include <stddef.h>
Include dependency graph for hist.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HIST_WKSP_SIZE_U32   1024
 

Functions

size_t HIST_count (unsigned *count, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize)
 
unsigned HIST_isError (size_t code)
 
size_t HIST_count_wksp (unsigned *count, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize, unsigned *workSpace)
 
size_t HIST_countFast (unsigned *count, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize)
 
size_t HIST_countFast_wksp (unsigned *count, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize, unsigned *workSpace)
 
unsigned HIST_count_simple (unsigned *count, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize)
 

Macro Definition Documentation

◆ HIST_WKSP_SIZE_U32

#define HIST_WKSP_SIZE_U32   1024

Definition at line 58 of file hist.h.

Function Documentation

◆ HIST_count()

size_t HIST_count ( unsigned count,
unsigned maxSymbolValuePtr,
const void src,
size_t  srcSize 
)

HIST_count(): Provides the precise count of each byte within a table 'count'. 'count' is a table of unsigned int, of minimum size (*maxSymbolValuePtr+1). Updates *maxSymbolValuePtr with actual largest symbol value detected.

Returns
: count of the most frequent symbol (which isn't identified). or an error code, which can be tested using HIST_isError(). note : if return == srcSize, there is only one symbol.

Definition at line 202 of file hist.c.

204 {
205  unsigned tmpCounters[HIST_WKSP_SIZE_U32];
206  return HIST_count_wksp(count, maxSymbolValuePtr, src, srcSize, tmpCounters);
207 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define HIST_WKSP_SIZE_U32
Definition: hist.h:58
size_t HIST_count_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, unsigned *workSpace)
Definition: hist.c:193
GLenum src
Definition: glext.h:6340

◆ HIST_count_simple()

unsigned HIST_count_simple ( unsigned count,
unsigned maxSymbolValuePtr,
const void src,
size_t  srcSize 
)

HIST_count_simple() : Same as HIST_countFast(), this function is unsafe, and will segfault if any value within src is > *maxSymbolValuePtr. It is also a bit slower for large inputs. However, it does not need any additional memory (not even on stack).

Returns
: count of the most frequent symbol. Note this function doesn't produce any error (i.e. it must succeed).

Definition at line 52 of file hist.c.

54 {
55  const BYTE* ip = (const BYTE*)src;
56  const BYTE* const end = ip + srcSize;
57  unsigned maxSymbolValue = *maxSymbolValuePtr;
58  unsigned largestCount=0;
59 
60  memset(count, 0, (maxSymbolValue+1) * sizeof(*count));
61  if (srcSize==0) { *maxSymbolValuePtr = 0; return 0; }
62 
63  while (ip<end) {
64  assert(*ip <= maxSymbolValue);
65  count[*ip++]++;
66  }
67 
68  while (!count[maxSymbolValue]) maxSymbolValue--;
69  *maxSymbolValuePtr = maxSymbolValue;
70 
71  { U32 s;
72  for (s=0; s<=maxSymbolValue; s++)
73  if (count[s] > largestCount) largestCount = count[s];
74  }
75 
76  return largestCount;
77 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
GLuint GLuint end
Definition: gl.h:1545
Definition: dhcpd.h:61
unsigned char BYTE
Definition: mem.h:68
GLdouble s
Definition: gl.h:2039
GLenum src
Definition: glext.h:6340
#define memset(x, y, z)
Definition: compat.h:39

Referenced by HIST_countFast_wksp(), HUF_compressWeights(), and ZSTD_rescaleFreqs().

◆ HIST_count_wksp()

size_t HIST_count_wksp ( unsigned count,
unsigned maxSymbolValuePtr,
const void src,
size_t  srcSize,
unsigned workSpace 
)

HIST_count_wksp() : Same as HIST_count(), but using an externally provided scratch buffer. Benefit is this function will use very little stack space. workSpace must be a table of unsigned of size >= HIST_WKSP_SIZE_U32

Definition at line 193 of file hist.c.

195 {
196  if (*maxSymbolValuePtr < 255)
197  return HIST_count_parallel_wksp(count, maxSymbolValuePtr, source, sourceSize, 1, workSpace);
198  *maxSymbolValuePtr = 255;
199  return HIST_countFast_wksp(count, maxSymbolValuePtr, source, sourceSize, workSpace);
200 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
size_t HIST_countFast_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, unsigned *workSpace)
Definition: hist.c:164
static size_t HIST_count_parallel_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, unsigned checkMax, unsigned *const workSpace)
Definition: hist.c:88

Referenced by FSE_compress_wksp(), HIST_count(), and HUF_compress_internal().

◆ HIST_countFast()

size_t HIST_countFast ( unsigned count,
unsigned maxSymbolValuePtr,
const void src,
size_t  srcSize 
)

HIST_countFast() : same as HIST_count(), but blindly trusts that all byte values within src are <= *maxSymbolValuePtr. This function is unsafe, and will segfault if any value within src is > *maxSymbolValuePtr

Definition at line 174 of file hist.c.

176 {
177  unsigned* tmpCounters = ExAllocatePoolWithTag(NonPagedPool, sizeof(unsigned) * HIST_WKSP_SIZE_U32, HIST_ALLOC_TAG);
178  size_t ret;
179 
180  if (!tmpCounters)
181  return 0;
182 
183  ret = HIST_countFast_wksp(count, maxSymbolValuePtr, source, sourceSize, tmpCounters);
184 
185  ExFreePool(tmpCounters);
186 
187  return ret;
188 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define HIST_WKSP_SIZE_U32
Definition: hist.h:58
size_t HIST_countFast_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, unsigned *workSpace)
Definition: hist.c:164
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
int ret
#define HIST_ALLOC_TAG
Definition: hist.c:44
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ HIST_countFast_wksp()

size_t HIST_countFast_wksp ( unsigned count,
unsigned maxSymbolValuePtr,
const void src,
size_t  srcSize,
unsigned workSpace 
)

HIST_countFast_wksp() : Same as HIST_countFast(), but using an externally provided scratch buffer. workSpace must be a table of unsigned of size >= HIST_WKSP_SIZE_U32

Definition at line 164 of file hist.c.

167 {
168  if (sourceSize < 1500) /* heuristic threshold */
169  return HIST_count_simple(count, maxSymbolValuePtr, source, sourceSize);
170  return HIST_count_parallel_wksp(count, maxSymbolValuePtr, source, sourceSize, 0, workSpace);
171 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
static size_t HIST_count_parallel_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, unsigned checkMax, unsigned *const workSpace)
Definition: hist.c:88
unsigned HIST_count_simple(unsigned *count, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize)
Definition: hist.c:52

Referenced by HIST_count_wksp(), HIST_countFast(), and ZSTD_compressSequences_internal().

◆ HIST_isError()

unsigned HIST_isError ( size_t  code)

tells if a return value is an error code

Definition at line 47 of file hist.c.

47 { return ERR_isError(code); }
ERR_STATIC unsigned ERR_isError(size_t code)
Definition: error_private.h:56