Skip to content

Commit 43eac1c

Browse files
committed
GFRevシフトキャッシュ
1 parent 596c9d3 commit 43eac1c

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/main/java/net/siisise/math/GFRev.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class GFRev {
4545
public GFRev(long[] l) {
4646

4747
long[] n = l.clone();
48+
shL = new long[l.length * 64][];
4849
for (int i = 0; i < l.length * 64; i++) {
4950
shL[i] = n;
5051
n = x(n);
@@ -76,9 +77,10 @@ public long[] mul(long[] a) {
7677
for ( int j = 0; j < 64; j++ ) {
7778
if ( c << j < 0) {
7879
int k = i * 64 + j;
79-
for (int l = 0; l < a.length; l++) {
80-
v[l] ^= shL[k][l];
81-
}
80+
Bin.xorl(v, shL[k]);
81+
//for (int l = 0; l < a.length; l++) {
82+
// v[l] ^= shL[k][l];
83+
//}
8284
}
8385
}
8486
}
@@ -113,14 +115,20 @@ public long[] mul(long[] a, long[] b) {
113115
public long[] inv(long[] a) {
114116
return pow(a, INV_POW);
115117
}
116-
118+
119+
public long[] inv() {
120+
return pow(INV_POW);
121+
}
122+
117123
/**
118124
* 累乗.
119125
* @param a 底
120126
* @param p exponent 1以上
121127
* @return
122128
*/
123129
public long[] pow(long[] a, BigInteger p) {
130+
return new GFRev(a).pow(p);
131+
/*
124132
if ( p.equals(BigInteger.ONE)) {
125133
return a;
126134
} else {
@@ -136,6 +144,27 @@ public long[] pow(long[] a, BigInteger p) {
136144
}
137145
return n;
138146
}
147+
*/
148+
}
149+
150+
public long[] pow(BigInteger p) {
151+
long[] a = shL[0];
152+
if ( p.equals(BigInteger.ONE)) {
153+
return a;
154+
} else {
155+
long[] n;
156+
if ( p.mod(THREE).equals(BigInteger.ZERO)) {
157+
n = pow(p.divide(THREE));
158+
GFRev gfn = new GFRev(n);
159+
return gfn.mul(gfn.mul(n));
160+
}
161+
n = pow( p.divide(TWO));
162+
n = mul(n,n);
163+
if ( !p.mod(TWO).equals(BigInteger.ZERO)) {
164+
n = mul(n);
165+
}
166+
return n;
167+
}
139168
}
140169

141170
}

0 commit comments

Comments
 (0)