├── .astylerc ├── .gitignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── bin └── .gitignore ├── include ├── catch.h ├── matrix_utilities.h ├── parameters │ ├── fec_parameters.h │ ├── internal_constants.h │ ├── internal_functions.h │ ├── parameter_checker.h │ └── parameter_io.h ├── parsed.h ├── partition.h ├── row.h ├── symbol.h ├── tuple.h └── util │ ├── deg.h │ ├── extra_math.h │ ├── octet_ops.h │ ├── rand.h │ └── systematic_indices.h ├── lib └── .gitignore ├── src ├── matrix_utilities.cpp ├── orq.cpp ├── parameters │ ├── fec_parameters.cpp │ ├── internal_functions.cpp │ ├── parameter_checker.cpp │ └── parameter_io.cpp ├── partition.cpp ├── row.cpp ├── tuple.cpp └── util │ ├── deg.cpp │ ├── extra_math.cpp │ ├── octet_ops.cpp │ ├── rand.cpp │ └── systematic_indices.cpp └── test ├── orq.cpp ├── parameters └── fec_parameters.cpp ├── parsed.cpp ├── partition.cpp ├── row.cpp ├── tuple.cpp └── util └── rand.cpp /.astylerc: -------------------------------------------------------------------------------- 1 | --style=linux 2 | --suffix=none 3 | --indent=spaces=4 4 | --formatted 5 | --pad-oper 6 | --pad-header 7 | --align-pointer=name 8 | --align-reference=name 9 | --add-brackets 10 | --convert-tabs 11 | --max-code-length=80 12 | --indent-namespaces 13 | --indent-col1-comments 14 | # --exclude="include/catch.h" 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | # Ignore Mac specific files 31 | .DS_Store 32 | 33 | Vagrantfile 34 | .vagrant 35 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 2014 Matt Olan 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | language: cpp 24 | 25 | before_install: 26 | - sudo pip install cpp-coveralls 27 | 28 | compiler: 29 | - clang 30 | - gcc 31 | 32 | script: 33 | make && make test && make gcov 34 | 35 | after_success: 36 | - coveralls --exclude lib --exclude tests --gcov-options '\-lp' 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Matt Olan, Prajjwal Bhandari. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 2014 Matt Olan 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | CC ?= gcc 24 | CXX ?= g++ 25 | SRCDIR := src 26 | TESTDIR := test 27 | INCDIR := include 28 | BUILDDIR := build 29 | TARGET := bin/orq 30 | TESTTARGET := bin/test 31 | 32 | SRCEXT := cpp 33 | SOURCES := $(shell find $(SRCDIR) -type f -name "*.$(SRCEXT)") 34 | HEADERS := $(shell find $(SRCDIR) -type f -name "*.h") 35 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) 36 | TESTSOURCES := $(shell find $(TESTDIR) -type f -name "*.$(SRCEXT)") 37 | TESTOBJECTS := $(patsubst $(TESTDIR)/%,$(BUILDDIR)/$(TESTDIR)/%,$(TESTSOURCES:.$(SRCEXT)=.o)) 38 | HEADERS := $(shell find $(INCDIR) -type f -name "*.h" -a -not -name "catch.h") 39 | CFLAGS := -g -Wall -pedantic -std=c1x 40 | CXXFLAGS := -g -Wall -pedantic -std=c++0x 41 | LDFLAGS := 42 | INC := -I $(INCDIR) 43 | 44 | # make 45 | $(TARGET): $(OBJECTS) 46 | @echo ""; echo "Linking..." 47 | $(CXX) $^ -o $(TARGET) $(LDFLAGS) 48 | 49 | $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) 50 | @mkdir -p $(dir $@) 51 | $(CXX) $(CXXFLAGS) $(INC) -c -o $@ $< 52 | 53 | # make test 54 | test: $(TARGET) $(TESTTARGET) 55 | $(TESTTARGET) 56 | 57 | $(TESTTARGET): $(TESTOBJECTS) 58 | @echo ""; echo "Linking..." 59 | $(CXX) $^ $(filter-out $(BUILDDIR)/orq.o,$(OBJECTS)) -o $(TESTTARGET) $(LDFLAGS) 60 | 61 | $(BUILDDIR)/$(TESTDIR)/%.o: $(TESTDIR)/%.$(SRCEXT) 62 | @mkdir -p $(dir $@) 63 | $(CXX) $(CXXFLAGS) $(INC) -c -o $@ $< 64 | 65 | gcov: 66 | ifeq ($(CXX),g++) 67 | gcov: CXXFLAGS += -g -O0 --coverage 68 | gcov: LDFLAGS += -lgcov 69 | gcov: clean test 70 | else ifeq ($(CC),gcc) 71 | gcov: CFLAGS += -g -O0 --coverage 72 | gcov: LDFLAGS += -lgcov 73 | gcov: clean test 74 | endif 75 | 76 | .PHONY: clean style astyle cpplint 77 | 78 | style: astyle cpplint 79 | 80 | astyle: 81 | @astyle --options=.astylerc $(ASTYLE_FLAGS) $(SOURCES) $(HEADERS) $(TESTSOURCES) 82 | 83 | cpplint: 84 | @cpplint $(CPPLINT_EXTRA) \ 85 | --filter=-whitespace/indent,-whitespace/line_length,-whitespace/braces,-runtime/int,-whitespace/labels\ 86 | $(SOURCES) $(HEADERS) $(TESTSOURCES) 2>&1 | \ 87 | awk '!/^Done processing .*(cpp|h)/ { print $$0 }; \ 88 | /Total errors / { gsub ("^[[:alpha:] ]+: ", ""); err=$$0} \ 89 | END { exit err; }' 90 | 91 | clean: 92 | @echo " Cleaning..."; 93 | $(RM) -r $(BUILDDIR) $(TARGET) $(TESTTARGET) 94 | 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | orq 2 | === 3 | 4 | [![Build Status](https://travis-ci.org/olanmatt/orq.svg?branch=master)](https://travis-ci.org/olanmatt/orq) 5 | [![Coverage Status](https://img.shields.io/coveralls/olanmatt/orq.svg)](https://coveralls.io/r/olanmatt/orq) 6 | 7 | An Open-Source [RFC 6330](https://tools.ietf.org/html/rfc6330) Implementation in C++, based off the work by the [OpenRQ Team](https://github.com/openrq-team/OpenRQ). 8 | 9 | Currently under heavy active development, with a stable first release planned [by Christmas](http://www.perlfoundation.org/perl6/index.cgi?faq). 10 | -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /include/matrix_utilities.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_MATRIX_UTILITIES_H_ 26 | #define INCLUDE_MATRIX_UTILITIES_H_ 27 | 28 | class matrix_utilities 29 | { 30 | public: 31 | static long ceil_prime(long p); 32 | static bool is_prime(long n); 33 | }; 34 | 35 | #endif // INCLUDE_MATRIX_UTILITIES_H_ 36 | -------------------------------------------------------------------------------- /include/parameters/fec_parameters.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_PARAMETERS_FEC_PARAMETERS_H_ 26 | #define INCLUDE_PARAMETERS_FEC_PARAMETERS_H_ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | class fec_parameters 35 | { 36 | public: 37 | static fec_parameters new_parameters(uint64_t data_len, uint16_t symbol_size, 38 | uint8_t num_source_blocks); 39 | 40 | static fec_parameters new_parameters(uint64_t data_len, uint16_t symbol_size, 41 | uint8_t num_source_blocks, uint16_t inter_len); 42 | 43 | static fec_parameters derive_parameters(uint64_t data_len, uint16_t pay_len, 44 | uint64_t max_db_mem); 45 | static fec_parameters new_local_instance(uint64_t F, uint16_t T, uint8_t Z, 46 | uint16_t N, uint8_t Al); 47 | 48 | uint64_t data_length(); 49 | uint16_t symbol_size(); 50 | uint8_t num_source_blocks(); 51 | uint16_t interleaver_length(); 52 | uint8_t symbol_alignment(); 53 | uint16_t total_symbols(); 54 | 55 | private: 56 | static uint8_t derive_Z(uint16_t Kt, uint64_t WS, uint16_t T, uint8_t Al, 57 | uint16_t topN); 58 | 59 | static int derive_N(uint16_t Kt, uint8_t Z, uint64_t WS, uint16_t T, uint8_t Al, 60 | uint16_t topN); 61 | 62 | fec_parameters(uint64_t common_fec_oti, uint32_t scheme_spec_fec_oti); 63 | uint64_t common_fec_oti_; 64 | uint32_t scheme_spec_fec_oti_; 65 | }; 66 | 67 | #endif // INCLUDE_PARAMETERS_FEC_PARAMETERS_H_ 68 | -------------------------------------------------------------------------------- /include/parameters/internal_constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_PARAMETERS_INTERNAL_CONSTANTS_H_ 26 | #define INCLUDE_PARAMETERS_INTERNAL_CONSTANTS_H_ 27 | 28 | #include 29 | 30 | namespace internal_constants 31 | { 32 | static const uint8_t Al = 1; 33 | // "maximum number of symbols in each source block" 34 | static const uint16_t K_max = 56403; 35 | // "maximum number of source blocks" 36 | static const uint16_t Z_max = 256; 37 | // static const int Kt_max = K_max * Z_max; 38 | // "maximum number of symbols" 39 | static const uint32_t Kt_max = 14439168; 40 | // static const int T_max = (65535 / Al) * Al; 41 | // "maximum symbol size, in octets" 42 | static const uint16_t T_max = 65535; 43 | // static const uint64_t F_max = Kt_max * T_max; 44 | // "maximum transfer length of the object, in octets" 45 | static const uint64_t F_max = 946270874880LLU; 46 | // "maximum interleaver length, in number of sub-blocks" 47 | static const uint16_t N_max = 1 /* K_max */; 48 | // TODO(olanmatt): Enable interleaving. 49 | 50 | static const uint16_t K_min = 1; 51 | // the first K' value in the systematic indices table 52 | static const uint16_t K_prime_min = 10; 53 | static const uint16_t Z_min = 1; 54 | static const uint8_t T_min = Al; 55 | // RFC 6330 defines F as a non-negative value, but we force a positive value here 56 | static const uint64_t F_min = 1; 57 | static const uint16_t N_min = 1; 58 | 59 | static const uint8_t SBN_max = 255; 60 | static const uint32_t ESI_max = 16777215; 61 | 62 | static const uint8_t SBN_min = 0; 63 | static const uint32_t ESI_min = 0; 64 | 65 | // TODO(olanmatt): Convert to stdint.h. 66 | static const int F_num_bytes = 5; 67 | static const int ESI_num_bytes = 3; 68 | 69 | // third octet is reserved bits 70 | static const uint64_t common_oti_reserved_inverse_mask = 0xFFFFFFFFFF00FFFF; 71 | } // namespace internal_constants 72 | 73 | #endif // INCLUDE_PARAMETERS_INTERNAL_CONSTANTS_H_ 74 | -------------------------------------------------------------------------------- /include/parameters/internal_functions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_PARAMETERS_INTERNAL_FUNCTIONS_H_ 26 | #define INCLUDE_PARAMETERS_INTERNAL_FUNCTIONS_H_ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | class internal_functions 35 | { 36 | public: 37 | static uint64_t get_possible_total_symbols(uint64_t F, uint16_t T); 38 | static uint64_t get_total_symbols(uint64_t F, uint16_t T); 39 | static uint16_t top_interleaver_length(uint16_t T); 40 | static uint16_t KL(uint64_t WS, uint16_t T, uint8_t Al, uint16_t n); 41 | static uint64_t min_WS(uint16_t Kprime, uint16_t T, uint8_t Al, uint16_t n); 42 | 43 | private: 44 | static uint16_t sub_symbol_size(uint16_t T, uint8_t Al, uint16_t n); 45 | }; 46 | 47 | #endif // INCLUDE_PARAMETERS_INTERNAL_FUNCTIONS_H_ 48 | -------------------------------------------------------------------------------- /include/parameters/parameter_checker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_PARAMETERS_PARAMETER_CHECKER_H_ 26 | #define INCLUDE_PARAMETERS_PARAMETER_CHECKER_H_ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | class parameter_checker 34 | { 35 | public: 36 | static bool is_data_length_out_of_bounds(uint64_t dataLen); 37 | static uint64_t max_allowed_data_length(uint16_t symbSize); 38 | static bool is_symbol_size_out_of_bounds(uint16_t symbSize); 39 | static uint16_t min_allowed_symbol_size(uint64_t dataLen); 40 | static bool is_num_source_blocks_out_of_bounds(uint8_t numSrcBs); 41 | static uint8_t min_allowed_num_source_blocks(uint64_t dataLen, 42 | uint16_t symbSize); 43 | static uint8_t max_allowed_num_source_blocks(uint64_t dataLen, 44 | uint16_t symbSize); 45 | static bool is_interleaver_length_out_of_bounds(uint16_t interLen); 46 | static uint16_t max_allowed_interleaver_length(uint16_t symbSize); 47 | static bool are_valid_fec_parameters(uint64_t dataLen, uint16_t symbSize, 48 | uint8_t numSrcBs, uint16_t interLen); 49 | static bool is_payload_length_out_of_bounds(uint16_t payLen); 50 | static uint16_t min_allowed_payload_length(uint64_t dataLen); 51 | static uint64_t min_decoding_block_size(); 52 | static uint64_t min_allowed_decoding_block_size(uint64_t dataLen, 53 | uint16_t payLen); 54 | static uint64_t max_allowed_data_length(uint16_t payLen, uint64_t maxDBMem); 55 | static bool are_valid_deriver_parameters(uint64_t dataLen, uint16_t payLen, 56 | uint64_t maxDBMem); 57 | static bool is_source_block_number_out_of_bounds(uint8_t sbn); 58 | static bool is_encoding_symbol_id_out_of_bounds(uint32_t esi); 59 | static bool is_valid_fec_payload_id(uint8_t sbn, uint32_t esi, 60 | uint8_t numSrcBs); 61 | static bool is_num_source_symbols_per_block_out_of_bounds(uint16_t numSrcSymbs); 62 | static uint32_t num_repair_symbols_per_block(uint16_t numSrcSymbs); 63 | 64 | private: 65 | static uint64_t _max_allowed_data_length(uint16_t T); 66 | static uint16_t _min_allowed_symbol_size(uint64_t F); 67 | static uint16_t _min_allowed_num_source_blocks(uint16_t Kt); 68 | static uint16_t _max_allowed_num_source_blocks(uint16_t Kt); 69 | static uint16_t _max_allowed_interleaver_length(uint16_t T); 70 | static uint64_t _min_allowed_decoding_block_size(uint64_t F, uint16_t T); 71 | static uint64_t _max_allowed_data_length(uint16_t T, uint64_t WS); 72 | static bool _are_data_length_and_symbol_size_out_of_bounds(uint64_t F, 73 | uint16_t T); 74 | static bool _are_data_length_and_payload_length_out_of_bounds(uint64_t F, 75 | uint16_t P); 76 | static void _check_data_length_out_of_bounds(uint64_t F); 77 | static void _check_symbol_size_out_of_bounds(uint16_t T); 78 | static void _check_data_length_and_symbol_size_out_of_bounds(uint64_t F, 79 | uint16_t T); 80 | static void _check_num_source_blocks_out_of_bounds(uint8_t Z); 81 | static void _check_payload_length_out_of_bounds(uint16_t P); 82 | static void _check_data_length_and_payload_length_out_of_bounds(uint64_t F, 83 | uint16_t P); 84 | static void _check_decoding_block_size_out_of_bounds(uint64_t WS); 85 | static void _check_num_source_symbols_per_block_out_of_bounds(uint16_t K); 86 | }; 87 | 88 | #endif // INCLUDE_PARAMETERS_PARAMETER_CHECKER_H_ 89 | -------------------------------------------------------------------------------- /include/parameters/parameter_io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_PARAMETERS_PARAMETER_IO_H_ 26 | #define INCLUDE_PARAMETERS_PARAMETER_IO_H_ 27 | 28 | #include 29 | #include 30 | 31 | class parameter_io 32 | { 33 | public: 34 | static uint64_t extract_data_length(uint64_t commonFecOTI); 35 | static uint16_t extract_symbol_size(uint64_t commonFecOTI); 36 | static uint8_t extract_num_source_blocks(uint32_t schemeSpecFecOTI); 37 | static uint16_t extract_interleaver_length(uint32_t schemeSpecFecOTI); 38 | static uint8_t extract_symbol_alignment(uint32_t schemeSpecFecOTI); 39 | static uint8_t extract_source_block_number(uint32_t fecPayloadID); 40 | static uint32_t extract_encoding_symbol_id(uint32_t fecPayloadID); 41 | static uint64_t build_common_fec_oti(uint64_t dataLen, uint16_t symbolSize); 42 | static uint64_t canonicalize_common_fec_oti(uint64_t commonFecOTI); 43 | static uint32_t build_scheme_spec_fec_oti(uint8_t numSrcBs, uint16_t interLen, 44 | uint8_t sAlign); 45 | static uint32_t build_fec_payload_id(uint8_t sbn, uint32_t esi); 46 | 47 | private: 48 | static int data_length_shift(); 49 | static int num_source_blocks_shift(); 50 | static int interleaver_length_shift(); 51 | static int source_block_number_shift(); 52 | }; 53 | 54 | #endif // INCLUDE_PARAMETERS_PARAMETER_IO_H_ 55 | -------------------------------------------------------------------------------- /include/parsed.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan, Prajjwal Bhandari 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_PARSED_H_ 26 | #define INCLUDE_PARSED_H_ 27 | 28 | #include 29 | #include 30 | 31 | template 32 | class Parsed 33 | { 34 | public: 35 | static Parsed &of(V value); 36 | static Parsed &invalid(std::string failureReason); 37 | 38 | virtual bool is_valid() = 0; 39 | virtual V value() = 0; 40 | virtual std::string failure_reason() = 0; 41 | 42 | protected: 43 | Parsed() { } 44 | 45 | private: 46 | class ParsedValue; 47 | 48 | class InvalidValue; 49 | }; 50 | 51 | /* I get link error when using any of these functions unless they're fully 52 | * defined in the file that is to be included. So I'm doing just that until I 53 | * can find a better solution */ 54 | 55 | template 56 | Parsed &Parsed::of(V value) 57 | { 58 | return *(new ParsedValue(value)); 59 | } 60 | 61 | template 62 | Parsed &Parsed::invalid(std::string reason) 63 | { 64 | return *(new InvalidValue(reason)); 65 | } 66 | 67 | template 68 | class Parsed::ParsedValue : public Parsed 69 | { 70 | public: 71 | ParsedValue(const V &value) : Parsed() 72 | { 73 | value_ = value; 74 | } 75 | ~ParsedValue(void) 76 | { 77 | delete value_; 78 | } 79 | 80 | bool is_valid() 81 | { 82 | return true; 83 | } 84 | V value() 85 | { 86 | return this->value_; 87 | } 88 | std::string failure_reason() 89 | { 90 | return ""; 91 | } 92 | 93 | private: 94 | V value_; 95 | }; 96 | 97 | template 98 | class Parsed::InvalidValue : public Parsed 99 | { 100 | public: 101 | InvalidValue(const std::string &reason) : Parsed() 102 | { 103 | reason_ = reason; 104 | } 105 | ~InvalidValue(void) 106 | { 107 | delete reason_; 108 | } 109 | 110 | bool is_valid(void) 111 | { 112 | return false; 113 | } 114 | V value(void) 115 | { 116 | throw failure_reason(); 117 | } 118 | std::string failure_reason(void) 119 | { 120 | return this->reason_; 121 | } 122 | 123 | private: 124 | std::string reason_; 125 | }; 126 | 127 | #endif // INCLUDE_PARSED_H_ 128 | -------------------------------------------------------------------------------- /include/partition.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_PARTITION_H_ 26 | #define INCLUDE_PARTITION_H_ 27 | 28 | class partition 29 | { 30 | public: 31 | partition(unsigned int I, unsigned int J); 32 | int IL(); 33 | int IS(); 34 | int JL(); 35 | int JS(); 36 | 37 | private: 38 | int m_IL; 39 | int m_IS; 40 | int m_JL; 41 | int m_JS; 42 | }; 43 | 44 | #endif // INCLUDE_PARTITION_H_ 45 | -------------------------------------------------------------------------------- /include/row.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_ROW_H_ 26 | #define INCLUDE_ROW_H_ 27 | 28 | #include 29 | 30 | class row 31 | { 32 | public: 33 | row(int i, int r, int d, bool hdpc); 34 | row(int i, int r, int d, bool hdpc, std::set e); 35 | bool operator==(const row &other); 36 | 37 | private: 38 | int m_position; 39 | int m_non_zeros; 40 | int m_original_degree; 41 | std::set m_nodes; 42 | bool m_is_hdpc; 43 | }; 44 | 45 | #endif // INCLUDE_ROW_H_ 46 | -------------------------------------------------------------------------------- /include/symbol.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2014 Matt Olan, Prajjwal Bhandari 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | 26 | #ifndef INCLUDE_SYMBOL_H_ 27 | #define INCLUDE_SYMBOL_H_ 28 | 29 | 30 | namespace Symbol 31 | { 32 | enum TYPE { 33 | /* Value indicating a source symbol. */ 34 | SOURCE, 35 | 36 | /* Value indicating a repair symbol. */ 37 | REPAIR, 38 | }; 39 | } // namespace Symbol 40 | 41 | #endif // INCLUDE_SYMBOL_H_ 42 | -------------------------------------------------------------------------------- /include/tuple.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_TUPLE_H_ 26 | #define INCLUDE_TUPLE_H_ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | class tuple 34 | { 35 | public: 36 | tuple(int k_prime, long x); 37 | long D(); 38 | long A(); 39 | long B(); 40 | long D1(); 41 | long A1(); 42 | long B1(); 43 | 44 | private: 45 | long m_d, m_a, m_b, m_d1, m_a1, m_b1; 46 | }; 47 | 48 | #endif // INCLUDE_TUPLE_H_ 49 | -------------------------------------------------------------------------------- /include/util/deg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_UTIL_DEG_H_ 26 | #define INCLUDE_UTIL_DEG_H_ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | class deg 33 | { 34 | public: 35 | static int generate(unsigned int v, int W); 36 | 37 | private: 38 | static const unsigned int m_table1[]; 39 | deg() { } // Otherwise default constructor is generated 40 | }; 41 | 42 | #endif // INCLUDE_UTIL_DEG_H_ 43 | -------------------------------------------------------------------------------- /include/util/extra_math.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_UTIL_EXTRA_MATH_H_ 26 | #define INCLUDE_UTIL_EXTRA_MATH_H_ 27 | 28 | class extra_math 29 | { 30 | public: 31 | static int ceil_div(int num, int den); 32 | }; 33 | 34 | #endif // INCLUDE_UTIL_EXTRA_MATH_H_ 35 | -------------------------------------------------------------------------------- /include/util/octet_ops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_UTIL_OCTET_OPS_H_ 26 | #define INCLUDE_UTIL_OCTET_OPS_H_ 27 | 28 | #include 29 | #include 30 | 31 | class octet_ops 32 | { 33 | public: 34 | static uint8_t get_exp(int i); 35 | static uint8_t get_log(int i); 36 | static uint8_t addition(uint8_t u, uint8_t v); 37 | static uint8_t subtraction(uint8_t u, uint8_t v); 38 | static uint8_t product(uint8_t u, uint8_t v); 39 | static uint8_t division(uint8_t u, uint8_t v); 40 | static uint8_t alpha_power(int i); 41 | static void beta_product(uint8_t beta, uint8_t U[]); 42 | static void beta_division(uint8_t U[], uint8_t beta); 43 | static void beta_product(uint8_t beta, uint8_t U[], int pos, int length); 44 | static void beta_division(uint8_t U[], uint8_t beta, int pos, int length); 45 | 46 | private: 47 | static const int m_OCT_EXP[]; 48 | static const int m_OCT_LOG[]; 49 | }; 50 | 51 | #endif // INCLUDE_UTIL_OCTET_OPS_H_ 52 | -------------------------------------------------------------------------------- /include/util/rand.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_UTIL_RAND_H_ 26 | #define INCLUDE_UTIL_RAND_H_ 27 | 28 | #include 29 | #include 30 | 31 | class rand 32 | { 33 | public: 34 | static int generate(uint32_t y, uint8_t i, uint32_t m); 35 | 36 | private: 37 | static const uint32_t m_V0[]; 38 | static const uint32_t m_V1[]; 39 | static const uint32_t m_V2[]; 40 | static const uint32_t m_V3[]; 41 | }; 42 | 43 | #endif // INCLUDE_UTIL_RAND_H_ 44 | -------------------------------------------------------------------------------- /include/util/systematic_indices.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef INCLUDE_UTIL_SYSTEMATIC_INDICES_H_ 26 | #define INCLUDE_UTIL_SYSTEMATIC_INDICES_H_ 27 | 28 | #include 29 | 30 | class systematic_indices 31 | { 32 | public: 33 | static unsigned int get_k_index(unsigned int k_prime); 34 | static unsigned int K(unsigned int k_index); 35 | static unsigned int J(unsigned int k_index); 36 | static unsigned int S(unsigned int k_index); 37 | static unsigned int H(unsigned int k_index); 38 | static unsigned int W(unsigned int k_index); 39 | static int ceil(unsigned int k_prime); 40 | static int floor(unsigned int k_prime); 41 | 42 | private: 43 | static const unsigned int m_table2[][5]; 44 | }; 45 | 46 | #endif // INCLUDE_UTIL_SYSTEMATIC_INDICES_H_ 47 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /src/matrix_utilities.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | // TODO(olanmatt): Replace with a lookup table. 28 | long matrix_utilities::ceil_prime(long p) 29 | { 30 | if (p == 1) { 31 | p++; 32 | } 33 | 34 | while (!is_prime(p)) { 35 | p++; 36 | } 37 | 38 | return p; 39 | } 40 | 41 | bool matrix_utilities::is_prime(long n) 42 | { 43 | if ((n & 1) == 0) { 44 | return false; 45 | } 46 | 47 | for (long i = 3; i * i <= n; i += 2) { 48 | if (n % i == 0) { 49 | return false; 50 | } 51 | } 52 | 53 | return true; 54 | } 55 | -------------------------------------------------------------------------------- /src/orq.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | // Suppressing compile errors until main class is written 26 | int main() 27 | { 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/parameters/fec_parameters.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | fec_parameters 28 | fec_parameters::new_parameters(uint64_t data_length, 29 | uint16_t symbol_size, 30 | uint8_t num_source_blocks) 31 | { 32 | return new_parameters(data_length, symbol_size, num_source_blocks, 1); 33 | } 34 | 35 | fec_parameters 36 | fec_parameters::new_parameters(uint64_t data_length, 37 | uint16_t symbol_size, 38 | uint8_t num_source_blocks, 39 | uint16_t interleaver_length) 40 | { 41 | uint64_t F = data_length; 42 | uint16_t T = symbol_size; 43 | uint8_t Z = num_source_blocks; 44 | uint16_t N = interleaver_length; 45 | uint8_t Al = internal_constants::Al; 46 | 47 | if (parameter_checker::are_valid_fec_parameters(F, T, Z, N)) { 48 | return new_local_instance(F, T, Z, N, Al); 49 | } else { 50 | // TODO(olanmatt): Add more exception specificity. 51 | throw std::invalid_argument("invalid FECParameter argument"); 52 | } 53 | } 54 | 55 | fec_parameters 56 | fec_parameters::derive_parameters(uint64_t data_length, 57 | uint16_t payload_length, 58 | uint64_t max_db_mem) 59 | { 60 | uint64_t F = data_length; 61 | uint16_t P = payload_length; 62 | uint64_t WS = max_db_mem; 63 | uint8_t Al = internal_constants::Al; 64 | 65 | if (parameter_checker::are_valid_deriver_parameters(F, P, WS)) { 66 | uint16_t T = P; 67 | 68 | uint16_t Kt = internal_functions::get_total_symbols(F, T); 69 | uint16_t topN = internal_functions::top_interleaver_length(T); 70 | 71 | uint8_t Z = derive_Z(Kt, WS, T, Al, topN); 72 | uint16_t N = derive_N(Kt, Z, WS, T, Al, topN); 73 | 74 | return new_local_instance(F, T, Z, N, Al); 75 | } else { 76 | // TODO(olanmatt): Add more exception specificity. 77 | throw std::invalid_argument("invalid FECParameter argument"); 78 | } 79 | } 80 | 81 | uint8_t 82 | fec_parameters::derive_Z(uint16_t Kt, 83 | uint64_t WS, 84 | uint16_t T, 85 | uint8_t Al, 86 | uint16_t topN) 87 | { 88 | int Kl = internal_functions::KL(WS, T, Al, topN); 89 | return extra_math::ceil_div(Kt, Kl); // Z = ceil(Kt/KL(N_max)) 90 | } 91 | 92 | int 93 | fec_parameters::derive_N(uint16_t Kt, 94 | uint8_t Z, 95 | uint64_t WS, 96 | uint16_t T, 97 | uint8_t Al, 98 | uint16_t topN) 99 | { 100 | // N is the minimum n=1, ..., N_max such that ceil(Kt/Z) <= KL(n) 101 | int topK = extra_math::ceil_div(Kt, Z); 102 | for (int n = topN; n >= 1; n--) { 103 | if (topK <= internal_functions::KL(WS, T, Al, n)) { 104 | return n; 105 | } 106 | } 107 | 108 | throw std::runtime_error("must never be thrown"); 109 | } 110 | 111 | fec_parameters 112 | fec_parameters::new_local_instance(uint64_t F, 113 | uint16_t T, 114 | uint8_t Z, 115 | uint16_t N, 116 | uint8_t Al) 117 | { 118 | uint64_t common_fec_oti = parameter_io::build_common_fec_oti(F, T); 119 | uint32_t scheme_spec_fec_oti = parameter_io::build_scheme_spec_fec_oti(Z, N, 120 | Al); 121 | return fec_parameters(common_fec_oti, scheme_spec_fec_oti); 122 | } 123 | 124 | fec_parameters::fec_parameters(uint64_t common_fec_oti, 125 | uint32_t scheme_spec_fec_oti) 126 | { 127 | common_fec_oti_ = common_fec_oti; 128 | scheme_spec_fec_oti_ = scheme_spec_fec_oti; 129 | } 130 | 131 | uint64_t 132 | fec_parameters::data_length(void) 133 | { 134 | return parameter_io::extract_data_length(common_fec_oti_); 135 | } 136 | 137 | uint16_t 138 | fec_parameters::symbol_size(void) 139 | { 140 | return parameter_io::extract_symbol_size(common_fec_oti_); 141 | } 142 | 143 | uint8_t 144 | fec_parameters::num_source_blocks(void) 145 | { 146 | return parameter_io::extract_num_source_blocks(scheme_spec_fec_oti_); 147 | } 148 | 149 | uint16_t 150 | fec_parameters::interleaver_length(void) 151 | { 152 | return parameter_io::extract_interleaver_length(scheme_spec_fec_oti_); 153 | } 154 | 155 | uint8_t 156 | fec_parameters::symbol_alignment(void) 157 | { 158 | return parameter_io::extract_symbol_alignment(scheme_spec_fec_oti_); 159 | } 160 | 161 | uint16_t 162 | fec_parameters::total_symbols(void) 163 | { 164 | return internal_functions::get_total_symbols(data_length(), symbol_size()); 165 | } 166 | -------------------------------------------------------------------------------- /src/parameters/internal_functions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | uint64_t internal_functions::get_possible_total_symbols(uint64_t F, uint16_t T) 29 | { 30 | return extra_math::ceil_div(F, T); 31 | } 32 | 33 | uint64_t 34 | internal_functions::get_total_symbols(uint64_t F, uint16_t T) 35 | { 36 | return (uint64_t)extra_math::ceil_div(F, 37 | T); // downcast never overflows since F and T are bounded 38 | } 39 | 40 | uint16_t 41 | internal_functions::top_interleaver_length(uint16_t T) 42 | { 43 | uint16_t SStimesAl = T; 44 | return T / SStimesAl; 45 | } 46 | 47 | uint16_t 48 | internal_functions::KL(uint64_t WS, uint16_t T, uint8_t Al, uint16_t n) 49 | { 50 | uint16_t K_upper_bound = (uint16_t)std::min((uint16_t)internal_constants::K_max, 51 | (uint16_t)(WS / sub_symbol_size(T, Al, n))); 52 | return systematic_indices::floor(K_upper_bound); 53 | } 54 | 55 | uint64_t 56 | internal_functions::min_WS(uint16_t K_prime, uint16_t T, uint8_t Al, uint16_t n) 57 | { 58 | return (uint64_t)systematic_indices::ceil(K_prime) * sub_symbol_size(T, Al, n); 59 | } 60 | 61 | uint16_t 62 | internal_functions::sub_symbol_size(uint16_t T, uint8_t Al, uint16_t n) 63 | { 64 | return Al * extra_math::ceil_div(T, Al * n); 65 | } 66 | -------------------------------------------------------------------------------- /src/parameters/parameter_checker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | bool parameter_checker::is_data_length_out_of_bounds(uint64_t dataLen) 29 | { 30 | return !(internal_constants::F_min <= dataLen 31 | && dataLen <= internal_constants::F_max); 32 | } 33 | 34 | uint64_t parameter_checker::max_allowed_data_length(uint16_t symbSize) 35 | { 36 | _check_symbol_size_out_of_bounds(symbSize); 37 | return _max_allowed_data_length(symbSize); 38 | } 39 | 40 | bool parameter_checker::is_symbol_size_out_of_bounds(uint16_t symbSize) 41 | { 42 | return !(internal_constants::T_min <= symbSize 43 | && symbSize <= internal_constants::T_max); 44 | } 45 | 46 | uint16_t parameter_checker::min_allowed_symbol_size(uint64_t dataLen) 47 | { 48 | _check_data_length_out_of_bounds(dataLen); 49 | return _min_allowed_symbol_size(dataLen); 50 | } 51 | 52 | bool parameter_checker::is_num_source_blocks_out_of_bounds(uint8_t numSrcBs) 53 | { 54 | // TODO(olanmatt): Verify overflow control that throws warning. 55 | return !(internal_constants::Z_min <= 56 | numSrcBs); // && numSrcBs <= internal_constants::Z_max); 57 | } 58 | 59 | uint8_t parameter_checker::min_allowed_num_source_blocks(uint64_t dataLen, 60 | uint16_t symbSize) 61 | { 62 | _check_data_length_out_of_bounds(dataLen); 63 | _check_symbol_size_out_of_bounds(symbSize); 64 | _check_data_length_and_symbol_size_out_of_bounds(dataLen, symbSize); 65 | 66 | uint32_t Kt = internal_functions::get_total_symbols(dataLen, symbSize); 67 | return _min_allowed_num_source_blocks(Kt); 68 | } 69 | 70 | uint8_t parameter_checker::max_allowed_num_source_blocks(uint64_t dataLen, 71 | uint16_t symbSize) 72 | { 73 | _check_data_length_out_of_bounds(dataLen); 74 | _check_symbol_size_out_of_bounds(symbSize); 75 | _check_data_length_and_symbol_size_out_of_bounds(dataLen, symbSize); 76 | 77 | uint16_t Kt = internal_functions::get_total_symbols(dataLen, symbSize); 78 | return _max_allowed_num_source_blocks(Kt); 79 | } 80 | 81 | bool parameter_checker::is_interleaver_length_out_of_bounds(uint16_t interLen) 82 | { 83 | return !(internal_constants::N_min <= interLen 84 | && interLen <= internal_constants::N_max); 85 | } 86 | 87 | uint16_t parameter_checker::max_allowed_interleaver_length(uint16_t symbSize) 88 | { 89 | _check_symbol_size_out_of_bounds(symbSize); 90 | return _max_allowed_interleaver_length(symbSize); 91 | } 92 | 93 | bool parameter_checker::are_valid_fec_parameters(uint64_t dataLen, 94 | uint16_t symbSize, uint8_t numSrcBs, uint16_t interLen) 95 | { 96 | uint64_t F = dataLen; 97 | uint16_t T = symbSize; 98 | uint8_t Z = numSrcBs; 99 | uint16_t N = interLen; 100 | 101 | if (is_data_length_out_of_bounds(F)) { 102 | return false; 103 | } 104 | if (is_symbol_size_out_of_bounds(T)) { 105 | return false; 106 | } 107 | if (is_num_source_blocks_out_of_bounds(Z)) { 108 | return false; 109 | } 110 | if (is_interleaver_length_out_of_bounds(N)) { 111 | return false; 112 | } 113 | 114 | if (_are_data_length_and_symbol_size_out_of_bounds(F, T)) { 115 | return false; 116 | } 117 | 118 | int Kt = internal_functions::get_total_symbols(F, T); 119 | int minAllowedZ = _min_allowed_num_source_blocks(Kt); 120 | int maxAllowedZ = _max_allowed_num_source_blocks(Kt); 121 | 122 | if (Z < minAllowedZ || Z > maxAllowedZ) { 123 | return false; 124 | } 125 | 126 | int maxAllowedN = _max_allowed_interleaver_length(T); 127 | 128 | if (N > maxAllowedN) { 129 | return false; 130 | } 131 | 132 | return true; 133 | } 134 | 135 | bool parameter_checker::is_payload_length_out_of_bounds(uint16_t payLen) 136 | { 137 | return !(internal_constants::T_min <= payLen 138 | && payLen <= internal_constants::T_max); 139 | } 140 | 141 | uint16_t parameter_checker::min_allowed_payload_length(uint64_t dataLen) 142 | { 143 | return min_allowed_symbol_size(dataLen); 144 | } 145 | 146 | uint64_t parameter_checker::min_decoding_block_size() 147 | { 148 | return _min_allowed_decoding_block_size(internal_constants::F_min, 149 | internal_constants::T_min); 150 | } 151 | 152 | uint64_t parameter_checker::min_allowed_decoding_block_size(uint64_t dataLen, 153 | uint16_t payLen) 154 | { 155 | _check_data_length_out_of_bounds(dataLen); 156 | _check_payload_length_out_of_bounds(payLen); 157 | _check_data_length_and_payload_length_out_of_bounds(dataLen, payLen); 158 | 159 | return _min_allowed_decoding_block_size(dataLen, payLen); 160 | } 161 | 162 | uint64_t parameter_checker::max_allowed_data_length(uint16_t payLen, 163 | uint64_t maxDBMem) 164 | { 165 | _check_payload_length_out_of_bounds(payLen); 166 | _check_decoding_block_size_out_of_bounds(maxDBMem); 167 | if (maxDBMem < payLen) { 168 | throw std::invalid_argument("maximum decoding block size must be at least equal to the payload length"); 169 | } 170 | 171 | return _max_allowed_data_length(payLen, maxDBMem); 172 | } 173 | 174 | bool parameter_checker::are_valid_deriver_parameters(uint64_t dataLen, 175 | uint16_t payLen, uint64_t maxDBMem) 176 | { 177 | long F = dataLen; 178 | int T = payLen; 179 | long WS = maxDBMem; 180 | 181 | if (is_data_length_out_of_bounds(F)) { 182 | return false; 183 | } 184 | if (is_symbol_size_out_of_bounds(T)) { 185 | return false; 186 | } 187 | 188 | long absolMinWS = min_decoding_block_size(); 189 | if (WS < absolMinWS) { 190 | return false; 191 | } 192 | 193 | int minT = _min_allowed_symbol_size(F); 194 | if (T < minT) { 195 | return false; 196 | } 197 | 198 | long minWS = _min_allowed_decoding_block_size(F, T); 199 | if (WS < minWS) { 200 | return false; 201 | } 202 | 203 | return true; 204 | } 205 | 206 | bool parameter_checker::is_source_block_number_out_of_bounds(uint8_t sbn) 207 | { 208 | return !(internal_constants::SBN_min <= sbn 209 | && sbn <= internal_constants::SBN_max); 210 | } 211 | 212 | bool parameter_checker::is_encoding_symbol_id_out_of_bounds(uint32_t esi) 213 | { 214 | // TODO(olanmatt): Verify overflow control that throws warning. 215 | return !(esi <= 216 | internal_constants::ESI_max); // && internal_constants::ESI_min <= esi 217 | } 218 | 219 | bool parameter_checker::is_valid_fec_payload_id(uint8_t sbn, uint32_t esi, 220 | uint8_t numSrcBs) 221 | { 222 | _check_num_source_blocks_out_of_bounds(numSrcBs); 223 | 224 | if (sbn < internal_constants::SBN_min || sbn >= numSrcBs) { 225 | return false; 226 | } 227 | if (is_encoding_symbol_id_out_of_bounds(esi)) { 228 | return false; 229 | } 230 | 231 | return true; 232 | } 233 | 234 | bool parameter_checker::is_num_source_symbols_per_block_out_of_bounds( 235 | uint16_t numSrcSymbs) 236 | { 237 | return !(internal_constants::K_min <= numSrcSymbs 238 | && numSrcSymbs <= internal_constants::K_max); 239 | } 240 | 241 | uint32_t parameter_checker::num_repair_symbols_per_block(uint16_t numSrcSymbs) 242 | { 243 | _check_num_source_symbols_per_block_out_of_bounds(numSrcSymbs); 244 | 245 | int minESI = internal_constants::ESI_min; 246 | int maxESI = internal_constants::ESI_max; 247 | int totalSymbs = 1 + maxESI - minESI; 248 | 249 | return totalSymbs - numSrcSymbs; 250 | } 251 | 252 | uint64_t parameter_checker::_max_allowed_data_length(uint16_t T) 253 | { 254 | return std::min(internal_constants::F_max, 255 | (uint64_t)(T * internal_constants::Kt_max)); 256 | } 257 | 258 | uint16_t parameter_checker::_min_allowed_symbol_size(uint64_t F) 259 | { 260 | return std::max((uint16_t)internal_constants::T_min, 261 | (uint16_t)(extra_math::ceil_div(F, internal_constants::Kt_max))); 262 | } 263 | 264 | uint16_t parameter_checker::_min_allowed_num_source_blocks(uint16_t Kt) 265 | { 266 | return std::max(internal_constants::Z_min, (uint16_t)extra_math::ceil_div(Kt, 267 | internal_constants::K_max)); 268 | } 269 | 270 | uint16_t parameter_checker::_max_allowed_num_source_blocks(uint16_t Kt) 271 | { 272 | return std::min(internal_constants::Z_max, Kt); 273 | } 274 | 275 | uint16_t parameter_checker::_max_allowed_interleaver_length(uint16_t T) 276 | { 277 | return std::min(internal_constants::N_max, 278 | (uint16_t)(T / internal_constants::Al)); 279 | } 280 | 281 | uint64_t parameter_checker::_min_allowed_decoding_block_size(uint64_t F, 282 | uint16_t T) 283 | { 284 | int Kt = internal_functions::get_total_symbols(F, T); 285 | 286 | int Kprime = std::max((uint16_t)internal_constants::K_prime_min, 287 | (uint16_t)extra_math::ceil_div(Kt, internal_constants::Z_max)); 288 | 289 | return internal_functions::min_WS(Kprime, T, internal_constants::Al, 290 | internal_functions::top_interleaver_length(T)); 291 | } 292 | 293 | uint64_t parameter_checker::_max_allowed_data_length(uint16_t T, uint64_t WS) 294 | { 295 | long boundFromT = _max_allowed_data_length(T); 296 | 297 | int KL = internal_functions::KL(WS, T, internal_constants::Al, 298 | internal_functions::top_interleaver_length(T)); 299 | long boundFromWS = (long)internal_constants::Z_max * KL * T; 300 | 301 | return std::min(boundFromT, boundFromWS); 302 | } 303 | 304 | bool parameter_checker::_are_data_length_and_symbol_size_out_of_bounds( 305 | uint64_t F, 306 | uint16_t T) 307 | { 308 | return internal_functions::get_possible_total_symbols(F, 309 | T) > internal_constants::Kt_max; 310 | } 311 | 312 | bool parameter_checker::_are_data_length_and_payload_length_out_of_bounds( 313 | uint64_t F, 314 | uint16_t P) 315 | { 316 | return _are_data_length_and_symbol_size_out_of_bounds(F, P); 317 | } 318 | 319 | void parameter_checker::_check_data_length_out_of_bounds(uint64_t F) 320 | { 321 | if (is_data_length_out_of_bounds(F)) { 322 | throw std::invalid_argument("source data length is out of bounds"); 323 | } 324 | } 325 | 326 | void parameter_checker::_check_symbol_size_out_of_bounds(uint16_t T) 327 | { 328 | if (is_symbol_size_out_of_bounds(T)) { 329 | throw std::invalid_argument("symbol size is out of bounds"); 330 | } 331 | } 332 | 333 | void parameter_checker::_check_data_length_and_symbol_size_out_of_bounds( 334 | uint64_t F, 335 | uint16_t T) 336 | { 337 | if (_are_data_length_and_symbol_size_out_of_bounds(F, T)) { 338 | throw std::invalid_argument("source data length and symbol size are out of bounds in unison"); 339 | } 340 | } 341 | 342 | void parameter_checker::_check_num_source_blocks_out_of_bounds(uint8_t Z) 343 | { 344 | if (is_num_source_blocks_out_of_bounds(Z)) { 345 | throw std::invalid_argument("number of source blocks is out of bounds"); 346 | } 347 | } 348 | 349 | void parameter_checker::_check_payload_length_out_of_bounds(uint16_t P) 350 | { 351 | if (is_payload_length_out_of_bounds(P)) { 352 | throw std::invalid_argument("payload length is out of bounds"); 353 | } 354 | } 355 | 356 | void parameter_checker::_check_data_length_and_payload_length_out_of_bounds( 357 | uint64_t F, uint16_t P) 358 | { 359 | if (_are_data_length_and_payload_length_out_of_bounds(F, P)) { 360 | throw std::invalid_argument("source data length and payload length are out of bounds in unison"); 361 | } 362 | } 363 | 364 | void parameter_checker::_check_decoding_block_size_out_of_bounds(uint64_t WS) 365 | { 366 | if (WS < min_decoding_block_size()) { 367 | throw std::invalid_argument("maximum decoding block size is out of bounds"); 368 | } 369 | } 370 | 371 | void parameter_checker::_check_num_source_symbols_per_block_out_of_bounds( 372 | uint16_t K) 373 | { 374 | if (is_num_source_symbols_per_block_out_of_bounds(K)) { 375 | throw std::invalid_argument("number of source symbols per block is out of bounds"); 376 | } 377 | } 378 | -------------------------------------------------------------------------------- /src/parameters/parameter_io.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | int parameter_io::data_length_shift() 28 | { 29 | return (1 + sizeof(unsigned short)) * sizeof(uint8_t) * 30 | 8; // shift by (1 + 2) octets 31 | } 32 | 33 | uint64_t parameter_io::extract_data_length(uint64_t commonFecOTI) 34 | { 35 | return commonFecOTI >> data_length_shift(); 36 | } 37 | 38 | uint16_t parameter_io::extract_symbol_size(uint64_t commonFecOTI) 39 | { 40 | return (uint16_t)commonFecOTI; 41 | } 42 | 43 | int parameter_io::num_source_blocks_shift() 44 | { 45 | return (sizeof(uint16_t) + 1) * sizeof(uint8_t) * 8; // shift by (2 + 1) octets 46 | } 47 | 48 | uint8_t parameter_io::extract_num_source_blocks(uint32_t schemeSpecFecOTI) 49 | { 50 | return (uint8_t)(schemeSpecFecOTI >> num_source_blocks_shift()); 51 | } 52 | 53 | int parameter_io::interleaver_length_shift() 54 | { 55 | return 1 * sizeof(uint8_t) * 8; // shift by 1 octet 56 | } 57 | 58 | uint16_t parameter_io::extract_interleaver_length(uint32_t schemeSpecFecOTI) 59 | { 60 | return (uint16_t)(schemeSpecFecOTI >> interleaver_length_shift()); 61 | } 62 | 63 | uint8_t parameter_io::extract_symbol_alignment(uint32_t schemeSpecFecOTI) 64 | { 65 | return (uint8_t)schemeSpecFecOTI; 66 | } 67 | 68 | int parameter_io::source_block_number_shift() 69 | { 70 | return internal_constants::ESI_num_bytes * sizeof(uint8_t) * 8; 71 | } 72 | 73 | uint8_t parameter_io::extract_source_block_number(uint32_t fecPayloadID) 74 | { 75 | return (uint8_t)(fecPayloadID >> source_block_number_shift()); 76 | } 77 | 78 | uint32_t parameter_io::extract_encoding_symbol_id(uint32_t fecPayloadID) 79 | { 80 | return fecPayloadID; 81 | } 82 | 83 | uint64_t parameter_io::build_common_fec_oti(uint64_t dataLen, 84 | uint16_t symbolSize) 85 | { 86 | return (dataLen << data_length_shift()) | symbolSize; 87 | } 88 | 89 | uint64_t parameter_io::canonicalize_common_fec_oti(uint64_t commonFecOTI) 90 | { 91 | return commonFecOTI & internal_constants::common_oti_reserved_inverse_mask; 92 | } 93 | 94 | uint32_t parameter_io::build_scheme_spec_fec_oti(uint8_t numSrcBs, 95 | uint16_t interLen, uint8_t sAlign) 96 | { 97 | return (numSrcBs << num_source_blocks_shift()) | (interLen << 98 | interleaver_length_shift()) | sAlign; 99 | } 100 | 101 | uint32_t parameter_io::build_fec_payload_id(uint8_t sbn, uint32_t esi) 102 | { 103 | return (sbn << source_block_number_shift()) | esi; 104 | } 105 | -------------------------------------------------------------------------------- /src/partition.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | // 4.4.1.2 Source Block and Sub-Block Partitioning 28 | partition::partition(unsigned int I, unsigned int J) 29 | { 30 | m_IL = (I + J - 1) / J; // ceil(I / J) 31 | m_IS = I / J; // floor(I / J) 32 | m_JL = I - (m_IS * J); 33 | m_JS = J - m_JL; 34 | } 35 | 36 | // TODO(pbhandari): Convert these to constant member variables. 37 | int partition::IL() 38 | { 39 | return m_IL; 40 | } 41 | 42 | int partition::IS() 43 | { 44 | return m_IS; 45 | } 46 | 47 | int partition::JL() 48 | { 49 | return m_JL; 50 | } 51 | 52 | int partition::JS() 53 | { 54 | return m_JS; 55 | } 56 | -------------------------------------------------------------------------------- /src/row.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | row::row(int i, int r, int d, bool hdpc) 29 | { 30 | m_position = i; 31 | m_non_zeros = r; 32 | m_original_degree = d; 33 | m_nodes = std::set(); 34 | m_is_hdpc = hdpc; 35 | } 36 | 37 | row::row(int i, int r, int d, bool hdpc, std::set e) 38 | { 39 | m_position = i; 40 | m_non_zeros = r; 41 | m_original_degree = d; 42 | m_nodes = e; 43 | m_is_hdpc = hdpc; 44 | } 45 | 46 | bool row::operator==(const row &other) 47 | { 48 | return other.m_position == this->m_position; 49 | } 50 | -------------------------------------------------------------------------------- /src/tuple.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | // 5.3.3.2 Source Symbol Tuples 28 | tuple::tuple(int k_prime, long x) 29 | { 30 | int Ki = systematic_indices::get_k_index(k_prime); 31 | int S = systematic_indices::S(Ki); 32 | int H = systematic_indices::H(Ki); 33 | int W = systematic_indices::W(Ki); 34 | int L = k_prime + S + H; 35 | int J = systematic_indices::J(Ki); 36 | int P = L - W; 37 | long P1 = matrix_utilities::ceil_prime(P); 38 | 39 | long A = 53591 + J * 997; 40 | if (A % 2 == 0) { 41 | A++; 42 | } 43 | 44 | long B = 10267 * (J + 1); 45 | 46 | long y = (B + x * A) % 4294967296L; // 2^^32 47 | 48 | long v = rand::generate(y, 0, 1048576L); // 2^^20 49 | 50 | m_d = deg::generate(v, W); 51 | m_a = 1 + rand::generate(y, 1, W - 1); 52 | m_b = rand::generate(y, 2, W); 53 | if (m_d < 4) { 54 | m_d1 = 2 + rand::generate(x, 3, 2L); 55 | } else { 56 | m_d1 = 2; 57 | } 58 | m_a1 = 1 + rand::generate(x, 4, P1 - 1); 59 | m_b1 = rand::generate(x, 5, P1); 60 | } 61 | 62 | long tuple::D() 63 | { 64 | return m_d; 65 | } 66 | 67 | long tuple::A() 68 | { 69 | return m_a; 70 | } 71 | 72 | long tuple::B() 73 | { 74 | return m_b; 75 | } 76 | 77 | long tuple::D1() 78 | { 79 | return m_d1; 80 | } 81 | 82 | long tuple::A1() 83 | { 84 | return m_a1; 85 | } 86 | 87 | long tuple::B1() 88 | { 89 | return m_b1; 90 | } 91 | -------------------------------------------------------------------------------- /src/util/deg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | // 5.3.5.2 Degree Generator 29 | const unsigned int deg::m_table1[] = { 30 | 0, 31 | 5243, 32 | 529531, 33 | 704294, 34 | 791675, 35 | 844104, 36 | 879057, 37 | 904023, 38 | 922747, 39 | 937311, 40 | 948962, 41 | 958494, 42 | 966438, 43 | 973160, 44 | 978921, 45 | 983914, 46 | 988283, 47 | 992138, 48 | 995565, 49 | 998631, 50 | 1001391, 51 | 1003887, 52 | 1006157, 53 | 1008229, 54 | 1010129, 55 | 1011876, 56 | 1013490, 57 | 1014983, 58 | 1016370, 59 | 1017662, 60 | 1048576 61 | }; 62 | 63 | int deg::generate(unsigned int v, int W) 64 | { 65 | for (int i = 0; i < 31; i++) { 66 | if (v < m_table1[i]) { 67 | return (std::min(i, W - 2)); 68 | } 69 | } 70 | 71 | throw std::runtime_error("Inconsistent table state"); 72 | } 73 | -------------------------------------------------------------------------------- /src/util/extra_math.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | int extra_math::ceil_div(int num, int den) 28 | { 29 | return (num + (den - 1L)) / den; 30 | } 31 | -------------------------------------------------------------------------------- /src/util/octet_ops.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | // TODO(pbhandari): make this table a bit more organized. 28 | // 5.7.3 The Table OCT_EXP 29 | const int octet_ops::m_OCT_EXP[] = { 30 | 1, 2, 4, 8, 16, 32, 64, 128, 29, 58, 116, 232, 205, 135, 19, 38, 76, 31 | 152, 45, 90, 180, 117, 234, 201, 143, 3, 6, 12, 24, 48, 96, 192, 157, 32 | 39, 78, 156, 37, 74, 148, 53, 106, 212, 181, 119, 238, 193, 159, 35, 33 | 70, 140, 5, 10, 20, 40, 80, 160, 93, 186, 105, 210, 185, 111, 222, 34 | 161, 95, 190, 97, 194, 153, 47, 94, 188, 101, 202, 137, 15, 30, 60, 35 | 120, 240, 253, 231, 211, 187, 107, 214, 177, 127, 254, 225, 223, 163, 36 | 91, 182, 113, 226, 217, 175, 67, 134, 17, 34, 68, 136, 13, 26, 52, 37 | 104, 208, 189, 103, 206, 129, 31, 62, 124, 248, 237, 199, 147, 59, 38 | 118, 236, 197, 151, 51, 102, 204, 133, 23, 46, 92, 184, 109, 218, 39 | 169, 79, 158, 33, 66, 132, 21, 42, 84, 168, 77, 154, 41, 82, 164, 85, 40 | 170, 73, 146, 57, 114, 228, 213, 183, 115, 230, 209, 191, 99, 198, 41 | 145, 63, 126, 252, 229, 215, 179, 123, 246, 241, 255, 227, 219, 171, 42 | 75, 150, 49, 98, 196, 149, 55, 110, 220, 165, 87, 174, 65, 130, 25, 43 | 50, 100, 200, 141, 7, 14, 28, 56, 112, 224, 221, 167, 83, 166, 81, 44 | 162, 89, 178, 121, 242, 249, 239, 195, 155, 43, 86, 172, 69, 138, 9, 45 | 18, 36, 72, 144, 61, 122, 244, 245, 247, 243, 251, 235, 203, 139, 11, 46 | 22, 44, 88, 176, 125, 250, 233, 207, 131, 27, 54, 108, 216, 173, 71, 47 | 142, 1, 2, 4, 8, 16, 32, 64, 128, 29, 58, 116, 232, 205, 135, 19, 38, 48 | 76, 152, 45, 90, 180, 117, 234, 201, 143, 3, 6, 12, 24, 48, 96, 192, 49 | 157, 39, 78, 156, 37, 74, 148, 53, 106, 212, 181, 119, 238, 193, 159, 50 | 35, 70, 140, 5, 10, 20, 40, 80, 160, 93, 186, 105, 210, 185, 111, 51 | 222, 161, 95, 190, 97, 194, 153, 47, 94, 188, 101, 202, 137, 15, 30, 52 | 60, 120, 240, 253, 231, 211, 187, 107, 214, 177, 127, 254, 225, 223, 53 | 163, 91, 182, 113, 226, 217, 175, 67, 134, 17, 34, 68, 136, 13, 26, 54 | 52, 104, 208, 189, 103, 206, 129, 31, 62, 124, 248, 237, 199, 147, 55 | 59, 118, 236, 197, 151, 51, 102, 204, 133, 23, 46, 92, 184, 109, 218, 56 | 169, 79, 158, 33, 66, 132, 21, 42, 84, 168, 77, 154, 41, 82, 164, 85, 57 | 170, 73, 146, 57, 114, 228, 213, 183, 115, 230, 209, 191, 99, 198, 58 | 145, 63, 126, 252, 229, 215, 179, 123, 246, 241, 255, 227, 219, 171, 59 | 75, 150, 49, 98, 196, 149, 55, 110, 220, 165, 87, 174, 65, 130, 25, 60 | 50, 100, 200, 141, 7, 14, 28, 56, 112, 224, 221, 167, 83, 166, 81, 61 | 162, 89, 178, 121, 242, 249, 239, 195, 155, 43, 86, 172, 69, 138, 9, 62 | 18, 36, 72, 144, 61, 122, 244, 245, 247, 243, 251, 235, 203, 139, 11, 63 | 22, 44, 88, 176, 125, 250, 233, 207, 131, 27, 54, 108, 216, 173, 71, 64 | 142 65 | }; 66 | 67 | // TODO(pbhandari): make this table a bit more organized. 68 | // 5.7.4 The Table OCT_LOG 69 | const int octet_ops::m_OCT_LOG[] = { 70 | 0, 1, 25, 2, 50, 26, 198, 3, 223, 51, 238, 27, 104, 199, 75, 4, 100, 71 | 224, 14, 52, 141, 239, 129, 28, 193, 105, 248, 200, 8, 76, 113, 5, 72 | 138, 101, 47, 225, 36, 15, 33, 53, 147, 142, 218, 240, 18, 130, 69, 73 | 29, 181, 194, 125, 106, 39, 249, 185, 201, 154, 9, 120, 77, 228, 114, 74 | 166, 6, 191, 139, 98, 102, 221, 48, 253, 226, 152, 37, 179, 16, 145, 75 | 34, 136, 54, 208, 148, 206, 143, 150, 219, 189, 241, 210, 19, 92, 76 | 131, 56, 70, 64, 30, 66, 182, 163, 195, 72, 126, 110, 107, 58, 40, 77 | 84, 250, 133, 186, 61, 202, 94, 155, 159, 10, 21, 121, 43, 78, 212, 78 | 229, 172, 115, 243, 167, 87, 7, 112, 192, 247, 140, 128, 99, 13, 103, 79 | 74, 222, 237, 49, 197, 254, 24, 227, 165, 153, 119, 38, 184, 180, 80 | 124, 17, 68, 146, 217, 35, 32, 137, 46, 55, 63, 209, 91, 149, 188, 81 | 207, 205, 144, 135, 151, 178, 220, 252, 190, 97, 242, 86, 211, 171, 82 | 20, 42, 93, 158, 132, 60, 57, 83, 71, 109, 65, 162, 31, 45, 67, 216, 83 | 183, 123, 164, 118, 196, 23, 73, 236, 127, 12, 111, 246, 108, 161, 84 | 59, 82, 41, 157, 85, 170, 251, 96, 134, 177, 187, 204, 62, 90, 203, 85 | 89, 95, 176, 156, 169, 160, 81, 11, 245, 22, 235, 122, 117, 44, 215, 86 | 79, 174, 213, 233, 230, 231, 173, 232, 116, 214, 244, 234, 168, 80, 87 | 88, 175 88 | }; 89 | 90 | // 5.7.2 Arithmetic Operations on Octets 91 | uint8_t octet_ops::get_exp(int i) 92 | { 93 | return m_OCT_EXP[i]; 94 | } 95 | 96 | uint8_t octet_ops::get_log(int i) 97 | { 98 | return m_OCT_LOG[i - 1]; 99 | } 100 | 101 | uint8_t octet_ops::addition(uint8_t u, uint8_t v) 102 | { 103 | return (uint8_t)(u ^ v); 104 | } 105 | 106 | uint8_t octet_ops::subtraction(uint8_t u, uint8_t v) 107 | { 108 | return addition(u, v); 109 | } 110 | 111 | uint8_t octet_ops::product(uint8_t u, uint8_t v) 112 | { 113 | if (u == 0 || v == 0) { 114 | return 0; 115 | } 116 | return (uint8_t)get_exp(get_log(u) + get_log(v)); 117 | } 118 | 119 | uint8_t octet_ops::division(uint8_t u, uint8_t v) 120 | { 121 | if (v == 0) { 122 | throw std::invalid_argument("Denominator cannot be 0."); 123 | } 124 | if (u == 0) { 125 | return 0; 126 | } 127 | return (uint8_t)get_exp((get_log(u) - get_log(v)) + 255); 128 | } 129 | 130 | uint8_t octet_ops::alpha_power(int i) 131 | { 132 | return get_exp(i); 133 | } 134 | 135 | // 5.7.5 Operations on Symbols 136 | // TODO(pbhandari): Convert uint8_t arrays to vectors. 137 | void octet_ops::beta_product(uint8_t beta, uint8_t *U) 138 | { 139 | // TODO(pbhandari): Check that U != null and length of U > 0. 140 | if (beta == 1) { 141 | return; 142 | } 143 | 144 | for (int i = 0; i < static_cast(sizeof(U) / sizeof(U[0])); i++) { 145 | U[i] = product(beta, U[i]); 146 | } 147 | } 148 | 149 | // TODO(pbhandari): Convert uint8_t arrays to vectors. 150 | void octet_ops::beta_division(uint8_t *U, uint8_t beta) 151 | { 152 | // TODO(pbhandari): Check that U != null and length of U > 0. 153 | if (beta == 1) { 154 | return; 155 | } 156 | for (int i = 0; i < static_cast(sizeof(U) / sizeof(U[0])); i++) { 157 | U[i] = division(U[i], beta); 158 | } 159 | } 160 | 161 | // TODO(pbhandari): Convert uint8_t arrays to vectors. 162 | void octet_ops::beta_product(uint8_t beta, uint8_t U[], int pos, int length) 163 | { 164 | // TODO(pbhandari): Check that U != null and length of U > 0. 165 | if (beta == 1) { 166 | return; 167 | } 168 | for (int i = 0; i < length; i++) { 169 | U[i + pos] = product(beta, U[i + pos]); 170 | } 171 | } 172 | 173 | // TODO(pbhandari): Convert uint8_t arrays to vectors. 174 | void octet_ops::beta_division(uint8_t U[], uint8_t beta, int pos, int length) 175 | { 176 | // TODO(pbhandari): Check that U != null and length of U > 0. 177 | if (beta == 1) { 178 | return; 179 | } 180 | for (int i = 0; i < length; i++) { 181 | U[i + pos] = division(U[i + pos], beta); 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /src/util/rand.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby grantedu, free of chargeu, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software")u, to deal 8 | * in the Software without restrictionu, including without limitation the rights 9 | * to useu, copyu, modifyu, mergeu, publishu, distributeu, sublicenseu, and/or sell 10 | * copies of the Softwareu, and to permit persons to whom the Software is 11 | * furnished to do sou, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS"u, WITHOUT WARRANTY OF ANY KINDu, EXPRESS OR 17 | * IMPLIEDu, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITYu, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIMu, DAMAGES OR OTHER 20 | * LIABILITYu, WHETHER IN AN ACTION OF CONTRACTu, TORT OR OTHERWISEu, ARISING FROMu, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | // 5.5 Random Numbers 28 | const uint32_t rand::m_V0[] = { 29 | 251291136u, 3952231631u, 3370958628u, 4070167936u, 123631495u, 30 | 3351110283u, 3218676425u, 2011642291u, 774603218u, 2402805061u, 31 | 1004366930u, 1843948209u, 428891132u, 3746331984u, 1591258008u, 32 | 3067016507u, 1433388735u, 504005498u, 2032657933u, 3419319784u, 33 | 2805686246u, 3102436986u, 3808671154u, 2501582075u, 3978944421u, 34 | 246043949u, 4016898363u, 649743608u, 1974987508u, 2651273766u, 35 | 2357956801u, 689605112u, 715807172u, 2722736134u, 191939188u, 36 | 3535520147u, 3277019569u, 1470435941u, 3763101702u, 3232409631u, 37 | 122701163u, 3920852693u, 782246947u, 372121310u, 2995604341u, 38 | 2045698575u, 2332962102u, 4005368743u, 218596347u, 3415381967u, 39 | 4207612806u, 861117671u, 3676575285u, 2581671944u, 3312220480u, 40 | 681232419u, 307306866u, 4112503940u, 1158111502u, 709227802u, 41 | 2724140433u, 4201101115u, 4215970289u, 4048876515u, 3031661061u, 42 | 1909085522u, 510985033u, 1361682810u, 129243379u, 3142379587u, 43 | 2569842483u, 3033268270u, 1658118006u, 932109358u, 1982290045u, 44 | 2983082771u, 3007670818u, 3448104768u, 683749698u, 778296777u, 45 | 1399125101u, 1939403708u, 1692176003u, 3868299200u, 1422476658u, 46 | 593093658u, 1878973865u, 2526292949u, 1591602827u, 3986158854u, 47 | 3964389521u, 2695031039u, 1942050155u, 424618399u, 1347204291u, 48 | 2669179716u, 2434425874u, 2540801947u, 1384069776u, 4123580443u, 49 | 1523670218u, 2708475297u, 1046771089u, 2229796016u, 1255426612u, 50 | 4213663089u, 1521339547u, 3041843489u, 420130494u, 10677091u, 51 | 515623176u, 3457502702u, 2115821274u, 2720124766u, 3242576090u, 52 | 854310108u, 425973987u, 325832382u, 1796851292u, 2462744411u, 53 | 1976681690u, 1408671665u, 1228817808u, 3917210003u, 263976645u, 54 | 2593736473u, 2471651269u, 4291353919u, 650792940u, 1191583883u, 55 | 3046561335u, 2466530435u, 2545983082u, 969168436u, 2019348792u, 56 | 2268075521u, 1169345068u, 3250240009u, 3963499681u, 2560755113u, 57 | 911182396u, 760842409u, 3569308693u, 2687243553u, 381854665u, 58 | 2613828404u, 2761078866u, 1456668111u, 883760091u, 3294951678u, 59 | 1604598575u, 1985308198u, 1014570543u, 2724959607u, 3062518035u, 60 | 3115293053u, 138853680u, 4160398285u, 3322241130u, 2068983570u, 61 | 2247491078u, 3669524410u, 1575146607u, 828029864u, 3732001371u, 62 | 3422026452u, 3370954177u, 4006626915u, 543812220u, 1243116171u, 63 | 3928372514u, 2791443445u, 4081325272u, 2280435605u, 885616073u, 64 | 616452097u, 3188863436u, 2780382310u, 2340014831u, 1208439576u, 65 | 258356309u, 3837963200u, 2075009450u, 3214181212u, 3303882142u, 66 | 880813252u, 1355575717u, 207231484u, 2420803184u, 358923368u, 67 | 1617557768u, 3272161958u, 1771154147u, 2842106362u, 1751209208u, 68 | 1421030790u, 658316681u, 194065839u, 3241510581u, 38625260u, 69 | 301875395u, 4176141739u, 297312930u, 2137802113u, 1502984205u, 70 | 3669376622u, 3728477036u, 234652930u, 2213589897u, 2734638932u, 71 | 1129721478u, 3187422815u, 2859178611u, 3284308411u, 3819792700u, 72 | 3557526733u, 451874476u, 1740576081u, 3592838701u, 1709429513u, 73 | 3702918379u, 3533351328u, 1641660745u, 179350258u, 2380520112u, 74 | 3936163904u, 3685256204u, 3156252216u, 1854258901u, 2861641019u, 75 | 3176611298u, 834787554u, 331353807u, 517858103u, 3010168884u, 76 | 4012642001u, 2217188075u, 3756943137u, 3077882590u, 2054995199u, 77 | 3081443129u, 3895398812u, 1141097543u, 2376261053u, 2626898255u, 78 | 2554703076u, 401233789u, 1460049922u, 678083952u, 1064990737u, 79 | 940909784u, 1673396780u, 528881783u, 1712547446u, 3629685652u, 80 | 1358307511u 81 | }; 82 | 83 | const uint32_t rand::m_V1[] = { 84 | 807385413u, 2043073223u, 3336749796u, 1302105833u, 2278607931u, 85 | 541015020u, 1684564270u, 372709334u, 3508252125u, 1768346005u, 86 | 1270451292u, 2603029534u, 2049387273u, 3891424859u, 2152948345u, 87 | 4114760273u, 915180310u, 3754787998u, 700503826u, 2131559305u, 88 | 1308908630u, 224437350u, 4065424007u, 3638665944u, 1679385496u, 89 | 3431345226u, 1779595665u, 3068494238u, 1424062773u, 1033448464u, 90 | 4050396853u, 3302235057u, 420600373u, 2868446243u, 311689386u, 91 | 259047959u, 4057180909u, 1575367248u, 4151214153u, 110249784u, 92 | 3006865921u, 4293710613u, 3501256572u, 998007483u, 499288295u, 93 | 1205710710u, 2997199489u, 640417429u, 3044194711u, 486690751u, 94 | 2686640734u, 2394526209u, 2521660077u, 49993987u, 3843885867u, 95 | 4201106668u, 415906198u, 19296841u, 2402488407u, 2137119134u, 96 | 1744097284u, 579965637u, 2037662632u, 852173610u, 2681403713u, 97 | 1047144830u, 2982173936u, 910285038u, 4187576520u, 2589870048u, 98 | 989448887u, 3292758024u, 506322719u, 176010738u, 1865471968u, 99 | 2619324712u, 564829442u, 1996870325u, 339697593u, 4071072948u, 100 | 3618966336u, 2111320126u, 1093955153u, 957978696u, 892010560u, 101 | 1854601078u, 1873407527u, 2498544695u, 2694156259u, 1927339682u, 102 | 1650555729u, 183933047u, 3061444337u, 2067387204u, 228962564u, 103 | 3904109414u, 1595995433u, 1780701372u, 2463145963u, 307281463u, 104 | 3237929991u, 3852995239u, 2398693510u, 3754138664u, 522074127u, 105 | 146352474u, 4104915256u, 3029415884u, 3545667983u, 332038910u, 106 | 976628269u, 3123492423u, 3041418372u, 2258059298u, 2139377204u, 107 | 3243642973u, 3226247917u, 3674004636u, 2698992189u, 3453843574u, 108 | 1963216666u, 3509855005u, 2358481858u, 747331248u, 1957348676u, 109 | 1097574450u, 2435697214u, 3870972145u, 1888833893u, 2914085525u, 110 | 4161315584u, 1273113343u, 3269644828u, 3681293816u, 412536684u, 111 | 1156034077u, 3823026442u, 1066971017u, 3598330293u, 1979273937u, 112 | 2079029895u, 1195045909u, 1071986421u, 2712821515u, 3377754595u, 113 | 2184151095u, 750918864u, 2585729879u, 4249895712u, 1832579367u, 114 | 1192240192u, 946734366u, 31230688u, 3174399083u, 3549375728u, 115 | 1642430184u, 1904857554u, 861877404u, 3277825584u, 4267074718u, 116 | 3122860549u, 666423581u, 644189126u, 226475395u, 307789415u, 117 | 1196105631u, 3191691839u, 782852669u, 1608507813u, 1847685900u, 118 | 4069766876u, 3931548641u, 2526471011u, 766865139u, 2115084288u, 119 | 4259411376u, 3323683436u, 568512177u, 3736601419u, 1800276898u, 120 | 4012458395u, 1823982u, 27980198u, 2023839966u, 869505096u, 121 | 431161506u, 1024804023u, 1853869307u, 3393537983u, 1500703614u, 122 | 3019471560u, 1351086955u, 3096933631u, 3034634988u, 2544598006u, 123 | 1230942551u, 3362230798u, 159984793u, 491590373u, 3993872886u, 124 | 3681855622u, 903593547u, 3535062472u, 1799803217u, 772984149u, 125 | 895863112u, 1899036275u, 4187322100u, 101856048u, 234650315u, 126 | 3183125617u, 3190039692u, 525584357u, 1286834489u, 455810374u, 127 | 1869181575u, 922673938u, 3877430102u, 3422391938u, 1414347295u, 128 | 1971054608u, 3061798054u, 830555096u, 2822905141u, 167033190u, 129 | 1079139428u, 4210126723u, 3593797804u, 429192890u, 372093950u, 130 | 1779187770u, 3312189287u, 204349348u, 452421568u, 2800540462u, 131 | 3733109044u, 1235082423u, 1765319556u, 3174729780u, 3762994475u, 132 | 3171962488u, 442160826u, 198349622u, 45942637u, 1324086311u, 133 | 2901868599u, 678860040u, 3812229107u, 19936821u, 1119590141u, 134 | 3640121682u, 3545931032u, 2102949142u, 2828208598u, 3603378023u, 135 | 4135048896u 136 | }; 137 | 138 | const uint32_t rand::m_V2[] = { 139 | 1629829892u, 282540176u, 2794583710u, 496504798u, 2990494426u, 140 | 3070701851u, 2575963183u, 4094823972u, 2775723650u, 4079480416u, 141 | 176028725u, 2246241423u, 3732217647u, 2196843075u, 1306949278u, 142 | 4170992780u, 4039345809u, 3209664269u, 3387499533u, 293063229u, 143 | 3660290503u, 2648440860u, 2531406539u, 3537879412u, 773374739u, 144 | 4184691853u, 1804207821u, 3347126643u, 3479377103u, 3970515774u, 145 | 1891731298u, 2368003842u, 3537588307u, 2969158410u, 4230745262u, 146 | 831906319u, 2935838131u, 264029468u, 120852739u, 3200326460u, 147 | 355445271u, 2296305141u, 1566296040u, 1760127056u, 20073893u, 148 | 3427103620u, 2866979760u, 2359075957u, 2025314291u, 1725696734u, 149 | 3346087406u, 2690756527u, 99815156u, 4248519977u, 2253762642u, 150 | 3274144518u, 598024568u, 3299672435u, 556579346u, 4121041856u, 151 | 2896948975u, 3620123492u, 918453629u, 3249461198u, 2231414958u, 152 | 3803272287u, 3657597946u, 2588911389u, 242262274u, 1725007475u, 153 | 2026427718u, 46776484u, 2873281403u, 2919275846u, 3177933051u, 154 | 1918859160u, 2517854537u, 1857818511u, 3234262050u, 479353687u, 155 | 200201308u, 2801945841u, 1621715769u, 483977159u, 423502325u, 156 | 3689396064u, 1850168397u, 3359959416u, 3459831930u, 841488699u, 157 | 3570506095u, 930267420u, 1564520841u, 2505122797u, 593824107u, 158 | 1116572080u, 819179184u, 3139123629u, 1414339336u, 1076360795u, 159 | 512403845u, 177759256u, 1701060666u, 2239736419u, 515179302u, 160 | 2935012727u, 3821357612u, 1376520851u, 2700745271u, 966853647u, 161 | 1041862223u, 715860553u, 171592961u, 1607044257u, 1227236688u, 162 | 3647136358u, 1417559141u, 4087067551u, 2241705880u, 4194136288u, 163 | 1439041934u, 20464430u, 119668151u, 2021257232u, 2551262694u, 164 | 1381539058u, 4082839035u, 498179069u, 311508499u, 3580908637u, 165 | 2889149671u, 142719814u, 1232184754u, 3356662582u, 2973775623u, 166 | 1469897084u, 1728205304u, 1415793613u, 50111003u, 3133413359u, 167 | 4074115275u, 2710540611u, 2700083070u, 2457757663u, 2612845330u, 168 | 3775943755u, 2469309260u, 2560142753u, 3020996369u, 1691667711u, 169 | 4219602776u, 1687672168u, 1017921622u, 2307642321u, 368711460u, 170 | 3282925988u, 213208029u, 4150757489u, 3443211944u, 2846101972u, 171 | 4106826684u, 4272438675u, 2199416468u, 3710621281u, 497564971u, 172 | 285138276u, 765042313u, 916220877u, 3402623607u, 2768784621u, 173 | 1722849097u, 3386397442u, 487920061u, 3569027007u, 3424544196u, 174 | 217781973u, 2356938519u, 3252429414u, 145109750u, 2692588106u, 175 | 2454747135u, 1299493354u, 4120241887u, 2088917094u, 932304329u, 176 | 1442609203u, 952586974u, 3509186750u, 753369054u, 854421006u, 177 | 1954046388u, 2708927882u, 4047539230u, 3048925996u, 1667505809u, 178 | 805166441u, 1182069088u, 4265546268u, 4215029527u, 3374748959u, 179 | 373532666u, 2454243090u, 2371530493u, 3651087521u, 2619878153u, 180 | 1651809518u, 1553646893u, 1227452842u, 703887512u, 3696674163u, 181 | 2552507603u, 2635912901u, 895130484u, 3287782244u, 3098973502u, 182 | 990078774u, 3780326506u, 2290845203u, 41729428u, 1949580860u, 183 | 2283959805u, 1036946170u, 1694887523u, 4880696u, 466000198u, 184 | 2765355283u, 3318686998u, 1266458025u, 3919578154u, 3545413527u, 185 | 2627009988u, 3744680394u, 1696890173u, 3250684705u, 4142417708u, 186 | 915739411u, 3308488877u, 1289361460u, 2942552331u, 1169105979u, 187 | 3342228712u, 698560958u, 1356041230u, 2401944293u, 107705232u, 188 | 3701895363u, 903928723u, 3646581385u, 844950914u, 1944371367u, 189 | 3863894844u, 2946773319u, 1972431613u, 1706989237u, 29917467u, 190 | 3497665928u 191 | }; 192 | 193 | const uint32_t rand::m_V3[] = { 194 | 1191369816u, 744902811u, 2539772235u, 3213192037u, 3286061266u, 195 | 1200571165u, 2463281260u, 754888894u, 714651270u, 1968220972u, 196 | 3628497775u, 1277626456u, 1493398934u, 364289757u, 2055487592u, 197 | 3913468088u, 2930259465u, 902504567u, 3967050355u, 2056499403u, 198 | 692132390u, 186386657u, 832834706u, 859795816u, 1283120926u, 199 | 2253183716u, 3003475205u, 1755803552u, 2239315142u, 4271056352u, 200 | 2184848469u, 769228092u, 1249230754u, 1193269205u, 2660094102u, 201 | 642979613u, 1687087994u, 2726106182u, 446402913u, 4122186606u, 202 | 3771347282u, 37667136u, 192775425u, 3578702187u, 1952659096u, 203 | 3989584400u, 3069013882u, 2900516158u, 4045316336u, 3057163251u, 204 | 1702104819u, 4116613420u, 3575472384u, 2674023117u, 1409126723u, 205 | 3215095429u, 1430726429u, 2544497368u, 1029565676u, 1855801827u, 206 | 4262184627u, 1854326881u, 2906728593u, 3277836557u, 2787697002u, 207 | 2787333385u, 3105430738u, 2477073192u, 748038573u, 1088396515u, 208 | 1611204853u, 201964005u, 3745818380u, 3654683549u, 3816120877u, 209 | 3915783622u, 2563198722u, 1181149055u, 33158084u, 3723047845u, 210 | 3790270906u, 3832415204u, 2959617497u, 372900708u, 1286738499u, 211 | 1932439099u, 3677748309u, 2454711182u, 2757856469u, 2134027055u, 212 | 2780052465u, 3190347618u, 3758510138u, 3626329451u, 1120743107u, 213 | 1623585693u, 1389834102u, 2719230375u, 3038609003u, 462617590u, 214 | 260254189u, 3706349764u, 2556762744u, 2874272296u, 2502399286u, 215 | 4216263978u, 2683431180u, 2168560535u, 3561507175u, 668095726u, 216 | 680412330u, 3726693946u, 4180630637u, 3335170953u, 942140968u, 217 | 2711851085u, 2059233412u, 4265696278u, 3204373534u, 232855056u, 218 | 881788313u, 2258252172u, 2043595984u, 3758795150u, 3615341325u, 219 | 2138837681u, 1351208537u, 2923692473u, 3402482785u, 2105383425u, 220 | 2346772751u, 499245323u, 3417846006u, 2366116814u, 2543090583u, 221 | 1828551634u, 3148696244u, 3853884867u, 1364737681u, 2200687771u, 222 | 2689775688u, 232720625u, 4071657318u, 2671968983u, 3531415031u, 223 | 1212852141u, 867923311u, 3740109711u, 1923146533u, 3237071777u, 224 | 3100729255u, 3247856816u, 906742566u, 4047640575u, 4007211572u, 225 | 3495700105u, 1171285262u, 2835682655u, 1634301229u, 3115169925u, 226 | 2289874706u, 2252450179u, 944880097u, 371933491u, 1649074501u, 227 | 2208617414u, 2524305981u, 2496569844u, 2667037160u, 1257550794u, 228 | 3399219045u, 3194894295u, 1643249887u, 342911473u, 891025733u, 229 | 3146861835u, 3789181526u, 938847812u, 1854580183u, 2112653794u, 230 | 2960702988u, 1238603378u, 2205280635u, 1666784014u, 2520274614u, 231 | 3355493726u, 2310872278u, 3153920489u, 2745882591u, 1200203158u, 232 | 3033612415u, 2311650167u, 1048129133u, 4206710184u, 4209176741u, 233 | 2640950279u, 2096382177u, 4116899089u, 3631017851u, 4104488173u, 234 | 1857650503u, 3801102932u, 445806934u, 3055654640u, 897898279u, 235 | 3234007399u, 1325494930u, 2982247189u, 1619020475u, 2720040856u, 236 | 885096170u, 3485255499u, 2983202469u, 3891011124u, 546522756u, 237 | 1524439205u, 2644317889u, 2170076800u, 2969618716u, 961183518u, 238 | 1081831074u, 1037015347u, 3289016286u, 2331748669u, 620887395u, 239 | 303042654u, 3990027945u, 1562756376u, 3413341792u, 2059647769u, 240 | 2823844432u, 674595301u, 2457639984u, 4076754716u, 2447737904u, 241 | 1583323324u, 625627134u, 3076006391u, 345777990u, 1684954145u, 242 | 879227329u, 3436182180u, 1522273219u, 3802543817u, 1456017040u, 243 | 1897819847u, 2970081129u, 1382576028u, 3820044861u, 1044428167u, 244 | 612252599u, 3340478395u, 2150613904u, 3397625662u, 3573635640u, 245 | 3432275192u 246 | }; 247 | 248 | // 5.3.5.1 Random Number Generator 249 | int rand::generate(uint32_t y, uint8_t i, uint32_t m) 250 | { 251 | // if(y < 0) throw std::invalid_argument("y must be non-negative"); 252 | if (i < 0 || i > 255) { 253 | throw std::invalid_argument("i must be non-negative and less than 256"); 254 | } 255 | if (m < 1) { 256 | throw std::invalid_argument("m must be positive"); 257 | } 258 | 259 | int x0 = (y + i) % 256; 260 | int x1 = (y / 256 + i) % 256; 261 | int x2 = (y / 65536 + i) % 256; 262 | int x3 = (y / 16777216 + i) % 256; 263 | 264 | int v0 = m_V0[x0]; 265 | int v1 = m_V1[x1]; 266 | int v2 = m_V2[x2]; 267 | int v3 = m_V3[x3]; 268 | 269 | int ret = v0 ^ v1 ^ v2 ^ v3; 270 | ret = ret % m; 271 | 272 | return ret; 273 | } 274 | -------------------------------------------------------------------------------- /src/util/systematic_indices.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | // 5.6 Systematic Indicies and Other Parameters 28 | const unsigned int systematic_indices::m_table2[][5] = { 29 | {10, 254, 7, 10, 17}, 30 | {12, 630, 7, 10, 19}, 31 | {18, 682, 11, 10, 29}, 32 | {20, 293, 11, 10, 31}, 33 | {26, 80, 11, 10, 37}, 34 | {30, 566, 11, 10, 41}, 35 | {32, 860, 11, 10, 43}, 36 | {36, 267, 11, 10, 47}, 37 | {42, 822, 11, 10, 53}, 38 | {46, 506, 13, 10, 59}, 39 | {48, 589, 13, 10, 61}, 40 | {49, 87, 13, 10, 61}, 41 | {55, 520, 13, 10, 67}, 42 | {60, 159, 13, 10, 71}, 43 | {62, 235, 13, 10, 73}, 44 | {69, 157, 13, 10, 79}, 45 | {75, 502, 17, 10, 89}, 46 | {84, 334, 17, 10, 97}, 47 | {88, 583, 17, 10, 101}, 48 | {91, 66, 17, 10, 103}, 49 | {95, 352, 17, 10, 107}, 50 | {97, 365, 17, 10, 109}, 51 | {101, 562, 17, 10, 113}, 52 | {114, 5, 19, 10, 127}, 53 | {119, 603, 19, 10, 131}, 54 | {125, 721, 19, 10, 137}, 55 | {127, 28, 19, 10, 139}, 56 | {138, 660, 19, 10, 149}, 57 | {140, 829, 19, 10, 151}, 58 | {149, 900, 23, 10, 163}, 59 | {153, 930, 23, 10, 167}, 60 | {160, 814, 23, 10, 173}, 61 | {166, 661, 23, 10, 179}, 62 | {168, 693, 23, 10, 181}, 63 | {179, 780, 23, 10, 191}, 64 | {181, 605, 23, 10, 193}, 65 | {185, 551, 23, 10, 197}, 66 | {187, 777, 23, 10, 199}, 67 | {200, 491, 23, 10, 211}, 68 | {213, 396, 23, 10, 223}, 69 | {217, 764, 29, 10, 233}, 70 | {225, 843, 29, 10, 241}, 71 | {236, 646, 29, 10, 251}, 72 | {242, 557, 29, 10, 257}, 73 | {248, 608, 29, 10, 263}, 74 | {257, 265, 29, 10, 271}, 75 | {263, 505, 29, 10, 277}, 76 | {269, 722, 29, 10, 283}, 77 | {280, 263, 29, 10, 293}, 78 | {295, 999, 29, 10, 307}, 79 | {301, 874, 29, 10, 313}, 80 | {305, 160, 29, 10, 317}, 81 | {324, 575, 31, 10, 337}, 82 | {337, 210, 31, 10, 349}, 83 | {341, 513, 31, 10, 353}, 84 | {347, 503, 31, 10, 359}, 85 | {355, 558, 31, 10, 367}, 86 | {362, 932, 31, 10, 373}, 87 | {368, 404, 31, 10, 379}, 88 | {372, 520, 37, 10, 389}, 89 | {380, 846, 37, 10, 397}, 90 | {385, 485, 37, 10, 401}, 91 | {393, 728, 37, 10, 409}, 92 | {405, 554, 37, 10, 421}, 93 | {418, 471, 37, 10, 433}, 94 | {428, 641, 37, 10, 443}, 95 | {434, 732, 37, 10, 449}, 96 | {447, 193, 37, 10, 461}, 97 | {453, 934, 37, 10, 467}, 98 | {466, 864, 37, 10, 479}, 99 | {478, 790, 37, 10, 491}, 100 | {486, 912, 37, 10, 499}, 101 | {491, 617, 37, 10, 503}, 102 | {497, 587, 37, 10, 509}, 103 | {511, 800, 37, 10, 523}, 104 | {526, 923, 41, 10, 541}, 105 | {532, 998, 41, 10, 547}, 106 | {542, 92, 41, 10, 557}, 107 | {549, 497, 41, 10, 563}, 108 | {557, 559, 41, 10, 571}, 109 | {563, 667, 41, 10, 577}, 110 | {573, 912, 41, 10, 587}, 111 | {580, 262, 41, 10, 593}, 112 | {588, 152, 41, 10, 601}, 113 | {594, 526, 41, 10, 607}, 114 | {600, 268, 41, 10, 613}, 115 | {606, 212, 41, 10, 619}, 116 | {619, 45, 41, 10, 631}, 117 | {633, 898, 43, 10, 647}, 118 | {640, 527, 43, 10, 653}, 119 | {648, 558, 43, 10, 661}, 120 | {666, 460, 47, 10, 683}, 121 | {675, 5, 47, 10, 691}, 122 | {685, 895, 47, 10, 701}, 123 | {693, 996, 47, 10, 709}, 124 | {703, 282, 47, 10, 719}, 125 | {718, 513, 47, 10, 733}, 126 | {728, 865, 47, 10, 743}, 127 | {736, 870, 47, 10, 751}, 128 | {747, 239, 47, 10, 761}, 129 | {759, 452, 47, 10, 773}, 130 | {778, 862, 53, 10, 797}, 131 | {792, 852, 53, 10, 811}, 132 | {802, 643, 53, 10, 821}, 133 | {811, 543, 53, 10, 829}, 134 | {821, 447, 53, 10, 839}, 135 | {835, 321, 53, 10, 853}, 136 | {845, 287, 53, 10, 863}, 137 | {860, 12, 53, 10, 877}, 138 | {870, 251, 53, 10, 887}, 139 | {891, 30, 53, 10, 907}, 140 | {903, 621, 53, 10, 919}, 141 | {913, 555, 53, 10, 929}, 142 | {926, 127, 53, 10, 941}, 143 | {938, 400, 53, 10, 953}, 144 | {950, 91, 59, 10, 971}, 145 | {963, 916, 59, 10, 983}, 146 | {977, 935, 59, 10, 997}, 147 | {989, 691, 59, 10, 1009}, 148 | {1002, 299, 59, 10, 1021}, 149 | {1020, 282, 59, 10, 1039}, 150 | {1032, 824, 59, 10, 1051}, 151 | {1050, 536, 59, 11, 1069}, 152 | {1074, 596, 59, 11, 1093}, 153 | {1085, 28, 59, 11, 1103}, 154 | {1099, 947, 59, 11, 1117}, 155 | {1111, 162, 59, 11, 1129}, 156 | {1136, 536, 59, 11, 1153}, 157 | {1152, 1000, 61, 11, 1171}, 158 | {1169, 251, 61, 11, 1187}, 159 | {1183, 673, 61, 11, 1201}, 160 | {1205, 559, 61, 11, 1223}, 161 | {1220, 923, 61, 11, 1237}, 162 | {1236, 81, 67, 11, 1259}, 163 | {1255, 478, 67, 11, 1277}, 164 | {1269, 198, 67, 11, 1291}, 165 | {1285, 137, 67, 11, 1307}, 166 | {1306, 75, 67, 11, 1327}, 167 | {1347, 29, 67, 11, 1367}, 168 | {1361, 231, 67, 11, 1381}, 169 | {1389, 532, 67, 11, 1409}, 170 | {1404, 58, 67, 11, 1423}, 171 | {1420, 60, 67, 11, 1439}, 172 | {1436, 964, 71, 11, 1459}, 173 | {1461, 624, 71, 11, 1483}, 174 | {1477, 502, 71, 11, 1499}, 175 | {1502, 636, 71, 11, 1523}, 176 | {1522, 986, 71, 11, 1543}, 177 | {1539, 950, 71, 11, 1559}, 178 | {1561, 735, 73, 11, 1583}, 179 | {1579, 866, 73, 11, 1601}, 180 | {1600, 203, 73, 11, 1621}, 181 | {1616, 83, 73, 11, 1637}, 182 | {1649, 14, 73, 11, 1669}, 183 | {1673, 522, 79, 11, 1699}, 184 | {1698, 226, 79, 11, 1723}, 185 | {1716, 282, 79, 11, 1741}, 186 | {1734, 88, 79, 11, 1759}, 187 | {1759, 636, 79, 11, 1783}, 188 | {1777, 860, 79, 11, 1801}, 189 | {1800, 324, 79, 11, 1823}, 190 | {1824, 424, 79, 11, 1847}, 191 | {1844, 999, 79, 11, 1867}, 192 | {1863, 682, 83, 11, 1889}, 193 | {1887, 814, 83, 11, 1913}, 194 | {1906, 979, 83, 11, 1931}, 195 | {1926, 538, 83, 11, 1951}, 196 | {1954, 278, 83, 11, 1979}, 197 | {1979, 580, 83, 11, 2003}, 198 | {2005, 773, 83, 11, 2029}, 199 | {2040, 911, 89, 11, 2069}, 200 | {2070, 506, 89, 11, 2099}, 201 | {2103, 628, 89, 11, 2131}, 202 | {2125, 282, 89, 11, 2153}, 203 | {2152, 309, 89, 11, 2179}, 204 | {2195, 858, 89, 11, 2221}, 205 | {2217, 442, 89, 11, 2243}, 206 | {2247, 654, 89, 11, 2273}, 207 | {2278, 82, 97, 11, 2311}, 208 | {2315, 428, 97, 11, 2347}, 209 | {2339, 442, 97, 11, 2371}, 210 | {2367, 283, 97, 11, 2399}, 211 | {2392, 538, 97, 11, 2423}, 212 | {2416, 189, 97, 11, 2447}, 213 | {2447, 438, 97, 11, 2477}, 214 | {2473, 912, 97, 11, 2503}, 215 | {2502, 1, 97, 11, 2531}, 216 | {2528, 167, 97, 11, 2557}, 217 | {2565, 272, 97, 11, 2593}, 218 | {2601, 209, 101, 11, 2633}, 219 | {2640, 927, 101, 11, 2671}, 220 | {2668, 386, 101, 11, 2699}, 221 | {2701, 653, 101, 11, 2731}, 222 | {2737, 669, 101, 11, 2767}, 223 | {2772, 431, 101, 11, 2801}, 224 | {2802, 793, 103, 11, 2833}, 225 | {2831, 588, 103, 11, 2861}, 226 | {2875, 777, 107, 11, 2909}, 227 | {2906, 939, 107, 11, 2939}, 228 | {2938, 864, 107, 11, 2971}, 229 | {2979, 627, 107, 11, 3011}, 230 | {3015, 265, 109, 11, 3049}, 231 | {3056, 976, 109, 11, 3089}, 232 | {3101, 988, 113, 11, 3137}, 233 | {3151, 507, 113, 11, 3187}, 234 | {3186, 640, 113, 11, 3221}, 235 | {3224, 15, 113, 11, 3259}, 236 | {3265, 667, 113, 11, 3299}, 237 | {3299, 24, 127, 11, 3347}, 238 | {3344, 877, 127, 11, 3391}, 239 | {3387, 240, 127, 11, 3433}, 240 | {3423, 720, 127, 11, 3469}, 241 | {3466, 93, 127, 11, 3511}, 242 | {3502, 919, 127, 11, 3547}, 243 | {3539, 635, 127, 11, 3583}, 244 | {3579, 174, 127, 11, 3623}, 245 | {3616, 647, 127, 11, 3659}, 246 | {3658, 820, 127, 11, 3701}, 247 | {3697, 56, 127, 11, 3739}, 248 | {3751, 485, 127, 11, 3793}, 249 | {3792, 210, 127, 11, 3833}, 250 | {3840, 124, 127, 11, 3881}, 251 | {3883, 546, 127, 11, 3923}, 252 | {3924, 954, 131, 11, 3967}, 253 | {3970, 262, 131, 11, 4013}, 254 | {4015, 927, 131, 11, 4057}, 255 | {4069, 957, 131, 11, 4111}, 256 | {4112, 726, 137, 11, 4159}, 257 | {4165, 583, 137, 11, 4211}, 258 | {4207, 782, 137, 11, 4253}, 259 | {4252, 37, 137, 11, 4297}, 260 | {4318, 758, 137, 11, 4363}, 261 | {4365, 777, 137, 11, 4409}, 262 | {4418, 104, 139, 11, 4463}, 263 | {4468, 476, 139, 11, 4513}, 264 | {4513, 113, 149, 11, 4567}, 265 | {4567, 313, 149, 11, 4621}, 266 | {4626, 102, 149, 11, 4679}, 267 | {4681, 501, 149, 11, 4733}, 268 | {4731, 332, 149, 11, 4783}, 269 | {4780, 786, 149, 11, 4831}, 270 | {4838, 99, 149, 11, 4889}, 271 | {4901, 658, 149, 11, 4951}, 272 | {4954, 794, 149, 11, 5003}, 273 | {5008, 37, 151, 11, 5059}, 274 | {5063, 471, 151, 11, 5113}, 275 | {5116, 94, 157, 11, 5171}, 276 | {5172, 873, 157, 11, 5227}, 277 | {5225, 918, 157, 11, 5279}, 278 | {5279, 945, 157, 11, 5333}, 279 | {5334, 211, 157, 11, 5387}, 280 | {5391, 341, 157, 11, 5443}, 281 | {5449, 11, 163, 11, 5507}, 282 | {5506, 578, 163, 11, 5563}, 283 | {5566, 494, 163, 11, 5623}, 284 | {5637, 694, 163, 11, 5693}, 285 | {5694, 252, 163, 11, 5749}, 286 | {5763, 451, 167, 11, 5821}, 287 | {5823, 83, 167, 11, 5881}, 288 | {5896, 689, 167, 11, 5953}, 289 | {5975, 488, 173, 11, 6037}, 290 | {6039, 214, 173, 11, 6101}, 291 | {6102, 17, 173, 11, 6163}, 292 | {6169, 469, 173, 11, 6229}, 293 | {6233, 263, 179, 11, 6299}, 294 | {6296, 309, 179, 11, 6361}, 295 | {6363, 984, 179, 11, 6427}, 296 | {6427, 123, 179, 11, 6491}, 297 | {6518, 360, 179, 11, 6581}, 298 | {6589, 863, 181, 11, 6653}, 299 | {6655, 122, 181, 11, 6719}, 300 | {6730, 522, 191, 11, 6803}, 301 | {6799, 539, 191, 11, 6871}, 302 | {6878, 181, 191, 11, 6949}, 303 | {6956, 64, 191, 11, 7027}, 304 | {7033, 387, 191, 11, 7103}, 305 | {7108, 967, 191, 11, 7177}, 306 | {7185, 843, 191, 11, 7253}, 307 | {7281, 999, 193, 11, 7351}, 308 | {7360, 76, 197, 11, 7433}, 309 | {7445, 142, 197, 11, 7517}, 310 | {7520, 599, 197, 11, 7591}, 311 | {7596, 576, 199, 11, 7669}, 312 | {7675, 176, 211, 11, 7759}, 313 | {7770, 392, 211, 11, 7853}, 314 | {7855, 332, 211, 11, 7937}, 315 | {7935, 291, 211, 11, 8017}, 316 | {8030, 913, 211, 11, 8111}, 317 | {8111, 608, 211, 11, 8191}, 318 | {8194, 212, 211, 11, 8273}, 319 | {8290, 696, 211, 11, 8369}, 320 | {8377, 931, 223, 11, 8467}, 321 | {8474, 326, 223, 11, 8563}, 322 | {8559, 228, 223, 11, 8647}, 323 | {8654, 706, 223, 11, 8741}, 324 | {8744, 144, 223, 11, 8831}, 325 | {8837, 83, 223, 11, 8923}, 326 | {8928, 743, 223, 11, 9013}, 327 | {9019, 187, 223, 11, 9103}, 328 | {9111, 654, 227, 11, 9199}, 329 | {9206, 359, 227, 11, 9293}, 330 | {9303, 493, 229, 11, 9391}, 331 | {9400, 369, 233, 11, 9491}, 332 | {9497, 981, 233, 11, 9587}, 333 | {9601, 276, 239, 11, 9697}, 334 | {9708, 647, 239, 11, 9803}, 335 | {9813, 389, 239, 11, 9907}, 336 | {9916, 80, 239, 11, 10009}, 337 | {10017, 396, 241, 11, 10111}, 338 | {10120, 580, 251, 11, 10223}, 339 | {10241, 873, 251, 11, 10343}, 340 | {10351, 15, 251, 11, 10453}, 341 | {10458, 976, 251, 11, 10559}, 342 | {10567, 584, 251, 11, 10667}, 343 | {10676, 267, 257, 11, 10781}, 344 | {10787, 876, 257, 11, 10891}, 345 | {10899, 642, 257, 12, 11003}, 346 | {11015, 794, 257, 12, 11119}, 347 | {11130, 78, 263, 12, 11239}, 348 | {11245, 736, 263, 12, 11353}, 349 | {11358, 882, 269, 12, 11471}, 350 | {11475, 251, 269, 12, 11587}, 351 | {11590, 434, 269, 12, 11701}, 352 | {11711, 204, 269, 12, 11821}, 353 | {11829, 256, 271, 12, 11941}, 354 | {11956, 106, 277, 12, 12073}, 355 | {12087, 375, 277, 12, 12203}, 356 | {12208, 148, 277, 12, 12323}, 357 | {12333, 496, 281, 12, 12451}, 358 | {12460, 88, 281, 12, 12577}, 359 | {12593, 826, 293, 12, 12721}, 360 | {12726, 71, 293, 12, 12853}, 361 | {12857, 925, 293, 12, 12983}, 362 | {13002, 760, 293, 12, 13127}, 363 | {13143, 130, 293, 12, 13267}, 364 | {13284, 641, 307, 12, 13421}, 365 | {13417, 400, 307, 12, 13553}, 366 | {13558, 480, 307, 12, 13693}, 367 | {13695, 76, 307, 12, 13829}, 368 | {13833, 665, 307, 12, 13967}, 369 | {13974, 910, 307, 12, 14107}, 370 | {14115, 467, 311, 12, 14251}, 371 | {14272, 964, 311, 12, 14407}, 372 | {14415, 625, 313, 12, 14551}, 373 | {14560, 362, 317, 12, 14699}, 374 | {14713, 759, 317, 12, 14851}, 375 | {14862, 728, 331, 12, 15013}, 376 | {15011, 343, 331, 12, 15161}, 377 | {15170, 113, 331, 12, 15319}, 378 | {15325, 137, 331, 12, 15473}, 379 | {15496, 308, 331, 12, 15643}, 380 | {15651, 800, 337, 12, 15803}, 381 | {15808, 177, 337, 12, 15959}, 382 | {15977, 961, 337, 12, 16127}, 383 | {16161, 958, 347, 12, 16319}, 384 | {16336, 72, 347, 12, 16493}, 385 | {16505, 732, 347, 12, 16661}, 386 | {16674, 145, 349, 12, 16831}, 387 | {16851, 577, 353, 12, 17011}, 388 | {17024, 305, 353, 12, 17183}, 389 | {17195, 50, 359, 12, 17359}, 390 | {17376, 351, 359, 12, 17539}, 391 | {17559, 175, 367, 12, 17729}, 392 | {17742, 727, 367, 12, 17911}, 393 | {17929, 902, 367, 12, 18097}, 394 | {18116, 409, 373, 12, 18289}, 395 | {18309, 776, 373, 12, 18481}, 396 | {18503, 586, 379, 12, 18679}, 397 | {18694, 451, 379, 12, 18869}, 398 | {18909, 287, 383, 12, 19087}, 399 | {19126, 246, 389, 12, 19309}, 400 | {19325, 222, 389, 12, 19507}, 401 | {19539, 563, 397, 12, 19727}, 402 | {19740, 839, 397, 12, 19927}, 403 | {19939, 897, 401, 12, 20129}, 404 | {20152, 409, 401, 12, 20341}, 405 | {20355, 618, 409, 12, 20551}, 406 | {20564, 439, 409, 12, 20759}, 407 | {20778, 95, 419, 13, 20983}, 408 | {20988, 448, 419, 13, 21191}, 409 | {21199, 133, 419, 13, 21401}, 410 | {21412, 938, 419, 13, 21613}, 411 | {21629, 423, 431, 13, 21841}, 412 | {21852, 90, 431, 13, 22063}, 413 | {22073, 640, 431, 13, 22283}, 414 | {22301, 922, 433, 13, 22511}, 415 | {22536, 250, 439, 13, 22751}, 416 | {22779, 367, 439, 13, 22993}, 417 | {23010, 447, 443, 13, 23227}, 418 | {23252, 559, 449, 13, 23473}, 419 | {23491, 121, 457, 13, 23719}, 420 | {23730, 623, 457, 13, 23957}, 421 | {23971, 450, 457, 13, 24197}, 422 | {24215, 253, 461, 13, 24443}, 423 | {24476, 106, 467, 13, 24709}, 424 | {24721, 863, 467, 13, 24953}, 425 | {24976, 148, 479, 13, 25219}, 426 | {25230, 427, 479, 13, 25471}, 427 | {25493, 138, 479, 13, 25733}, 428 | {25756, 794, 487, 13, 26003}, 429 | {26022, 247, 487, 13, 26267}, 430 | {26291, 562, 491, 13, 26539}, 431 | {26566, 53, 499, 13, 26821}, 432 | {26838, 135, 499, 13, 27091}, 433 | {27111, 21, 503, 13, 27367}, 434 | {27392, 201, 509, 13, 27653}, 435 | {27682, 169, 521, 13, 27953}, 436 | {27959, 70, 521, 13, 28229}, 437 | {28248, 386, 521, 13, 28517}, 438 | {28548, 226, 523, 13, 28817}, 439 | {28845, 3, 541, 13, 29131}, 440 | {29138, 769, 541, 13, 29423}, 441 | {29434, 590, 541, 13, 29717}, 442 | {29731, 672, 541, 13, 30013}, 443 | {30037, 713, 547, 13, 30323}, 444 | {30346, 967, 547, 13, 30631}, 445 | {30654, 368, 557, 14, 30949}, 446 | {30974, 348, 557, 14, 31267}, 447 | {31285, 119, 563, 14, 31583}, 448 | {31605, 503, 569, 14, 31907}, 449 | {31948, 181, 571, 14, 32251}, 450 | {32272, 394, 577, 14, 32579}, 451 | {32601, 189, 587, 14, 32917}, 452 | {32932, 210, 587, 14, 33247}, 453 | {33282, 62, 593, 14, 33601}, 454 | {33623, 273, 593, 14, 33941}, 455 | {33961, 554, 599, 14, 34283}, 456 | {34302, 936, 607, 14, 34631}, 457 | {34654, 483, 607, 14, 34981}, 458 | {35031, 397, 613, 14, 35363}, 459 | {35395, 241, 619, 14, 35731}, 460 | {35750, 500, 631, 14, 36097}, 461 | {36112, 12, 631, 14, 36457}, 462 | {36479, 958, 641, 14, 36833}, 463 | {36849, 524, 641, 14, 37201}, 464 | {37227, 8, 643, 14, 37579}, 465 | {37606, 100, 653, 14, 37967}, 466 | {37992, 339, 653, 14, 38351}, 467 | {38385, 804, 659, 14, 38749}, 468 | {38787, 510, 673, 14, 39163}, 469 | {39176, 18, 673, 14, 39551}, 470 | {39576, 412, 677, 14, 39953}, 471 | {39980, 394, 683, 14, 40361}, 472 | {40398, 830, 691, 15, 40787}, 473 | {40816, 535, 701, 15, 41213}, 474 | {41226, 199, 701, 15, 41621}, 475 | {41641, 27, 709, 15, 42043}, 476 | {42067, 298, 709, 15, 42467}, 477 | {42490, 368, 719, 15, 42899}, 478 | {42916, 755, 727, 15, 43331}, 479 | {43388, 379, 727, 15, 43801}, 480 | {43840, 73, 733, 15, 44257}, 481 | {44279, 387, 739, 15, 44701}, 482 | {44729, 457, 751, 15, 45161}, 483 | {45183, 761, 751, 15, 45613}, 484 | {45638, 855, 757, 15, 46073}, 485 | {46104, 370, 769, 15, 46549}, 486 | {46574, 261, 769, 15, 47017}, 487 | {47047, 299, 787, 15, 47507}, 488 | {47523, 920, 787, 15, 47981}, 489 | {48007, 269, 787, 15, 48463}, 490 | {48489, 862, 797, 15, 48953}, 491 | {48976, 349, 809, 15, 49451}, 492 | {49470, 103, 809, 15, 49943}, 493 | {49978, 115, 821, 15, 50461}, 494 | {50511, 93, 821, 16, 50993}, 495 | {51017, 982, 827, 16, 51503}, 496 | {51530, 432, 839, 16, 52027}, 497 | {52062, 340, 853, 16, 52571}, 498 | {52586, 173, 853, 16, 53093}, 499 | {53114, 421, 857, 16, 53623}, 500 | {53650, 330, 863, 16, 54163}, 501 | {54188, 624, 877, 16, 54713}, 502 | {54735, 233, 877, 16, 55259}, 503 | {55289, 362, 883, 16, 55817}, 504 | {55843, 963, 907, 16, 56393}, 505 | {56403, 471, 907, 16, 56951} 506 | }; 507 | 508 | unsigned int systematic_indices::get_k_index(unsigned int k_prime) 509 | { 510 | if (k_prime < 1) { 511 | throw std::invalid_argument("K must be positive."); 512 | } 513 | if (k_prime > 56403) { 514 | throw std::invalid_argument("K must be smaller than 56403."); 515 | } 516 | 517 | for (int i = 0; i < 477; i++) { 518 | if (K(i) >= k_prime) { 519 | return i; 520 | } 521 | } 522 | 523 | throw std::runtime_error("Invalid table state"); 524 | } 525 | 526 | unsigned int systematic_indices::K(unsigned int k_index) 527 | { 528 | return m_table2[k_index][0]; 529 | } 530 | 531 | unsigned int systematic_indices::J(unsigned int k_index) 532 | { 533 | return m_table2[k_index][1]; 534 | } 535 | 536 | unsigned int systematic_indices::S(unsigned int k_index) 537 | { 538 | return m_table2[k_index][2]; 539 | } 540 | 541 | unsigned int systematic_indices::H(unsigned int k_index) 542 | { 543 | return m_table2[k_index][3]; 544 | } 545 | 546 | unsigned int systematic_indices::W(unsigned int k_index) 547 | { 548 | return m_table2[k_index][4]; 549 | } 550 | 551 | int systematic_indices::ceil(unsigned int k_prime) 552 | { 553 | if (k_prime < 1) { 554 | throw std::invalid_argument("K must be positive."); 555 | } 556 | if (k_prime > 56403) { 557 | throw std::invalid_argument("K must be smaller than 56403."); 558 | } 559 | 560 | for (int i = 0; i < 477; i++) { 561 | if (K(i) >= k_prime) { 562 | return (K(i)); 563 | } 564 | } 565 | 566 | throw std::runtime_error("Invalid table state"); 567 | } 568 | 569 | int systematic_indices::floor(unsigned int k_prime) 570 | { 571 | if (k_prime < 1) { 572 | throw std::invalid_argument("K must be positive."); 573 | } 574 | if (k_prime > 56403) { 575 | throw std::invalid_argument("K must be smaller than 56403."); 576 | } 577 | 578 | for (int i = 477 - 1; i >= 0; i--) { 579 | if (K(i) <= k_prime) { 580 | return (K(i)); 581 | } 582 | } 583 | 584 | throw std::runtime_error("Invalid table state"); 585 | } 586 | -------------------------------------------------------------------------------- /test/orq.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #define CATCH_CONFIG_MAIN 26 | #include 27 | -------------------------------------------------------------------------------- /test/parameters/fec_parameters.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | TEST_CASE("fec_parameters can be created, encoded into OTIs, then restored", 29 | "[fec_parameters]") 30 | { 31 | fec_parameters f = fec_parameters::new_parameters(1024, 16, 64); 32 | 33 | REQUIRE(f.data_length() == 1024LLU); 34 | REQUIRE(f.symbol_size() == 16); 35 | REQUIRE(f.num_source_blocks() == 64); 36 | REQUIRE(f.interleaver_length() == 1); 37 | REQUIRE(f.symbol_alignment() == 1); 38 | REQUIRE(f.total_symbols() == 64); 39 | } 40 | -------------------------------------------------------------------------------- /test/parsed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan, Prajjwal Bhandari 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | TEST_CASE("Parsed::of returns a 'valid' Parsed Object", "[Parsed]") 32 | { 33 | std::vector test {1, 2, 3}; 34 | 35 | Parsed< std::vector > &p = Parsed< std::vector >::of(test); 36 | 37 | SECTION("It should be valid,") { 38 | REQUIRE(p.is_valid()); 39 | } 40 | 41 | SECTION("value() should return a copy of the object passed in.") { 42 | REQUIRE(p.value() == test); 43 | 44 | SECTION("The object that was passed in should be deep copied.") { 45 | std::vector backup = test; 46 | test.push_back(4); 47 | REQUIRE(p.value() == backup); 48 | } 49 | } 50 | 51 | SECTION("failure_reason() should be empty.") { 52 | REQUIRE(p.failure_reason() == ""); 53 | } 54 | } 55 | 56 | TEST_CASE("Parsed::invalid returns an 'invalid' Parsed Object", "[Parsed]") 57 | { 58 | std::string reason = "reasons"; 59 | Parsed &p = Parsed::invalid(reason); 60 | 61 | SECTION("It should not be valid,") { 62 | REQUIRE_FALSE(p.is_valid()); 63 | } 64 | 65 | SECTION("value() should throw an exception") { 66 | REQUIRE_THROWS_AS(p.value(), std::string); 67 | 68 | SECTION("exception message should be the same as it's failure reason") { 69 | try { 70 | p.value(); 71 | } catch (std::string exception) { 72 | REQUIRE(p.failure_reason() == exception); 73 | } 74 | } 75 | } 76 | 77 | SECTION("failure_reason() returns a copy of the string passed in.") { 78 | REQUIRE(p.failure_reason() == reason); 79 | 80 | SECTION("The object that was passed in should be deep copied.") { 81 | std::string backup_reason = reason; 82 | reason += "foo"; 83 | REQUIRE(p.failure_reason() == backup_reason); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /test/partition.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | TEST_CASE("Partition can be created, and values are valid", "[partition]") 29 | { 30 | partition p = partition(1337, 5); 31 | 32 | REQUIRE(p.IL() == 268); 33 | REQUIRE(p.IS() == 267); 34 | REQUIRE(p.JL() == 2); 35 | REQUIRE(p.JS() == 3); 36 | } 37 | -------------------------------------------------------------------------------- /test/row.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | TEST_CASE("Row can be created, and equated", "[row]") 29 | { 30 | row r1 = row(1, 2, 3, true); 31 | row r2 = row(1, 2, 3, true); 32 | 33 | REQUIRE(r1 == r2); 34 | } 35 | -------------------------------------------------------------------------------- /test/tuple.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | TEST_CASE("Tuple can be created, and values are valid", "[tuple]") 29 | { 30 | tuple t = tuple(1337, 5); 31 | 32 | REQUIRE(t.D() == 6); 33 | REQUIRE(t.A() == 1340); 34 | REQUIRE(t.B() == 371); 35 | REQUIRE(t.D1() == 2); 36 | REQUIRE(t.A1() == 31); 37 | REQUIRE(t.B1() == 44); 38 | } 39 | -------------------------------------------------------------------------------- /test/util/rand.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Matt Olan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | TEST_CASE("Rand can be called and values are consistant", "[rand]") 29 | { 30 | REQUIRE(rand::generate(12345, 128, 54321) == 44030); 31 | } 32 | --------------------------------------------------------------------------------