rebuild CalculateSqmMatrix
This commit is contained in:
@ -89,45 +89,38 @@ std::string SQMTableModel::IntToBinary(int n) {
|
|||||||
return bin;
|
return bin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQMTableModel::CalculateSqmMatrix(int startRow) {
|
void SQMTableModel::CalculateSqmMatrix() {
|
||||||
|
// Clear sqmMatrix
|
||||||
|
sqmMatrix.clear()
|
||||||
|
|
||||||
|
// Calculate binary of exponent
|
||||||
string bin = IntToBinary(exp);
|
string bin = IntToBinary(exp);
|
||||||
binLen = bin.length();
|
binLen = bin.length();
|
||||||
|
|
||||||
// Fill vector with 0
|
// Init BIN Column
|
||||||
vector<int> colSqn, colMul;
|
|
||||||
for (int i = 0; i <= binLen; i++) {
|
|
||||||
colSqn.push_back(0);
|
|
||||||
colMul.push_back(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Initialize bin column
|
|
||||||
vector<int> colBin;
|
vector<int> colBin;
|
||||||
for (int i = 0; i <= binLen; i++) {
|
for (int i = 0; i < binLen; i++) {
|
||||||
colBin.push_back(bin[i] - '0');
|
colBin.push_back(bin[i] - '0');
|
||||||
}
|
}
|
||||||
sqmMatrix.push_back(colBin);
|
sqmMatrix.push_back(colBin);
|
||||||
|
|
||||||
|
// Init SQN & MUL Column
|
||||||
|
vector<int> colSqn, colMul;
|
||||||
|
colSqn.push_back(1);
|
||||||
|
colMul.push_back(base);
|
||||||
sqmMatrix.push_back(colSqn);
|
sqmMatrix.push_back(colSqn);
|
||||||
sqmMatrix.push_back(colMul);
|
sqmMatrix.push_back(colMul);
|
||||||
|
|
||||||
|
|
||||||
for (int i = startRow; i < binLen; i++) {
|
// Calculate SQM
|
||||||
if (i == 0) {
|
for (int i = 0; i < binLen; i++) {
|
||||||
// Initialize first row
|
sqmMatrix.at(1).push_back((sqmMatrix.at(2).at(i - 1) * sqmMatrix.at(2).at(i - 1)) % mod);
|
||||||
sqmMatrix.at(1).at(0) = 1;
|
|
||||||
sqmMatrix.at(2).at(0) = base;
|
if (sqmMatrix.at(0).at(i) == 0) {
|
||||||
|
sqmMatrix.at(2).push_back(sqmMatrix.at(1).at(i));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Square Multiply
|
sqmMatrix.at(2).push_back((sqmMatrix.at(1).at(i) * base) % mod);
|
||||||
sqmMatrix.at(1).at(i) = sqmMatrix.at(2).at(i - 1) * sqmMatrix.at(2).at(i - 1);
|
|
||||||
|
|
||||||
if (sqmMatrix.at(0).at(i) == 0) {
|
|
||||||
sqmMatrix.at(2).at(i) = sqmMatrix.at(1).at(i);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sqmMatrix.at(2).at(i) = sqmMatrix.at(1).at(i) * base;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string IntToBinary(int n);
|
std::string IntToBinary(int n);
|
||||||
void CalculateSqmMatrix(int startRow);
|
void CalculateSqmMatrix();
|
||||||
|
void UpdateSqmMatrix(QModelIndex startIndex);
|
||||||
|
|
||||||
int base;
|
int base;
|
||||||
int exp;
|
int exp;
|
||||||
|
Reference in New Issue
Block a user