galois
所属分类:通讯编程
开发工具:Visual C++
文件大小:9KB
下载次数:74
上传日期:2005-11-20 21:57:06
上 传 者:
管理员
说明: 通信信道编码中有用的有限域运算库,集成函数很全
(communication channel coding useful finite field arithmetic library, integrated function is all)
文件列表:
galois.cpp (33730, 1997-10-25)
Galois.h (6086, 1997-10-25)
Galois Class Library
A C++ Class Library to implement Galois field arithmetic and polynomial algebra.
Designed and written by Andrew Lin (aelin@ix.netcom.com)
Copyright (c) 1997 by Andrew Lin. All rights reserved.
Warranty
========
This source code is presented "as is". No guarantee of its correctness
is stated or implied. Use of this source code is at your own risk. You
agree by using this source code to hold harmless the source code's author
against damages arising out of the use of this source code, even if the
author was notified in advance that such damages might occur.
This source code is Freeware, with the following restrictions: It is for
academic and personal use only. It may not be used in commercial systems
without the express, written permission of the author. You may freely
distribute it as long as no money is charged for it, and all the files,
in their original form, are distributed.
Version History
======= =======
Version 1.0 -- 25 October 1997
Initial release. Implemented rudimentary functions in three classes:
class galois_field, class gf_element, and class gf_poly.
Class Descriptions
===== ============
class galois_field
Public member functions:
Constructors/Destructors -
galois_field()
The default constructor. Initializes the Galois Field size to 0,
and does not build field maps.
galois_field(const int pwr, const int * primitive_poly)
The preferred constructor. Calculates field size as 2**pwr,
and generates field maps based on primitive_poly. Note: The
degree of the primitive polynomial MUST equal pwr. eg. if
you're generating GF(2**4) with the primitive polynomial
p(x) = 1 + x + x**4, pwr must equal 4. Otherwise bad things
will happen! The primitive polynomial is represented as an
array of ints. More specifically, 1's and 0's. So the above
primitive polynomial would be represented as { 1, 1, 0, 0, 1 }
in a C++ int array of length 5.
galois_field(gf_field & g)
The copy constructor.
~galois_field()
The destructor.
Value access functions -
int power_of(const int value) const
Returns the alpha exponent of the Galois Field element equal
to value. So if alpha**2 == value, power_of() would return 2.
int value_of(const int power) const
Returns the value of the Galois Field element associated with
alpha**power.
int size() const
Returns the size of the Galois Field - 1. This is equivalent
to 2**pwr - 1, where pwr is the value passed in to the preferred
constructor.
Operators -
operator=
Set function. Makes copies of all the data in the galois_field
indicated after the equal sign.
class gf_element
Public member functions:
Constructors/Destructors -
gf_element(galois_field * g = NULL, int v = 0)
Default constructor. The galois_field pointed to by g must
be in existence for as long as the gf_element exists. Otherwise
bad things will happen. v is the value to set the element to.
gf_element(const gf_element & e)
Copy constructor.
Value access functions -
int pwr() const
Returns the alpha exponent of the gf_element's value.
int value() const
Returns the value of the gf_element.
galois_field * op_field() const
Returns a pointer to the galois_field used by the gf_element.
Operators -
gf_element & operator=(const gf_element & e)
Set function. Copies all the data in the gf_element indicated
after the equal sign.
gf_element & operator=(const int & v)
Set function. Sets the value of the gf_element to v. The
galois_field pointer remains unchanged.
gf_element & operator+=(const gf_element & e)
Add operator. Checks to make sure e operates in the same
galois_field.
gf_element & operator+=(const int & v)
Add operator. Checks to make sure v can exist in the
galois_field being operated in.
gf_element & operator*=(const gf_element & e)
Multiply operator. Checks to make sure e operates in the same
galois_field.
gf_element & operator*=(const int & v)
Multiply operator. Checks to make sure v can exist in the
galois_field being operated in.
gf_element & operator/=(const gf_element & e)
Divide operator. Checks to make sure e operates in the same
galois_field.
gf_element & operator/=(const int & v)
Divide operator. Checks to make sure v can exist in the
galois_field being operated in.
bool operator==(const gf_element & e)
Compare operator. Compares galois_fields and values.
bool operator==(const int v)
Compare operator. Compares values only.
Global Functions -
gf_element operator+(const gf_element & a, const gf_element & b)
Add two gf_elements together.
gf_element operator*(const gf_element & a, const gf_element & b)
Multiply two gf_elements together.
gf_element operator/(const gf_element & a, const gf_element & b)
Divide two gf_elements.
ostream & operator<<(ostream & o, const gf_element & e)
Put operator for gf_elements.
class gf_poly
Public member functions:
Constructors/Destructors -
gf_poly(int size = 0, gf_element * p = NULL)
gf_poly(const gf_poly & p)
Value access functions -
int deg() const
Operators -
gf_poly & operator=(const gf_poly & p)
Sets gf_poly to p. Copies all the data in p.
gf_poly & operator=(const gf_element & e)
Sets gf_poly to the gf_element e.
gf_poly & operator+=(const gf_poly & p)
Adds p to gf_poly
gf_poly & operator*=(const gf_poly & p)
Multiplies gf_poly by p.
gf_poly & operator*=(const gf_element & e)
Multiplies gf_poly by a gf_element e.
gf_poly & operator/=(const gf_poly & p)
Divide operator. Divides gf_poly by p.
gf_poly & operator/=(const gf_element & e)
Divide operator. Divides gf_poly by a gf_element e.
gf_poly & operator%=(const gf_poly & p)
Modulo operator. Sets the gf_poly to the remainder of
gf_poly / p.
gf_element & operator[](int position)
Index operator. Returns a reference to the coefficient
of x**position.
gf_element operator()(const gf_element & value)
Evaluate operator. Evaluates the gf_poly at value.
bool operator==(gf_poly & p)
Compare operator.
Global Functions -
gf_poly operator +(const gf_poly & a, const gf_poly & b)
Adds two gf_polys together.
gf_poly operator *(const gf_poly & a, const gf_poly & b)
Multiplies two gf_polys together.
gf_poly operator *(const gf_element & a, const gf_poly & b)
Multiplies a gf_element by a gf_poly.
gf_poly operator*(const gf_poly & a, const gf_element & b)
Multiplies a gf_poly by a gf_element.
gf_poly operator /(const gf_poly & a, const gf_poly & b)
Divides two gf_polys.
gf_poly operator/(const gf_poly & a, const gf_element & b);
Divides a gf_poly by a gf_element.
gf_poly operator %(const gf_poly & a, const gf_poly & b)
Finds the remainder of a / b.
ostream & operator<<(ostream & o, const gf_poly & p)
Put operator for gf_polys.
Known Bugs
===== ====
0. In vector accesses, the index should be of size 'size_type', and I'm
using 'ints'. In Borland C++ 5.02, this results in compiler warnings
about comparing signed and unsigned values. However, when I substitute
'int' with 'size_type', Borland gets all confused. Still working on
fixing this, but it doesn't seem to affect functionality.
Files
=====
readme.txt - This file - 10,407 bytes, 26 October 1997
galois.h - Include file - 6,086 bytes, 25 October 1997
galois.cpp - Source file - 33,730 bytes, 25 October 1997
The source code compiled under Borland C++ 5.02. I made every attempt to
use ANSI standard C++, and am pretty sure it will compile under any ANSI
C++ compiler, but I have not actually tried it. Please notify the author
if the Galois Class Library succeeds or fails under any other compiler.
Programmer Ramblings
========== =========
Hmmm... Oh yeah. If you find a bug in my code, for God's sake, let me know
about it! Also, if you have any ideas on expansion of this library,
comments, or questions about it, drop me a line. The latest version of this
library can always be found on my Web page.
Bibliography
============
1. "Error Control Coding: Fundamentals and Applications"
by Shu Lin and Daniel J. Costello. Prentice Hall, 1***3.
ISBN 0-13-283796-X
2. "The C++ Programming Language, Second Edition"
by Bjarne Stroustrup. Addison-Wesley, 1994.
ISBN 0-201-53992-6
3. "Effective C++: 50 Specific Ways to Improve Your Programs and Designs"
by Scott Meyers. Addision-Wesley, 1992.
ISBN 0-210-563***-9
4. "C++ Programmer's Guide to the Standard Template Library"
by Mark Nelson. IDG Books, 1995.
ISBN 1-56884-314-3
Andrew Lin
aelin@ix.netcom.com
http://pw2.netcom.com/~aelin
近期下载者:
相关文件:
收藏者: