rssoft  0.0.0
Reed-Solomon codes library with soft decision decoding
/shared/development/google_code/rssoft/library/lib/GF2_Polynomial.h
Go to the documentation of this file.
00001 /*
00002      Copyright 2013 Edouard Griffiths <f4exb at free dot fr>
00003 
00004      This file is part of RSSoft. A Reed-Solomon Soft Decoding library
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
00019 
00020          Original from Arash Partow (see original copytight notice).
00021          Modified and included in RSSoft in gf sub-namespace.
00022 
00023          Univariate polynomials with coefficients in GF(2) class hence
00024          members of GF(2)[X]
00025 
00026 */
00027 
00028 #ifndef __GF2_POLYNOMIAL_H__
00029 #define __GF2_POLYNOMIAL_H__
00030 
00031 #include "GF2_Element.h"
00032 #include <iostream>
00033 #include <vector>
00034 #include <utility>
00035 #include <assert.h>
00036 
00037 namespace rssoft
00038 {
00039 namespace gf
00040 {
00041 
00042 class GF2_Polynomial
00043 {
00044 public:
00048         GF2_Polynomial();
00049 
00055         GF2_Polynomial(unsigned int size, GF2_Element* gfe);
00056 
00061         GF2_Polynomial(const GF2_Polynomial& polynomial);
00062 
00066         GF2_Polynomial(const GF2_Element& gfe);
00067 
00071         GF2_Polynomial(unsigned int n);
00072 
00076         ~GF2_Polynomial()
00077         {};
00078 
00082         bool valid() const;
00083 
00087         bool null() const;
00088 
00092         unsigned int deg() const;
00093 
00097         const std::vector<GF2_Element>& get_poly() const;
00098 
00102         std::vector<GF2_Element>& get_poly_for_update();
00103 
00108         void set_degree(unsigned int x);
00109 
00110         GF2_Polynomial& operator =(const GF2_Polynomial& polynomial);
00111         GF2_Polynomial& operator =(const GF2_Element& gfe);
00112         GF2_Polynomial& operator+=(const GF2_Polynomial& polynomial);
00113         GF2_Polynomial& operator+=(const GF2_Element& gfe);
00114         GF2_Polynomial& operator-=(const GF2_Polynomial& polynomial);
00115         GF2_Polynomial& operator-=(const GF2_Element& gfe);
00116         GF2_Polynomial& operator*=(const GF2_Polynomial& polynomial);
00117         GF2_Polynomial& operator*=(const GF2_Element& gfe);
00118         GF2_Polynomial& operator/=(const GF2_Polynomial& divisor);
00119         GF2_Polynomial& operator/=(const GF2_Element& gfe);
00120         GF2_Polynomial& operator%=(const GF2_Polynomial& divisor);
00121         GF2_Polynomial& operator%=(const unsigned int& power);
00122         GF2_Polynomial& operator^=(const int& n);
00123         GF2_Polynomial& operator<<=(const unsigned int& n);
00124         GF2_Polynomial& operator>>=(const unsigned int& n);
00125 
00126         GF2_Element& operator[](unsigned int term);
00127         GF2_Element operator()(GF2_Element value);
00128 
00129         const GF2_Element& operator[](unsigned int term) const;
00130         const GF2_Element operator()(GF2_Element value) const;
00131 
00132         bool operator==(const GF2_Polynomial& polynomial) const;
00133         bool operator!=(const GF2_Polynomial& polynomial) const;
00134 
00138         friend std::ostream& operator <<(std::ostream& os, const GF2_Polynomial& polynomial);
00139 
00140 private:
00141         std::vector<GF2_Element> poly; 
00142 };
00143 
00144 void simplify(GF2_Polynomial& polynomial);
00145 GF2_Polynomial operator +(const GF2_Polynomial& a, const GF2_Polynomial& b);
00146 GF2_Polynomial operator +(const GF2_Polynomial& a, const GF2_Element& b);
00147 GF2_Polynomial operator +(const GF2_Element& a, const GF2_Polynomial& b);
00148 GF2_Polynomial operator -(const GF2_Polynomial& a, const GF2_Polynomial& b);
00149 GF2_Polynomial operator -(const GF2_Polynomial& a, const GF2_Element& b);
00150 GF2_Polynomial operator -(const GF2_Element& a, const GF2_Polynomial& b);
00151 GF2_Polynomial operator *(const GF2_Polynomial& a, const GF2_Polynomial& b);
00152 GF2_Polynomial operator *(const GF2_Element& a, const GF2_Polynomial& b);
00153 GF2_Polynomial operator *(const GF2_Polynomial& a, const GF2_Element& b);
00154 GF2_Polynomial operator /(const GF2_Polynomial& a, const GF2_Polynomial& b);
00155 GF2_Polynomial operator /(const GF2_Polynomial& a, const GF2_Element& b);
00156 GF2_Polynomial operator %(const GF2_Polynomial& a, const GF2_Polynomial& b);
00157 GF2_Polynomial operator %(const GF2_Polynomial& a, const unsigned int& power);
00158 GF2_Polynomial operator ^(const GF2_Polynomial& a, const int& n);
00159 
00163 GF2_Polynomial operator <<(const GF2_Polynomial& a, const unsigned int& n);
00164 
00169 GF2_Polynomial operator >>(const GF2_Polynomial& a, const unsigned int& n);
00170 
00179 GF2_Polynomial gcd(const GF2_Polynomial& a, const GF2_Polynomial& b);
00180 
00187 std::pair<GF2_Polynomial, GF2_Polynomial> div(const GF2_Polynomial& a,
00188                 const GF2_Polynomial& b);
00189 
00195 bool irreducible(const GF2_Polynomial& a);
00196 
00202 unsigned int coeff_parity(const GF2_Polynomial& a);
00203 
00212 bool primitive(const GF2_Polynomial& a, unsigned int m);
00213 
00214 
00215 } // namespace gf
00216 } // namespace rssoft
00217 
00218 #endif // __GF2_POLYNOMIAL_H__
00219 
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines