]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/BrotliCompress/enc/histogram_inc.h
BaseTools: Copy Brotli algorithm 3rd party source code for tool
[mirror_edk2.git] / BaseTools / Source / C / BrotliCompress / enc / histogram_inc.h
CommitLineData
11b7501a
SB
1/* NOLINT(build/header_guard) */\r
2/* Copyright 2013 Google Inc. All Rights Reserved.\r
3\r
4 Distributed under MIT license.\r
5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT\r
6*/\r
7\r
8/* template parameters: Histogram, DATA_SIZE, DataType */\r
9\r
10/* A simple container for histograms of data in blocks. */\r
11\r
12typedef struct FN(Histogram) {\r
13 uint32_t data_[DATA_SIZE];\r
14 size_t total_count_;\r
15 double bit_cost_;\r
16} FN(Histogram);\r
17\r
18static BROTLI_INLINE void FN(HistogramClear)(FN(Histogram)* self) {\r
19 memset(self->data_, 0, sizeof(self->data_));\r
20 self->total_count_ = 0;\r
21 self->bit_cost_ = HUGE_VAL;\r
22}\r
23\r
24static BROTLI_INLINE void FN(ClearHistograms)(\r
25 FN(Histogram)* array, size_t length) {\r
26 size_t i;\r
27 for (i = 0; i < length; ++i) FN(HistogramClear)(array + i);\r
28}\r
29\r
30static BROTLI_INLINE void FN(HistogramAdd)(FN(Histogram)* self, size_t val) {\r
31 ++self->data_[val];\r
32 ++self->total_count_;\r
33}\r
34\r
35static BROTLI_INLINE void FN(HistogramAddVector)(FN(Histogram)* self,\r
36 const DataType *p, size_t n) {\r
37 self->total_count_ += n;\r
38 n += 1;\r
39 while (--n) ++self->data_[*p++];\r
40}\r
41\r
42static BROTLI_INLINE void FN(HistogramAddHistogram)(FN(Histogram)* self,\r
43 const FN(Histogram)* v) {\r
44 size_t i;\r
45 self->total_count_ += v->total_count_;\r
46 for (i = 0; i < DATA_SIZE; ++i) {\r
47 self->data_[i] += v->data_[i];\r
48 }\r
49}\r
50\r
51static BROTLI_INLINE size_t FN(HistogramDataSize)(void) { return DATA_SIZE; }\r