1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | // $Id: cf_generator.cc,v 1.1 1997-04-07 15:06:30 schmidt Exp $ |
---|
3 | |
---|
4 | /* |
---|
5 | $Log: not supported by cvs2svn $ |
---|
6 | Revision 1.0 1996/05/17 10:59:43 stobbe |
---|
7 | Initial revision |
---|
8 | |
---|
9 | */ |
---|
10 | |
---|
11 | #include <config.h> |
---|
12 | |
---|
13 | #include "assert.h" |
---|
14 | |
---|
15 | #include "cf_defs.h" |
---|
16 | #include "cf_generator.h" |
---|
17 | #include "imm.h" |
---|
18 | #include "gfops.h" |
---|
19 | #include "ffops.h" |
---|
20 | |
---|
21 | bool FFGenerator::hasItems() const |
---|
22 | { |
---|
23 | return current < ff_prime; |
---|
24 | } |
---|
25 | |
---|
26 | CanonicalForm FFGenerator::item() const |
---|
27 | { |
---|
28 | ASSERT( current < ff_prime, "no more items" ); |
---|
29 | return CanonicalForm( int2imm_p( current ) ); |
---|
30 | } |
---|
31 | |
---|
32 | void FFGenerator::next() |
---|
33 | { |
---|
34 | ASSERT( current < ff_prime, "no more items" ); |
---|
35 | current++; |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | GFGenerator::GFGenerator() |
---|
40 | { |
---|
41 | current = gf_zero(); |
---|
42 | } |
---|
43 | |
---|
44 | bool GFGenerator::hasItems() const |
---|
45 | { |
---|
46 | return ( current != gf_q + 1 ); |
---|
47 | } |
---|
48 | |
---|
49 | void GFGenerator::reset() |
---|
50 | { |
---|
51 | current = gf_zero(); |
---|
52 | } |
---|
53 | |
---|
54 | CanonicalForm GFGenerator::item() const |
---|
55 | { |
---|
56 | ASSERT( current != gf_q + 1, "no more items" ); |
---|
57 | return CanonicalForm( int2imm_gf( current ) ); |
---|
58 | } |
---|
59 | |
---|
60 | void GFGenerator::next() |
---|
61 | { |
---|
62 | ASSERT( current != gf_q + 1, "no more items" ); |
---|
63 | if ( gf_iszero( current ) ) |
---|
64 | current = 0; |
---|
65 | else if ( current == gf_q1 - 1 ) |
---|
66 | current = gf_q + 1; |
---|
67 | else |
---|
68 | current++; |
---|
69 | } |
---|
70 | |
---|
71 | AlgExtGenerator::AlgExtGenerator() |
---|
72 | { |
---|
73 | ASSERT( 0, "not a valid generator" ); |
---|
74 | } |
---|
75 | |
---|
76 | AlgExtGenerator::AlgExtGenerator( const AlgExtGenerator & ) |
---|
77 | { |
---|
78 | ASSERT( 0, "not a valid generator" ); |
---|
79 | } |
---|
80 | |
---|
81 | AlgExtGenerator& AlgExtGenerator::operator= ( const AlgExtGenerator & ) |
---|
82 | { |
---|
83 | ASSERT( 0, "not a valid generator" ); |
---|
84 | return *this; |
---|
85 | } |
---|
86 | |
---|
87 | AlgExtGenerator::AlgExtGenerator( const Variable & a ) |
---|
88 | { |
---|
89 | ASSERT( a.level() < 0, "not an algebraic extension" ); |
---|
90 | ASSERT( getCharacteristic() > 0, "not a finite field" ); |
---|
91 | algext = a; |
---|
92 | n = degree( getMipo( a ) ); |
---|
93 | gens = new CFGenerator * [n]; |
---|
94 | nomoreitems = false; |
---|
95 | for ( int i = 0; i < n; i++ ) |
---|
96 | gens[i] = CFGenFactory::generate(); |
---|
97 | } |
---|
98 | |
---|
99 | AlgExtGenerator::~AlgExtGenerator() |
---|
100 | { |
---|
101 | for ( int i = 0; i < n; i++ ) |
---|
102 | delete gens[i]; |
---|
103 | delete [] gens; |
---|
104 | } |
---|
105 | |
---|
106 | void AlgExtGenerator::reset() |
---|
107 | { |
---|
108 | for ( int i = 0; i < n; i++ ) |
---|
109 | gens[i]->reset(); |
---|
110 | nomoreitems = false; |
---|
111 | } |
---|
112 | |
---|
113 | CanonicalForm AlgExtGenerator::item() const |
---|
114 | { |
---|
115 | ASSERT( ! nomoreitems, "no more items" ); |
---|
116 | CanonicalForm result = 0; |
---|
117 | for ( int i = 0; i < n; i++ ) |
---|
118 | result += power( algext, i ) * gens[i]->item(); |
---|
119 | return result; |
---|
120 | } |
---|
121 | |
---|
122 | void AlgExtGenerator::next() |
---|
123 | { |
---|
124 | ASSERT( ! nomoreitems, "no more items" ); |
---|
125 | int i = 0; |
---|
126 | bool stop = false; |
---|
127 | while ( ! stop && i < n ) { |
---|
128 | gens[i]->next(); |
---|
129 | if ( ! gens[i]->hasItems() ) { |
---|
130 | gens[i]->reset(); |
---|
131 | i++; |
---|
132 | } |
---|
133 | else |
---|
134 | stop = true; |
---|
135 | } |
---|
136 | if ( ! stop ) |
---|
137 | nomoreitems = true; |
---|
138 | } |
---|
139 | |
---|
140 | CFGenerator * CFGenFactory::generate() |
---|
141 | { |
---|
142 | ASSERT( getCharacteristic() > 0, "not a finite field" ); |
---|
143 | if ( getGFDegree() > 1 ) |
---|
144 | return new GFGenerator(); |
---|
145 | else |
---|
146 | return new FFGenerator(); |
---|
147 | } |
---|