rssoft  0.0.0
Reed-Solomon codes library with soft decision decoding
rssoft::gf::GF2_Polynomial Class Reference

#include <GF2_Polynomial.h>

List of all members.

Public Member Functions

 GF2_Polynomial ()
 GF2_Polynomial (unsigned int size, GF2_Element *gfe)
 GF2_Polynomial (const GF2_Polynomial &polynomial)
 GF2_Polynomial (const GF2_Element &gfe)
 GF2_Polynomial (unsigned int n)
 ~GF2_Polynomial ()
bool valid () const
bool null () const
unsigned int deg () const
const std::vector< GF2_Element > & get_poly () const
std::vector< GF2_Element > & get_poly_for_update ()
void set_degree (unsigned int x)
GF2_Polynomialoperator= (const GF2_Polynomial &polynomial)
GF2_Polynomialoperator= (const GF2_Element &gfe)
GF2_Polynomialoperator+= (const GF2_Polynomial &polynomial)
GF2_Polynomialoperator+= (const GF2_Element &gfe)
GF2_Polynomialoperator-= (const GF2_Polynomial &polynomial)
GF2_Polynomialoperator-= (const GF2_Element &gfe)
GF2_Polynomialoperator*= (const GF2_Polynomial &polynomial)
GF2_Polynomialoperator*= (const GF2_Element &gfe)
GF2_Polynomialoperator/= (const GF2_Polynomial &divisor)
GF2_Polynomialoperator/= (const GF2_Element &gfe)
GF2_Polynomialoperator%= (const GF2_Polynomial &divisor)
GF2_Polynomialoperator%= (const unsigned int &power)
GF2_Polynomialoperator^= (const int &n)
GF2_Polynomialoperator<<= (const unsigned int &n)
GF2_Polynomialoperator>>= (const unsigned int &n)
GF2_Elementoperator[] (unsigned int term)
GF2_Element operator() (GF2_Element value)
const GF2_Elementoperator[] (unsigned int term) const
const GF2_Element operator() (GF2_Element value) const
bool operator== (const GF2_Polynomial &polynomial) const
bool operator!= (const GF2_Polynomial &polynomial) const

Private Attributes

std::vector< GF2_Elementpoly
 Coefficients vector.

Friends

std::ostream & operator<< (std::ostream &os, const GF2_Polynomial &polynomial)

Constructor & Destructor Documentation

Default constructor. Makes an empty thus invalid polynomial

{
        poly.clear();
}
rssoft::gf::GF2_Polynomial::GF2_Polynomial ( unsigned int  size,
GF2_Element gfe 
)

Constructs a new polynomial with coefficients in GF(2) with the specified coefficients

Parameters:
sizeThe number of coefficients
gfeCoefficients array in increasing powers of variable. If null it assign all zero values to coefficients
{
        if (gfe != NULL)
        {
                poly.assign(gfe, gfe + size);
        }
        else
        {
                poly.assign(size, 0);
        }
}

Copy constructor

Parameters:
polynomialReference of the polynomial to copy
{
        poly = polynomial.poly;
}

Constructs a zero degree polynomial with the given element as coefficient.

{
        poly.clear();
        poly.push_back(gfe);
}

Constructs the X^n polynomial

{
        poly.assign(n+1, 0);
        poly.back() = 1;
}

Destructor

        {};

Member Function Documentation

unsigned int rssoft::gf::GF2_Polynomial::deg ( ) const

Degree of the polynomial

{
        return static_cast<unsigned int>(poly.size() - 1);
}
const std::vector< GF2_Element > & rssoft::gf::GF2_Polynomial::get_poly ( ) const

Gets a constant reference to the coefficients vector

{
        return poly;
}

Gets a modifiable reference to the coefficients vector

{
        return poly;
}

Tells if the polynomial has no coefficients or a null coefficient

