Fixed pruneKey calculation
This commit is contained in:
parent
7c283aa827
commit
e209e5039c
5 changed files with 22 additions and 12 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@ public class KTConcierge implements Runnable {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
recCheckInWork(keyTree);
|
||||
synchronized (keyTree) {
|
||||
recCheckInWork(keyTree);
|
||||
}
|
||||
}
|
||||
|
||||
private void recCheckInWork(KeyTree node) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue