Skip to content

Commit

Permalink
Add new counter data formatting to debug group
Browse files Browse the repository at this point in the history
  • Loading branch information
rheitjoh committed Jul 8, 2021
1 parent 0d6a34c commit f59146d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public String formatCounterData(String bucketName) {
return String.format("%s\n", bucketName)
+ String.format("%s(Costly) Operations: %d\n", tab, totalNumOpsSqs)
+ String.format("%s%sNon-squarings: %d (%d of which happened during (multi-)exp)\n",
tab, tab, totalNumSqs, expMultiExpNumSqs)
tab, tab, totalNumSqs, expMultiExpNumOps)
+ String.format("%s%sSquarings: %d (%d of which happened during (multi-)exp)\n",
tab, tab, totalNumSqs, expMultiExpNumSqs)
+ String.format("%sInversions: %d (%d of which happened during (multi-)exp)\n",
Expand All @@ -364,10 +364,52 @@ public String formatCounterData(String bucketName) {
/**
* Formats the count data of all buckets for printing.
*
* @param summaryOnly if true, only formats the summed up results across all buckets; otherwise, outputs results
* of every bucket plus the summary
*
* @return a string detailing results of counting
*/
public String formatCounterData() {
public String formatCounterData(boolean summaryOnly) {
StringBuilder result = new StringBuilder();
if (!summaryOnly) {
for (String bucketName : ((DebugGroupImpl) groupTotal.getImpl()).getBucketMap().keySet()) {
result.append(formatCounterData(bucketName));
}
}

long totalNumOps = getNumOpsTotalAllBuckets();
long totalNumSqs = getNumSquaringsTotalAllBuckets();
long totalNumInvs = getNumInversionsTotalAllBuckets();
long totalNumOpsSqs = totalNumOps + totalNumSqs;
long expMultiExpNumOps = totalNumOps - getNumOpsNoExpMultiExpAllBuckets();
long expMultiExpNumSqs = totalNumSqs - getNumSquaringsNoExpMultiExpAllBuckets();
long expMultiExpNumInvs = totalNumInvs - getNumInversionsNoExpMultiExpAllBuckets();
List<Integer> multiExpTerms = getMultiExpTermNumbersAllBuckets();

String tab = " ";
result.append("Combined results of all buckets\n")
.append(String.format("%s(Costly) Operations: %d\n", tab, totalNumOpsSqs))
.append(String.format("%s%sNon-squarings: %d (%d of which happened during (multi-)exp)\n",
tab, tab, totalNumSqs, expMultiExpNumOps))
.append(String.format("%s%sSquarings: %d (%d of which happened during (multi-)exp)\n",
tab, tab, totalNumSqs, expMultiExpNumSqs))
.append(String.format("%sInversions: %d (%d of which happened during (multi-)exp)\n",
tab, totalNumInvs, expMultiExpNumInvs))
.append(String.format("%sExponentiations: %d\n", tab, getNumExpsAllBuckets()))
.append(String.format("%sMulti-exponentiations (number of terms in each): %s\n", tab, multiExpTerms))
.append(String.format("%sgetRepresentation() calls: %d\n",
tab, getNumRetrievedRepresentationsAllBuckets()));

return result.toString();
}

/**
* Formats the count data of all buckets for printing.
*
* @return a string detailing results of counting
*/
public String formatCounterData() {
return formatCounterData(false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.cryptimeleon.math.structures.groups.debug;

import org.cryptimeleon.math.serialization.Representation;
import org.cryptimeleon.math.serialization.annotations.ReprUtil;
import org.cryptimeleon.math.serialization.annotations.Represented;
import org.cryptimeleon.math.structures.groups.GroupElementImpl;
import org.cryptimeleon.math.structures.groups.mappings.impl.HashIntoGroupImpl;
import org.cryptimeleon.math.structures.rings.zn.HashIntoZn;
Expand All @@ -11,6 +13,7 @@
* Allows hashing a byte array to a {@link DebugGroupImpl} via {@link HashIntoZn}.
*/
public class HashIntoDebugGroupImpl implements HashIntoGroupImpl {
@Represented
protected DebugGroupImpl group;
protected HashIntoZn hash;

Expand All @@ -20,12 +23,13 @@ public HashIntoDebugGroupImpl(DebugGroupImpl group) {
}

public HashIntoDebugGroupImpl(Representation repr) {
this(new DebugGroupImpl(repr));
new ReprUtil(this).deserialize(repr);
hash = new HashIntoZn(group.size());
}

@Override
public Representation getRepresentation() {
return group.getRepresentation();
return ReprUtil.serialize(this);
}

@Override
Expand Down

0 comments on commit f59146d

Please sign in to comment.