{
        return (poly.size() == 0) || ((poly.size() == 1) && (poly[0] == 0));
}
bool rssoft::gf::GF2_Polynomial::operator!= ( const GF2_Polynomial polynomial) const
{
        return !(*this == polynomial);
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator%= ( const GF2_Polynomial divisor)
{
        const std::pair<GF2_Polynomial, GF2_Polynomial>& divres = div(*this, divisor);
        poly = divres.second.get_poly();
        return *this;
}

Here is the call graph for this function:

GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator%= ( const unsigned int &  power)
{
        if (poly.size() >= power)
        {
                for (size_t i = poly.size(); i > power; i--)
                {
                        poly.pop_back();
                }
        }

        simplify(*this);
        return *this;
}

Here is the call graph for this function:

GF2_Element rssoft::gf::GF2_Polynomial::operator() ( GF2_Element  value)
{
        GF2_Element result = 0;

        if (poly.size() > 0)
        {
                result = poly[poly.size() - 1];
                for (std::size_t i = poly.size() - 2; ((int) i) >= 0; i--)
                {
                        result = poly[i] + (result * value);
                }
                return result;
        }
        else
        {
                throw GF_Exception("Cannot evaluate invalid polynomial");
        }
}
const GF2_Element rssoft::gf::GF2_Polynomial::operator() ( GF2_Element  value) const
{
        GF2_Element result = 0;

        if (poly.size() > 0)
        {
                result = poly[poly.size() - 1];
                for (std::size_t i = poly.size() - 2; ((int) i) >= 0; i--)
                {
                        result = poly[i] + (result * value);
                }
                return result;
        }
        else
        {
                throw GF_Exception("Cannot evaluate invalid polynomial");
        }
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator*= ( const GF2_Polynomial polynomial)
{
        GF2_Polynomial product(deg() + polynomial.deg() + 1, 0); // create polynomial with all zero coefficients

        for (unsigned int i = 0; i < poly.size(); i++)
        {
                for (unsigned int j = 0; j < polynomial.poly.size(); j++)
                {
                        product.poly[i + j] += poly[i] * polynomial.poly[j];
                }
        }

        simplify(product);
        poly = product.poly;

        return *this;
}

Here is the call graph for this function:

GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator*= ( const GF2_Element gfe)
{
        if (gfe == 0)
        {
                poly.clear();
                poly.push_back(0);
        }

        return *this;
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator+= ( const GF2_Polynomial polynomial)
{
        if (poly.size() < polynomial.poly.size())
        {
                unsigned int j = 0;
                for (unsigned int i = 0; i < poly.size(); i++)
                {
                        poly[i] += polynomial.poly[j++];
                }

                for (; j < polynomial.poly.size(); j++)
                {
                        poly.push_back(polynomial.poly[j]);
                }
        }
        else
        {
                unsigned int i = 0;
                for (unsigned int j = 0; j < polynomial.poly.size(); j++)
                {
                        poly[i++] += polynomial.poly[j];
                }
        }

        simplify(*this);

        return *this;
}

Here is the call graph for this function:

GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator+= ( const GF2_Element gfe)
{
        poly[0] += gfe;
        return *this;
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator-= ( const GF2_Polynomial polynomial)
{
        return (*this += polynomial);
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator-= ( const GF2_Element gfe)
{
        poly[0] -= gfe;
        return *this;
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator/= ( const GF2_Polynomial divisor)
{
        const std::pair<GF2_Polynomial, GF2_Polynomial>& divres = div(*this, divisor);
        poly = divres.first.get_poly();
        return *this;
}

Here is the call graph for this function:

GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator/= ( const GF2_Element gfe)
{
        if (gfe == 0)
        {
                throw GF_Exception("Division by zero");
        }

        return *this;
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator<<= ( const unsigned int &  n)
{
        if (poly.size() > 0)
        {
                std::size_t initial_size = poly.size();
                poly.resize(poly.size() + n, 1);
                std::copy(poly.rend() - initial_size, poly.rend(), poly.rbegin());
                std::fill(poly.begin(), poly.begin() + n, 0);
        }

        return *this;
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator= ( const GF2_Polynomial polynomial)
{
        if (this != &polynomial)
        {
                poly = polynomial.poly;
        }
        return *this;
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator= ( const GF2_Element gfe)
{
        poly.clear();
        poly.push_back(gfe);
        return *this;
}
bool rssoft::gf::GF2_Polynomial::operator== ( const GF2_Polynomial polynomial) const
{
        if (poly.size() != polynomial.poly.size())
                return false;
        else
        {
                for (unsigned int i = 0; i < poly.size(); i++)
                {
                        if (poly[i] != polynomial.poly[i])
                                return false;
                }
                return true;
        }
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator>>= ( const unsigned int &  n)
{
        if (n <= poly.size())
        {
                std::copy(poly.begin() + n, poly.end(), poly.begin());
                poly.erase(poly.end() - n, poly.end());
        }
        else
        {
                poly.clear();
        }
        return *this;
}
GF2_Element & rssoft::gf::GF2_Polynomial::operator[] ( unsigned int  term)
{
        assert(term < poly.size());
        return poly[term];
}
const GF2_Element & rssoft::gf::GF2_Polynomial::operator[] ( unsigned int  term) const
{
        assert(term < poly.size());
        return poly[term];
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator^= ( const int &  n)
{
        GF2_Polynomial result = *this;

        for (int i = 0; i < n; i++)
        {
                result *= *this;
        }

        *this = result;

        return *this;
}
void rssoft::gf::GF2_Polynomial::set_degree ( unsigned int  x)

Sets the degree of the polynomial. Truncates or extends with zeros the coefficients vector internally

{
        poly.resize(x - 1, 0);
}

Tells if the polynomial has coefficients

{
        return (poly.size() > 0);
}

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const GF2_Polynomial polynomial 
) [friend]

Prints a polynomial to an output stream

{
        if (polynomial.deg() >= 0)
        {
                bool is_null = true;
                bool first_coeff = true;

                for (unsigned int i = 0; i < polynomial.poly.size(); i++)
                {
                        GF2_Element coeff = polynomial.poly[i];

                        if (coeff != 0)
                        {
                                is_null = false;
                                os << ((!first_coeff) ? "+ " : "");

                                if (i == 0)
                                {
                                        os << "1 ";
                                }
                                else if (i==1)
                                {
                                        os << "x ";
                                }
                                else
                                {
                                        os << "x^" << i << " ";
                                }

                                first_coeff = false;
                        }
                }

                if (is_null)
                {
                        os << "0";
                }
        }

        return os;
}

Member Data Documentation

Coefficients vector.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines