gpt4 book ai didi

logging - 用于事件关联的矢量时钟的比较

转载 作者:行者123 更新时间:2023-12-04 04:22:01 25 4
gpt4 key购买 nike

我有一堆日志文件,其中包含事件日志以及记录在其中的矢量时钟。现在在比较任意两个事件的矢量时钟时,是否对矢量时钟的每个分量的平方和取根,并用结果与另一个的结果进行比较,然后得出结论为较小的值在另一个之前?

最佳答案

不,如果有办法将其减少到一个值,我们将使用它而不是向量!

要比较矢量时钟,您需要分段比较整个矢量。

class VectorClock {
private long[] clocks;
...
/**
* This is before other iff both conditions are met:
* - each process's clock is less-than-or-equal-to its own clock in other; and
* - there is at least one process's clock which is strictly less-than its
* own clock in other
*/
public boolean isBefore(VectorClock other) {
boolean isBefore = false;
for (int i = 0; i < clocks.length; i++) {
int cmp = Long.compare(clocks[i], other.clocks[i]);
if (cmp > 0)
return false; // note, could return false even if isBefore is true
else if (cmp < 0)
isBefore = true;
}
return isBefore;
}
}

您可以仅使用最小值和最大值进行不太准确的传递:
class VectorClockSummary {
private long min, max;
...
public tribool isBefore(VectorClockSummary other) {
if (max < other.min)
return true;
else if (min > other.max)
return false;
else
return maybe;
}
}

关于logging - 用于事件关联的矢量时钟的比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13557435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com