00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __UT_PolyField__
00028 #define __UT_PolyField__
00029
00030 #include "UT_API.h"
00031 #include <SYS/SYS_Types.h>
00032 class ut_VeryLongValue;
00033 class UT_VeryLong;
00034 class UT_PolyField;
00035 class UT_BitStream;
00036
00037 UT_API UT_PolyField operator+(const UT_PolyField &x, const UT_PolyField &y);
00038 UT_API UT_PolyField operator*(const UT_PolyField &x, const UT_PolyField &y);
00039 UT_API UT_PolyField operator%(const UT_PolyField &x, const UT_PolyField &y);
00040 UT_API UT_PolyField operator-(const UT_PolyField &x, const UT_PolyField &y);
00041
00042 class UT_API UT_PolyField
00043 {
00044 public:
00045 UT_PolyField(unsigned x=0);
00046 UT_PolyField(const UT_PolyField &x);
00047 UT_PolyField(const UT_VeryLong &x);
00048 UT_PolyField(const unsigned *data, int nwords);
00049 UT_PolyField(const char *string);
00050 ~UT_PolyField();
00051
00052 UT_PolyField &operator=(const UT_PolyField &x);
00053 UT_PolyField &operator=(uint x);
00054 UT_PolyField &operator=(const char *x);
00055
00056
00057 UT_PolyField &operator+=(const UT_PolyField &x);
00058 UT_PolyField &operator-=(const UT_PolyField &x)
00059 {
00060 return operator+=(x);
00061 }
00062 UT_PolyField &operator*=(const UT_PolyField &x);
00063 UT_PolyField &operator%=(const UT_PolyField &x);
00064 UT_PolyField &operator^=(const UT_PolyField &x);
00065 UT_PolyField &operator<<=(uint shift);
00066 UT_PolyField &operator>>=(uint shift);
00067
00068
00069 friend inline int operator !=(const UT_PolyField &x, const UT_PolyField &y)
00070 { return x.cf(y) != 0; }
00071
00072 friend inline int operator ==(const UT_PolyField &x, const UT_PolyField &y)
00073 { return x.cf(y) == 0; }
00074
00075 friend inline int operator >=(const UT_PolyField &x, const UT_PolyField &y)
00076 { return x.cf(y) >= 0; }
00077
00078 friend inline int operator <=(const UT_PolyField &x, const UT_PolyField &y)
00079 { return x.cf(y) <= 0; }
00080
00081 friend inline int operator > (const UT_PolyField &x, const UT_PolyField &y)
00082 { return x.cf(y) > 0; }
00083
00084 friend inline int operator < (const UT_PolyField &x, const UT_PolyField &y)
00085 { return x.cf(y) < 0; }
00086
00087 static void inverse(UT_PolyField &dest,
00088 const UT_PolyField &a, const UT_PolyField &f);
00089 static void multiply(UT_PolyField &dest,
00090 const UT_PolyField &a, const UT_PolyField &b);
00091 static void add(UT_PolyField &dest,
00092 const UT_PolyField &a, const UT_PolyField &b);
00093 static void modulo(UT_PolyField &dest,
00094 const UT_PolyField &a, const UT_PolyField &f);
00095 static void square(UT_PolyField &dest,
00096 const UT_PolyField &a, const UT_PolyField &f,
00097 const int basis[]);
00098 static void reduce(UT_PolyField &dest,
00099 const UT_PolyField &a, const UT_PolyField &f,
00100 const int basis[]);
00101
00102 int getNumBits() const;
00103 int getBit(int i) const;
00104
00105 int isZero() const;
00106
00107 ut_VeryLongValue *getValue() { return myValue; }
00108 const ut_VeryLongValue *getValue() const { return myValue; }
00109
00110
00111
00112
00113 void printVariable(const char *name) const;
00114 void print( const char *prefix=0,
00115 int radix=16,
00116 const char *suffix="\n" ) const;
00117
00118 void saveToBitStream(UT_BitStream &bs, int nbits);
00119 void loadFromBitStream(UT_BitStream &bs, int nbits);
00120
00121 const unsigned *getData(unsigned &len) const;
00122 void setData(const unsigned *data, unsigned len);
00123
00124 private:
00125 int cf(const UT_PolyField &x) const;
00126 void harden();
00127
00128 ut_VeryLongValue *myValue;
00129 friend class UT_VeryLong;
00130 };
00131
00132 #endif