From 42ff499e233dc8dbf42d6d079081c5abcf12519a Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sat, 22 Sep 2018 19:56:52 +0200 Subject: [PATCH] use value_type --- tests/bch_decoder_test.cc | 14 +++++++------- tests/bch_encoder_test.cc | 10 +++++----- tests/rs_decoder_test.cc | 34 +++++++++++++++++----------------- tests/rs_encoder_test.cc | 14 +++++++------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/bch_decoder_test.cc b/tests/bch_decoder_test.cc index 91b62fd..0f85880 100644 --- a/tests/bch_decoder_test.cc +++ b/tests/bch_decoder_test.cc @@ -70,11 +70,11 @@ int main() typedef CODE::BoseChaudhuriHocquenghemDecoderReference<6, 1, 5, GF> BCH; GF instance; BCH decode; - uint8_t target[BCH::N] = { 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0 }; - uint8_t code[BCH::N]; + BCH::value_type target[BCH::N] = { 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0 }; + BCH::value_type code[BCH::N]; for (int i = 0; i < BCH::N; ++i) code[i] = target[i]; - std::uniform_int_distribution distribution(0, BCH::N-1); + std::uniform_int_distribution distribution(0, BCH::N-1); auto noise = std::bind(distribution, generator); for (int i = 0; i < 3; ++i) code[noise()] ^= 1; @@ -88,16 +88,16 @@ int main() typedef CODE::BoseChaudhuriHocquenghemDecoderReference<24, 1, 65343, GF> BCH; GF *instance = new GF(); BCH *decode = new BCH(); - uint16_t *target = new uint16_t[BCH::N]; + BCH::value_type *target = new BCH::value_type[BCH::N]; for (int i = 0, s = 0; i < BCH::K; ++i, s=(s*(s*s*51767+71287)+35149)&0xffffff) target[i] = (s^=s>>7)&1; - uint16_t parity[BCH::NP] = { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0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, 0, 1, 0, 1, 0, 1, 1, 0, 0 }; for (int i = 0; i < BCH::NP; ++i) target[BCH::K+i] = parity[i]; - uint16_t *code = new uint16_t[BCH::N]; + BCH::value_type *code = new BCH::value_type[BCH::N]; for (int i = 0; i < BCH::N; ++i) code[i] = target[i]; - std::uniform_int_distribution distribution(0, BCH::N-1); + std::uniform_int_distribution distribution(0, BCH::N-1); auto noise = std::bind(distribution, generator); for (int i = 0; i < 12; ++i) code[noise()] ^= 1; diff --git a/tests/bch_encoder_test.cc b/tests/bch_encoder_test.cc index 8e303a6..b0d23ea 100644 --- a/tests/bch_encoder_test.cc +++ b/tests/bch_encoder_test.cc @@ -52,8 +52,8 @@ int main() typedef CODE::BoseChaudhuriHocquenghemEncoderReference<6, 1, 5, GF> BCH; GF instance; BCH encode({0b10011, 0b11111, 0b00111}); - uint8_t code[BCH::N] = { 1, 1, 0, 0, 1 }; - uint8_t target[BCH::N] = { 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0 }; + BCH::value_type code[BCH::N] = { 1, 1, 0, 0, 1 }; + BCH::value_type target[BCH::N] = { 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0 }; encode(reinterpret_cast(code)); for (int i = 0; i < BCH::N; ++i) assert(code[i] == target[i]); @@ -64,11 +64,11 @@ int main() typedef CODE::BoseChaudhuriHocquenghemEncoderReference<24, 1, 65343, GF> BCH; GF *instance = new GF(); BCH *encode = new BCH({0b10000000000101101, 0b10000000101110011, 0b10000111110111101, 0b10101101001010101, 0b10001111100101111, 0b11111011110110101, 0b11010111101100101, 0b10111001101100111, 0b10000111010100001, 0b10111010110100111, 0b10011101000101101, 0b10001101011100011}); - uint16_t *code = new uint16_t[BCH::N]; - uint16_t *target = new uint16_t[BCH::N]; + BCH::value_type *code = new BCH::value_type[BCH::N]; + BCH::value_type *target = new BCH::value_type[BCH::N]; for (int i = 0, s = 0; i < BCH::K; ++i, s=(s*(s*s*51767+71287)+35149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 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0 }; for (int i = 0; i < BCH::NP; ++i) target[BCH::K+i] = parity[i]; (*encode)(reinterpret_cast(code)); diff --git a/tests/rs_decoder_test.cc b/tests/rs_decoder_test.cc index bd222ec..c492df0 100644 --- a/tests/rs_decoder_test.cc +++ b/tests/rs_decoder_test.cc @@ -20,14 +20,14 @@ int main() typedef CODE::ReedSolomonDecoder<4, 0, GF> RS; GF instance; RS decode; - uint8_t target[RS::N] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 3, 12, 12 }; - uint8_t code[RS::N]; + RS::value_type target[RS::N] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 3, 12, 12 }; + RS::value_type code[RS::N]; for (int i = 0; i < RS::N; ++i) code[i] = target[i]; - std::uniform_int_distribution distribution(0, RS::N-1); - auto noise = std::bind(distribution, generator); + auto pos = std::bind(std::uniform_int_distribution(0, RS::N-1), generator); + auto val = std::bind(std::uniform_int_distribution(0, RS::N), generator); for (int i = 0; i < 2; ++i) - code[noise()] = noise(); + code[pos()] = val(); decode(code); for (int i = 0; i < RS::N; ++i) assert(code[i] == target[i]); @@ -38,19 +38,19 @@ int main() typedef CODE::ReedSolomonDecoder<16, 0, GF> RS; GF instance; RS decode; - uint8_t target[RS::N]; + RS::value_type target[RS::N]; for (int i = 0; i < RS::K; ++i) target[i] = i + 1; - uint8_t parity[RS::NP] = { 1, 126, 147, 48, 155, 224, 3, 157, 29, 226, 40, 114, 61, 30, 244, 75 }; + RS::value_type parity[RS::NP] = { 1, 126, 147, 48, 155, 224, 3, 157, 29, 226, 40, 114, 61, 30, 244, 75 }; for (int i = 0; i < RS::NP; ++i) target[RS::K+i] = parity[i]; - uint8_t code[RS::N]; + RS::value_type code[RS::N]; for (int i = 0; i < RS::N; ++i) code[i] = target[i]; - std::uniform_int_distribution distribution(0, RS::N-1); - auto noise = std::bind(distribution, generator); + auto pos = std::bind(std::uniform_int_distribution(0, RS::N-1), generator); + auto val = std::bind(std::uniform_int_distribution(0, RS::N), generator); for (int i = 0; i < 8; ++i) - code[noise()] = noise(); + code[pos()] = val(); decode(code); for (int i = 0; i < RS::N; ++i) assert(code[i] == target[i]); @@ -61,19 +61,19 @@ int main() typedef CODE::ReedSolomonDecoder<64, 1, GF> RS; GF *instance = new GF(); RS *decode = new RS(); - uint16_t *target = new uint16_t[RS::N]; + RS::value_type *target = new RS::value_type[RS::N]; for (int i = 0; i < RS::K; ++i) target[i] = i + 1; - uint16_t parity[RS::NP] = { 25271, 26303, 22052, 31318, 31233, 6076, 40148, 29468, 47507, 32655, 12404, 13265, 23901, 38403, 50967, 50433, 40818, 226, 62296, 23636, 56393, 12952, 11476, 44416, 518, 50014, 10037, 57582, 33421, 42654, 54025, 7157, 4826, 52148, 17167, 23294, 6427, 40953, 11168, 35305, 18209, 1868, 39971, 54928, 27566, 1424, 4846, 25347, 34710, 42190, 56452, 21859, 49805, 28028, 41657, 25756, 22014, 24479, 28758, 17438, 12976, 61743, 46735, 1557 }; + RS::value_type parity[RS::NP] = { 25271, 26303, 22052, 31318, 31233, 6076, 40148, 29468, 47507, 32655, 12404, 13265, 23901, 38403, 50967, 50433, 40818, 226, 62296, 23636, 56393, 12952, 11476, 44416, 518, 50014, 10037, 57582, 33421, 42654, 54025, 7157, 4826, 52148, 17167, 23294, 6427, 40953, 11168, 35305, 18209, 1868, 39971, 54928, 27566, 1424, 4846, 25347, 34710, 42190, 56452, 21859, 49805, 28028, 41657, 25756, 22014, 24479, 28758, 17438, 12976, 61743, 46735, 1557 }; for (int i = 0; i < RS::NP; ++i) target[RS::K+i] = parity[i]; - uint16_t *code = new uint16_t[RS::N]; + RS::value_type *code = new RS::value_type[RS::N]; for (int i = 0; i < RS::N; ++i) code[i] = target[i]; - std::uniform_int_distribution distribution(0, RS::N-1); - auto noise = std::bind(distribution, generator); + auto pos = std::bind(std::uniform_int_distribution(0, RS::N-1), generator); + auto val = std::bind(std::uniform_int_distribution(0, RS::N), generator); for (int i = 0; i < 32; ++i) - code[noise()] = noise(); + code[pos()] = val(); (*decode)(code); for (int i = 0; i < RS::N; ++i) assert(code[i] == target[i]); diff --git a/tests/rs_encoder_test.cc b/tests/rs_encoder_test.cc index 661a78b..80a0e25 100644 --- a/tests/rs_encoder_test.cc +++ b/tests/rs_encoder_test.cc @@ -17,8 +17,8 @@ int main() typedef CODE::ReedSolomonEncoder<4, 0, GF> RS; GF instance; RS encode; - uint8_t code[RS::N] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - uint8_t target[RS::N] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 3, 12, 12 }; + RS::value_type code[RS::N] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + RS::value_type target[RS::N] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 3, 12, 12 }; encode(code); for (int i = 0; i < RS::N; ++i) assert(code[i] == target[i]); @@ -29,10 +29,10 @@ int main() typedef CODE::ReedSolomonEncoder<16, 0, GF> RS; GF instance; RS encode; - uint8_t code[RS::N], target[RS::N]; + RS::value_type code[RS::N], target[RS::N]; for (int i = 0; i < RS::K; ++i) target[i] = code[i] = i + 1; - uint8_t parity[RS::NP] = { 1, 126, 147, 48, 155, 224, 3, 157, 29, 226, 40, 114, 61, 30, 244, 75 }; + RS::value_type parity[RS::NP] = { 1, 126, 147, 48, 155, 224, 3, 157, 29, 226, 40, 114, 61, 30, 244, 75 }; for (int i = 0; i < RS::NP; ++i) target[RS::K+i] = parity[i]; encode(code); @@ -45,11 +45,11 @@ int main() typedef CODE::ReedSolomonEncoder<64, 1, GF> RS; GF *instance = new GF(); RS *encode = new RS(); - uint16_t *code = new uint16_t[RS::N]; - uint16_t *target = new uint16_t[RS::N]; + RS::value_type *code = new RS::value_type[RS::N]; + RS::value_type *target = new RS::value_type[RS::N]; for (int i = 0; i < RS::K; ++i) target[i] = code[i] = i + 1; - uint16_t parity[RS::NP] = { 25271, 26303, 22052, 31318, 31233, 6076, 40148, 29468, 47507, 32655, 12404, 13265, 23901, 38403, 50967, 50433, 40818, 226, 62296, 23636, 56393, 12952, 11476, 44416, 518, 50014, 10037, 57582, 33421, 42654, 54025, 7157, 4826, 52148, 17167, 23294, 6427, 40953, 11168, 35305, 18209, 1868, 39971, 54928, 27566, 1424, 4846, 25347, 34710, 42190, 56452, 21859, 49805, 28028, 41657, 25756, 22014, 24479, 28758, 17438, 12976, 61743, 46735, 1557 }; + RS::value_type parity[RS::NP] = { 25271, 26303, 22052, 31318, 31233, 6076, 40148, 29468, 47507, 32655, 12404, 13265, 23901, 38403, 50967, 50433, 40818, 226, 62296, 23636, 56393, 12952, 11476, 44416, 518, 50014, 10037, 57582, 33421, 42654, 54025, 7157, 4826, 52148, 17167, 23294, 6427, 40953, 11168, 35305, 18209, 1868, 39971, 54928, 27566, 1424, 4846, 25347, 34710, 42190, 56452, 21859, 49805, 28028, 41657, 25756, 22014, 24479, 28758, 17438, 12976, 61743, 46735, 1557 }; for (int i = 0; i < RS::NP; ++i) target[RS::K+i] = parity[i]; (*encode)(code);