Fixed pruneKey calculation

This commit is contained in:
armin 2018-04-28 18:53:08 +02:00
parent 7c283aa827
commit e209e5039c
5 changed files with 22 additions and 12 deletions

View file

@ -20,7 +20,7 @@ public class CnC {
public static final int MAX_BITS = 62;
public static void main(String[] args) {
KeyServer kts = KSFactory.build(54, 30, 90, TimeUnit.MINUTES, 0.62f);
KeyServer kts = KSFactory.build(54, 30, 15, TimeUnit.MINUTES, 0.62f);
CommServer server = new CommServer(PORT, kts);
try {
server.listen();

View file

@ -5,6 +5,7 @@ import org.btcollider.cnc.keysrv.impl.keytree.KeyTreeServer;
import org.btcollider.cnc.keysrv.impl.multistage.MultiStagedServer;
public class KSFactory {
private KSFactory() {}
public static KeyServer build(int index, int depth, long maxWorkSpan) {
return build(index, depth, maxWorkSpan, TimeUnit.MILLISECONDS);
@ -16,10 +17,13 @@ public class KSFactory {
public static KeyServer build(int index, int depth, long maxWorkSpan, TimeUnit timeUnit,
float pruneFraction) {
assert (pruneFraction >= 0.0 && pruneFraction <= 1.0);
long maxKey = ((long) 1 << index) | (((long) 1 << index) - 1);
long pruneKey = (long) Math.floor(maxKey * pruneFraction);
long minKey = ((long) 1 << index);
long pruneKey = (long) Math.floor((maxKey - minKey) * pruneFraction) + minKey;
return build(index, depth, maxWorkSpan, timeUnit, pruneKey);
}

View file

@ -16,7 +16,9 @@ public class KTConcierge implements Runnable {
@Override
public void run() {
recCheckInWork(keyTree);
synchronized (keyTree) {
recCheckInWork(keyTree);
}
}
private void recCheckInWork(KeyTree node) {

View file

@ -134,11 +134,11 @@ public class KeyTreeServer implements KeyServer {
}
private void recPrune(BitSet pruneKey, KeyTree node, int curIdx) {
if (node.getValue() && !pruneKey.get(curIdx)) { // node[ix] = 0 and pruneK[ix] = 1 -> path
if (!node.getValue() && pruneKey.get(curIdx)) { // node[ix] = 0 and pruneK[ix] = 1 -> path
// smaller
node.setSearched(true);
return;
} else if (!node.getValue() && pruneKey.get(curIdx)) { // node[ix] = 1 and pruneK[ix] = 0 ->
} else if (node.getValue() && !pruneKey.get(curIdx)) { // node[ix] = 1 and pruneK[ix] = 0 ->
// path
return;
}

View file

@ -81,24 +81,28 @@ public class MultiStagedServer implements KeyServer {
keyRangeBuffer.setInWork(keyRange);
// strip out partition bits -> get subspace KeyRange only
long mask = (long) Math.pow(2, (subIndex + 1)) - 1;
long mask = ((long) 1 << subIndex) - 1;
// add leading bit
long lb = (long) Math.pow(2, (subIndex + 1));
long lb = ((long) 1 << subIndex);
KeyRange secKR =
new KeyRange(((keyRange.getStart() & mask) | lb), ((keyRange.getEnd() & mask) | lb));
KeyRange secKR = new KeyRange(keyRange.getStart() & mask | lb, keyRange.getEnd() & mask | lb);
secKTS.setInWork(secKR);
}
@Override
public void setSearched(KeyRange keyRange) {
keyRangeBuffer.setSearched(keyRange);
// strip out partition bits -> get subspace KeyRange only
long mask = (long) Math.pow(2, (subIndex + 1)) - 1;
long mask = ((long) 1 << subIndex) - 1;
// add leading bit
long lb = (long) Math.pow(2, (subIndex + 1));
long lb = ((long) 1 << subIndex);
KeyRange secKR =
new KeyRange(((keyRange.getStart() & mask) | lb), ((keyRange.getEnd() & mask) | lb));
KeyRange secKR = new KeyRange(keyRange.getStart() & mask | lb, keyRange.getEnd() & mask | lb);
secKTS.setSearched(secKR);
}