From eedfc65bf13aaea2d02ddb26ef5201b897565c0a Mon Sep 17 00:00:00 2001 From: Geoffrey Allott Date: Tue, 2 Aug 2022 08:50:21 +0100 Subject: [PATCH] rename tans to tANS --- Makefile | 6 +- src/{tans_constants.h => tANS_constants.h} | 0 src/{tans_decode_st.c => tANS_decode_st.c} | 10 +- src/tANS_decode_st.h | 11 ++ src/{tans_decode_tbl.c => tANS_decode_tbl.c} | 4 +- src/tANS_decode_tbl.h | 16 +++ src/{tans_encode_st.c => tANS_encode_st.c} | 8 +- src/tANS_encode_st.h | 12 ++ src/{tans_encode_tbl.c => tANS_encode_tbl.c} | 4 +- src/tANS_encode_tbl.h | 15 +++ src/{tans_freq_tbl.c => tANS_freq_tbl.c} | 4 +- src/{tans_freq_tbl.h => tANS_freq_tbl.h} | 6 +- src/{tans_symbol_tbl.c => tANS_symbol_tbl.c} | 4 +- src/tANS_symbol_tbl.h | 20 ++++ src/tans_decode_st.h | 11 -- src/tans_decode_tbl.h | 16 --- src/tans_encode_st.h | 12 -- src/tans_encode_tbl.h | 15 --- src/tans_symbol_tbl.h | 20 ---- test/test_tANS.c | 112 +++++++++---------- 20 files changed, 153 insertions(+), 153 deletions(-) rename src/{tans_constants.h => tANS_constants.h} (100%) rename src/{tans_decode_st.c => tANS_decode_st.c} (73%) create mode 100644 src/tANS_decode_st.h rename src/{tans_decode_tbl.c => tANS_decode_tbl.c} (78%) create mode 100644 src/tANS_decode_tbl.h rename src/{tans_encode_st.c => tANS_encode_st.c} (83%) create mode 100644 src/tANS_encode_st.h rename src/{tans_encode_tbl.c => tANS_encode_tbl.c} (71%) create mode 100644 src/tANS_encode_tbl.h rename src/{tans_freq_tbl.c => tANS_freq_tbl.c} (92%) rename src/{tans_freq_tbl.h => tANS_freq_tbl.h} (59%) rename src/{tans_symbol_tbl.c => tANS_symbol_tbl.c} (87%) create mode 100644 src/tANS_symbol_tbl.h delete mode 100644 src/tans_decode_st.h delete mode 100644 src/tans_decode_tbl.h delete mode 100644 src/tans_encode_st.h delete mode 100644 src/tans_encode_tbl.h delete mode 100644 src/tans_symbol_tbl.h diff --git a/Makefile b/Makefile index 86ae62b..71ec0bd 100644 --- a/Makefile +++ b/Makefile @@ -13,11 +13,11 @@ $(RUN_TESTS): run_%: % all: $(OBJS) -$(OBJS): %.o: %.h src/tans_constants.h +$(OBJS): %.o: %.h src/tANS_constants.h $(TEST_OBJS): test/test.h $(OBJS) -test/test_tans_encode_decode.o: src/tans_decode_st.h src/tans_decode_tbl.h src/tans_encode_st.h src/tans_encode_tbl.h src/tans_symbol_tbl.h src/tans_freq_tbl.h -test/test_tans_encode_decode: src/tans_decode_st.o src/tans_decode_tbl.o src/tans_encode_st.o src/tans_encode_tbl.o src/tans_symbol_tbl.o src/tans_freq_tbl.o +test/test_tANS_encode_decode.o: src/tANS_decode_st.h src/tANS_decode_tbl.h src/tANS_encode_st.h src/tANS_encode_tbl.h src/tANS_symbol_tbl.h src/tANS_freq_tbl.h +test/test_tANS_encode_decode: src/tANS_decode_st.o src/tANS_decode_tbl.o src/tANS_encode_st.o src/tANS_encode_tbl.o src/tANS_symbol_tbl.o src/tANS_freq_tbl.o clean: rm -f $(OBJS) diff --git a/src/tans_constants.h b/src/tANS_constants.h similarity index 100% rename from src/tans_constants.h rename to src/tANS_constants.h diff --git a/src/tans_decode_st.c b/src/tANS_decode_st.c similarity index 73% rename from src/tans_decode_st.c rename to src/tANS_decode_st.c index 0f61ec8..2a51c0f 100644 --- a/src/tans_decode_st.c +++ b/src/tANS_decode_st.c @@ -1,8 +1,8 @@ -#include "tans_decode_st.h" +#include "tANS_decode_st.h" -void tans_decode_st_init(struct tans_decode_st *self, struct tans_symbol_tbl *symbol_tbl) +void tANS_decode_st_init(struct tANS_decode_st *self, struct tANS_symbol_tbl *symbol_tbl) { - tans_decode_tbl_init(&self->decode_tbl, symbol_tbl); + tANS_decode_tbl_init(&self->decode_tbl, symbol_tbl); self->x = 0; } @@ -11,10 +11,10 @@ static inline uint32_t get_uint32(uint8_t buf[const static 4]) return (uint32_t) buf[0] | (uint32_t) buf[1] << 8 | (uint32_t) buf[2] << 16 | (uint32_t) buf[3] << 24; } -uint32_t tans_decode_st_decode(struct tans_decode_st *self, uint8_t *data, uint32_t len, uint8_t *buf, uint32_t bits) +uint32_t tANS_decode_st_decode(struct tANS_decode_st *self, uint8_t *data, uint32_t len, uint8_t *buf, uint32_t bits) { uint32_t i; - struct tans_decode_tbl_entry t; + struct tANS_decode_tbl_entry t; uint32_t bit, byte, value; for (i = 0; i < len; ++i) { diff --git a/src/tANS_decode_st.h b/src/tANS_decode_st.h new file mode 100644 index 0000000..c576f4f --- /dev/null +++ b/src/tANS_decode_st.h @@ -0,0 +1,11 @@ +#pragma once + +#include "tANS_decode_tbl.h" + +struct tANS_decode_st { + struct tANS_decode_tbl decode_tbl; + uint16_t x; +}; + +void tANS_decode_st_init(struct tANS_decode_st *self, struct tANS_symbol_tbl *symbol_tbl); +uint32_t tANS_decode_st_decode(struct tANS_decode_st *self, uint8_t *data, uint32_t len, uint8_t *buf, uint32_t bits); diff --git a/src/tans_decode_tbl.c b/src/tANS_decode_tbl.c similarity index 78% rename from src/tans_decode_tbl.c rename to src/tANS_decode_tbl.c index 784ddac..4f813c6 100644 --- a/src/tans_decode_tbl.c +++ b/src/tANS_decode_tbl.c @@ -1,8 +1,8 @@ -#include "tans_decode_tbl.h" +#include "tANS_decode_tbl.h" #include "floor_log2.h" -void tans_decode_tbl_init(struct tans_decode_tbl *self, struct tans_symbol_tbl *symbol_tbl) +void tANS_decode_tbl_init(struct tANS_decode_tbl *self, struct tANS_symbol_tbl *symbol_tbl) { uint16_t i; uint16_t x; diff --git a/src/tANS_decode_tbl.h b/src/tANS_decode_tbl.h new file mode 100644 index 0000000..734d0f4 --- /dev/null +++ b/src/tANS_decode_tbl.h @@ -0,0 +1,16 @@ +#pragma once + +#include "tANS_symbol_tbl.h" + +struct tANS_decode_tbl_entry { + uint8_t symbol; + uint8_t nb_bits; + uint16_t new_x; +}; + +struct tANS_decode_tbl { + uint16_t tblsz; + struct tANS_decode_tbl_entry entries[TANS_MAX_TBLSZ]; +}; + +void tANS_decode_tbl_init(struct tANS_decode_tbl *self, struct tANS_symbol_tbl *symbol_tbl); diff --git a/src/tans_encode_st.c b/src/tANS_encode_st.c similarity index 83% rename from src/tans_encode_st.c rename to src/tANS_encode_st.c index eab6a8e..7fab508 100644 --- a/src/tans_encode_st.c +++ b/src/tANS_encode_st.c @@ -1,9 +1,9 @@ -#include "tans_encode_st.h" +#include "tANS_encode_st.h" -void tans_encode_st_init(struct tans_encode_st *self, const struct tans_symbol_tbl *symbol_tbl) +void tANS_encode_st_init(struct tANS_encode_st *self, const struct tANS_symbol_tbl *symbol_tbl) { self->symbol_tbl = *symbol_tbl; - tans_encode_tbl_init(&self->encode_tbl, &self->symbol_tbl); + tANS_encode_tbl_init(&self->encode_tbl, &self->symbol_tbl); self->x = self->encode_tbl.tblsz; } @@ -20,7 +20,7 @@ static inline void set_uint32(uint8_t buf[static 4], uint32_t value) buf[3] = (uint8_t) (value >> 24); } -uint32_t tans_encode_st_encode(struct tans_encode_st *self, uint8_t *data, uint32_t len, uint8_t *buf) +uint32_t tANS_encode_st_encode(struct tANS_encode_st *self, uint8_t *data, uint32_t len, uint8_t *buf) { uint8_t nb_bits; uint32_t i, written = 0; diff --git a/src/tANS_encode_st.h b/src/tANS_encode_st.h new file mode 100644 index 0000000..e0078c6 --- /dev/null +++ b/src/tANS_encode_st.h @@ -0,0 +1,12 @@ +#pragma once + +#include "tANS_encode_tbl.h" + +struct tANS_encode_st { + struct tANS_symbol_tbl symbol_tbl; + struct tANS_encode_tbl encode_tbl; + uint16_t x; +}; + +void tANS_encode_st_init(struct tANS_encode_st *self, const struct tANS_symbol_tbl *symbol_tbl); +uint32_t tANS_encode_st_encode(struct tANS_encode_st *self, uint8_t *data, uint32_t len, uint8_t *buf); diff --git a/src/tans_encode_tbl.c b/src/tANS_encode_tbl.c similarity index 71% rename from src/tans_encode_tbl.c rename to src/tANS_encode_tbl.c index 6c01b75..7be8889 100644 --- a/src/tans_encode_tbl.c +++ b/src/tANS_encode_tbl.c @@ -1,6 +1,6 @@ -#include "tans_encode_tbl.h" +#include "tANS_encode_tbl.h" -void tans_encode_tbl_init(struct tans_encode_tbl *self, struct tans_symbol_tbl *symbol_tbl) +void tANS_encode_tbl_init(struct tANS_encode_tbl *self, struct tANS_symbol_tbl *symbol_tbl) { uint8_t s; uint16_t i, x; diff --git a/src/tANS_encode_tbl.h b/src/tANS_encode_tbl.h new file mode 100644 index 0000000..1be51d0 --- /dev/null +++ b/src/tANS_encode_tbl.h @@ -0,0 +1,15 @@ +#pragma once + +#include "tANS_constants.h" +#include "tANS_symbol_tbl.h" + +struct tANS_encode_tbl_entry { + uint16_t x; +}; + +struct tANS_encode_tbl { + uint16_t tblsz; + struct tANS_encode_tbl_entry entries[TANS_MAX_TBLSZ]; +}; + +void tANS_encode_tbl_init(struct tANS_encode_tbl *self, struct tANS_symbol_tbl *symbol_tbl); diff --git a/src/tans_freq_tbl.c b/src/tANS_freq_tbl.c similarity index 92% rename from src/tans_freq_tbl.c rename to src/tANS_freq_tbl.c index 6d55485..841b4f9 100644 --- a/src/tans_freq_tbl.c +++ b/src/tANS_freq_tbl.c @@ -1,6 +1,6 @@ -#include "tans_freq_tbl.h" +#include "tANS_freq_tbl.h" -int tans_freq_tbl_init(struct tans_freq_tbl *self, uint16_t n_symbols, double *p, uint16_t log2_tblsz) +int tANS_freq_tbl_init(struct tANS_freq_tbl *self, uint16_t n_symbols, double *p, uint16_t log2_tblsz) { uint16_t i, tblsz, total; double total_p; diff --git a/src/tans_freq_tbl.h b/src/tANS_freq_tbl.h similarity index 59% rename from src/tans_freq_tbl.h rename to src/tANS_freq_tbl.h index 168067c..f52538e 100644 --- a/src/tans_freq_tbl.h +++ b/src/tANS_freq_tbl.h @@ -1,13 +1,13 @@ #pragma once -#include "tans_constants.h" +#include "tANS_constants.h" #include -struct tans_freq_tbl { +struct tANS_freq_tbl { uint16_t n_symbols; uint16_t log2_tblsz; uint16_t freq[TANS_MAX_SYMBOLS]; }; -int tans_freq_tbl_init(struct tans_freq_tbl *self, uint16_t n_symbols, double *p, uint16_t log2_tblsz); +int tANS_freq_tbl_init(struct tANS_freq_tbl *self, uint16_t n_symbols, double *p, uint16_t log2_tblsz); diff --git a/src/tans_symbol_tbl.c b/src/tANS_symbol_tbl.c similarity index 87% rename from src/tans_symbol_tbl.c rename to src/tANS_symbol_tbl.c index 46a9356..22a4b8d 100644 --- a/src/tans_symbol_tbl.c +++ b/src/tANS_symbol_tbl.c @@ -1,8 +1,8 @@ -#include "tans_symbol_tbl.h" +#include "tANS_symbol_tbl.h" #include "floor_log2.h" -int tans_symbol_tbl_init(struct tans_symbol_tbl *self, const struct tans_freq_tbl *freq_tbl) +int tANS_symbol_tbl_init(struct tANS_symbol_tbl *self, const struct tANS_freq_tbl *freq_tbl) { uint16_t x, step, s, i, start, freq, k; diff --git a/src/tANS_symbol_tbl.h b/src/tANS_symbol_tbl.h new file mode 100644 index 0000000..78c06e9 --- /dev/null +++ b/src/tANS_symbol_tbl.h @@ -0,0 +1,20 @@ +#pragma once + +#include "tANS_constants.h" +#include "tANS_freq_tbl.h" + +struct tANS_symbol_tbl_entry { + uint32_t nb; + uint16_t start; + uint16_t next; +}; + +struct tANS_symbol_tbl { + uint16_t n_symbols; + uint16_t log2_tblsz; + uint16_t tblsz; + uint8_t symbol[TANS_MAX_TBLSZ]; + struct tANS_symbol_tbl_entry entries[TANS_MAX_SYMBOLS]; +}; + +int tANS_symbol_tbl_init(struct tANS_symbol_tbl *self, const struct tANS_freq_tbl *freq_tbl); diff --git a/src/tans_decode_st.h b/src/tans_decode_st.h deleted file mode 100644 index c4ccfbc..0000000 --- a/src/tans_decode_st.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "tans_decode_tbl.h" - -struct tans_decode_st { - struct tans_decode_tbl decode_tbl; - uint16_t x; -}; - -void tans_decode_st_init(struct tans_decode_st *self, struct tans_symbol_tbl *symbol_tbl); -uint32_t tans_decode_st_decode(struct tans_decode_st *self, uint8_t *data, uint32_t len, uint8_t *buf, uint32_t bits); diff --git a/src/tans_decode_tbl.h b/src/tans_decode_tbl.h deleted file mode 100644 index 7c374a3..0000000 --- a/src/tans_decode_tbl.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "tans_symbol_tbl.h" - -struct tans_decode_tbl_entry { - uint8_t symbol; - uint8_t nb_bits; - uint16_t new_x; -}; - -struct tans_decode_tbl { - uint16_t tblsz; - struct tans_decode_tbl_entry entries[TANS_MAX_TBLSZ]; -}; - -void tans_decode_tbl_init(struct tans_decode_tbl *self, struct tans_symbol_tbl *symbol_tbl); diff --git a/src/tans_encode_st.h b/src/tans_encode_st.h deleted file mode 100644 index 4859be6..0000000 --- a/src/tans_encode_st.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "tans_encode_tbl.h" - -struct tans_encode_st { - struct tans_symbol_tbl symbol_tbl; - struct tans_encode_tbl encode_tbl; - uint16_t x; -}; - -void tans_encode_st_init(struct tans_encode_st *self, const struct tans_symbol_tbl *symbol_tbl); -uint32_t tans_encode_st_encode(struct tans_encode_st *self, uint8_t *data, uint32_t len, uint8_t *buf); diff --git a/src/tans_encode_tbl.h b/src/tans_encode_tbl.h deleted file mode 100644 index fbae420..0000000 --- a/src/tans_encode_tbl.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "tans_constants.h" -#include "tans_symbol_tbl.h" - -struct tans_encode_tbl_entry { - uint16_t x; -}; - -struct tans_encode_tbl { - uint16_t tblsz; - struct tans_encode_tbl_entry entries[TANS_MAX_TBLSZ]; -}; - -void tans_encode_tbl_init(struct tans_encode_tbl *self, struct tans_symbol_tbl *symbol_tbl); diff --git a/src/tans_symbol_tbl.h b/src/tans_symbol_tbl.h deleted file mode 100644 index 1392b5a..0000000 --- a/src/tans_symbol_tbl.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "tans_constants.h" -#include "tans_freq_tbl.h" - -struct tans_symbol_tbl_entry { - uint32_t nb; - uint16_t start; - uint16_t next; -}; - -struct tans_symbol_tbl { - uint16_t n_symbols; - uint16_t log2_tblsz; - uint16_t tblsz; - uint8_t symbol[TANS_MAX_TBLSZ]; - struct tans_symbol_tbl_entry entries[TANS_MAX_SYMBOLS]; -}; - -int tans_symbol_tbl_init(struct tans_symbol_tbl *self, const struct tans_freq_tbl *freq_tbl); diff --git a/test/test_tANS.c b/test/test_tANS.c index f551daf..f8e9865 100644 --- a/test/test_tANS.c +++ b/test/test_tANS.c @@ -1,14 +1,14 @@ #include "test.h" #include "floor_log2.h" -#include "tans_decode_st.h" -#include "tans_encode_st.h" +#include "tANS_decode_st.h" +#include "tANS_encode_st.h" -enum test_result test_tans_encode_equal_freq(void) +enum test_result test_tANS_encode_equal_freq(void) { - struct tans_freq_tbl freq_tbl; - struct tans_symbol_tbl symbol_tbl; - struct tans_encode_st encode_st; + struct tANS_freq_tbl freq_tbl; + struct tANS_symbol_tbl symbol_tbl; + struct tANS_encode_st encode_st; uint8_t data[8] = {0x01, 0xfe, 0x32, 0x12, 0x06, 0x07, 0x88, 0x00}; double p[256]; uint8_t buf[4 + 8 + 4] = {0}; @@ -17,21 +17,21 @@ enum test_result test_tans_encode_equal_freq(void) uint16_t log2_tblsz = 10; for (i = 0; i < n_symbols; ++i) p[i] = 1.0 / n_symbols; - ASSERT_NE(tans_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1); - ASSERT_EQ(tans_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0); - tans_encode_st_init(&encode_st, &symbol_tbl); + ASSERT_NE(tANS_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1); + ASSERT_EQ(tANS_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0); + tANS_encode_st_init(&encode_st, &symbol_tbl); - ASSERT_EQ(tans_encode_st_encode(&encode_st, data, sizeof data, buf + 4), sizeof data * 8); + ASSERT_EQ(tANS_encode_st_encode(&encode_st, data, sizeof data, buf + 4), sizeof data * 8); return TEST_SUCCESS; } -enum test_result test_tans_encode_high_zero_probability(void) +enum test_result test_tANS_encode_high_zero_probability(void) { - struct tans_freq_tbl freq_tbl; - struct tans_symbol_tbl symbol_tbl; - struct tans_encode_st encode_st; + struct tANS_freq_tbl freq_tbl; + struct tANS_symbol_tbl symbol_tbl; + struct tANS_encode_st encode_st; uint8_t data[8] = {0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x23}; double p[256]; uint8_t buf[16] = {0}; @@ -41,21 +41,21 @@ enum test_result test_tans_encode_high_zero_probability(void) p[0] = 0.75; for (i = 1; i < n_symbols; ++i) p[i] = 0.25 / n_symbols; - ASSERT_NE(tans_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1); - ASSERT_EQ(tans_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0); - tans_encode_st_init(&encode_st, &symbol_tbl); + ASSERT_NE(tANS_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1); + ASSERT_EQ(tANS_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0); + tANS_encode_st_init(&encode_st, &symbol_tbl); - ASSERT_LT(tans_encode_st_encode(&encode_st, data, sizeof data, buf + 4), 24); + ASSERT_LT(tANS_encode_st_encode(&encode_st, data, sizeof data, buf + 4), 24); return TEST_SUCCESS; } -enum test_result test_tans_encode_decode_equal_freq(void) +enum test_result test_tANS_encode_decode_equal_freq(void) { - struct tans_freq_tbl freq_tbl; - struct tans_symbol_tbl symbol_tbl; - struct tans_encode_st encode_st; - struct tans_decode_st decode_st; + struct tANS_freq_tbl freq_tbl; + struct tANS_symbol_tbl symbol_tbl; + struct tANS_encode_st encode_st; + struct tANS_decode_st decode_st; uint8_t data[8] = {0x01, 0xfe, 0x32, 0x12, 0x06, 0x07, 0x88, 0x00}; double p[256]; uint8_t buf[4 + 8 + 4] = {0}; @@ -65,15 +65,15 @@ enum test_result test_tans_encode_decode_equal_freq(void) uint16_t log2_tblsz = 10; for (i = 0; i < n_symbols; ++i) p[i] = 1.0 / n_symbols; - ASSERT_NE(tans_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1); - ASSERT_EQ(tans_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0); - tans_encode_st_init(&encode_st, &symbol_tbl); - tans_decode_st_init(&decode_st, &symbol_tbl); + ASSERT_NE(tANS_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1); + ASSERT_EQ(tANS_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0); + tANS_encode_st_init(&encode_st, &symbol_tbl); + tANS_decode_st_init(&decode_st, &symbol_tbl); - ASSERT_EQ(tans_encode_st_encode(&encode_st, data, sizeof data, buf + 4), 64); + ASSERT_EQ(tANS_encode_st_encode(&encode_st, data, sizeof data, buf + 4), 64); decode_st.x = (uint16_t) (encode_st.x - (1 << log2_tblsz)); - ASSERT_EQ(tans_decode_st_decode(&decode_st, rec, sizeof rec, buf + 4, 64), 0); + ASSERT_EQ(tANS_decode_st_decode(&decode_st, rec, sizeof rec, buf + 4, 64), 0); for (i = 0; i < sizeof rec; ++i) { ASSERT_EQ(data[i], rec[i]); @@ -82,12 +82,12 @@ enum test_result test_tans_encode_decode_equal_freq(void) return TEST_SUCCESS; } -enum test_result test_tans_encode_decode_high_zero_probability(void) +enum test_result test_tANS_encode_decode_high_zero_probability(void) { - struct tans_freq_tbl freq_tbl; - struct tans_symbol_tbl symbol_tbl; - struct tans_encode_st encode_st; - struct tans_decode_st decode_st; + struct tANS_freq_tbl freq_tbl; + struct tANS_symbol_tbl symbol_tbl; + struct tANS_encode_st encode_st; + struct tANS_decode_st decode_st; uint8_t data[8] = {0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x23}; double p[256]; uint8_t buf[4 + 8 + 4] = {0}; @@ -99,16 +99,16 @@ enum test_result test_tans_encode_decode_high_zero_probability(void) p[0] = 0.75; for (i = 1; i < n_symbols; ++i) p[i] = 0.25 / n_symbols; - ASSERT_NE(tans_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1); - ASSERT_EQ(tans_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0); - tans_encode_st_init(&encode_st, &symbol_tbl); - tans_decode_st_init(&decode_st, &symbol_tbl); + ASSERT_NE(tANS_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1); + ASSERT_EQ(tANS_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0); + tANS_encode_st_init(&encode_st, &symbol_tbl); + tANS_decode_st_init(&decode_st, &symbol_tbl); - bits = tans_encode_st_encode(&encode_st, data, sizeof data, buf + 4); + bits = tANS_encode_st_encode(&encode_st, data, sizeof data, buf + 4); decode_st.x = (uint16_t) (encode_st.x - (1 << log2_tblsz)); - ASSERT_EQ(tans_decode_st_decode(&decode_st, rec, sizeof rec, buf + 4, bits), 0); + ASSERT_EQ(tANS_decode_st_decode(&decode_st, rec, sizeof rec, buf + 4, bits), 0); for (i = 0; i < sizeof rec; ++i) { ASSERT_EQ(data[i], rec[i]); @@ -117,12 +117,12 @@ enum test_result test_tans_encode_decode_high_zero_probability(void) return TEST_SUCCESS; } -enum test_result test_tans_encode_decode_long_stream(void) +enum test_result test_tANS_encode_decode_long_stream(void) { - struct tans_freq_tbl freq_tbl; - struct tans_symbol_tbl symbol_tbl; - struct tans_encode_st encode_st; - struct tans_decode_st decode_st; + struct tANS_freq_tbl freq_tbl; + struct tANS_symbol_tbl symbol_tbl; + struct tANS_encode_st encode_st; + struct tANS_decode_st decode_st; uint8_t data[65536]; double p[256]; uint8_t rec[65536]; @@ -134,19 +134,19 @@ enum test_result test_tans_encode_decode_long_stream(void) p[0] = 0.75; for (i = 1; i < n_symbols; ++i) p[i] = 0.25 / n_symbols; - ASSERT_NE(tans_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1); - ASSERT_EQ(tans_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0); - tans_encode_st_init(&encode_st, &symbol_tbl); - tans_decode_st_init(&decode_st, &symbol_tbl); + ASSERT_NE(tANS_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1); + ASSERT_EQ(tANS_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0); + tANS_encode_st_init(&encode_st, &symbol_tbl); + tANS_decode_st_init(&decode_st, &symbol_tbl); for (i = 0; i < 65536; ++i) { data[i] = (uint8_t) (i % 4 == 3 ? i / 4 : 0); } - bits = (uint32_t) tans_encode_st_encode(&encode_st, data, sizeof data, buf + 4); + bits = (uint32_t) tANS_encode_st_encode(&encode_st, data, sizeof data, buf + 4); decode_st.x = (uint16_t) (encode_st.x - (1 << log2_tblsz)); - ASSERT_EQ(tans_decode_st_decode(&decode_st, rec, sizeof rec, buf + 4, bits), 0); + ASSERT_EQ(tANS_decode_st_decode(&decode_st, rec, sizeof rec, buf + 4, bits), 0); for (i = 0; i < sizeof rec; ++i) { ASSERT_EQ(data[i], rec[i]); @@ -157,9 +157,9 @@ enum test_result test_tans_encode_decode_long_stream(void) int main(void) { - RUN_TEST(test_tans_encode_equal_freq); - RUN_TEST(test_tans_encode_high_zero_probability); - RUN_TEST(test_tans_encode_decode_equal_freq); - RUN_TEST(test_tans_encode_decode_high_zero_probability); - RUN_TEST(test_tans_encode_decode_long_stream); + RUN_TEST(test_tANS_encode_equal_freq); + RUN_TEST(test_tANS_encode_high_zero_probability); + RUN_TEST(test_tANS_encode_decode_equal_freq); + RUN_TEST(test_tANS_encode_decode_high_zero_probability); + RUN_TEST(test_tANS_encode_decode_long_stream); } -- 2.34.1