Logging 事件相关向量时钟的比较
我有一堆日志文件,其中包括事件日志及其向量时钟。现在,在比较任意两个事件的向量时钟时,取向量时钟每个分量的平方和的根,并使用结果与另一个进行比较,然后得出值较小的一个在另一个之前的结论,是否正确 不,如果有办法把它降到一个值,我们就用它来代替向量 要比较向量时钟,需要逐段比较整个向量Logging 事件相关向量时钟的比较,logging,event-log,distributed-system,vector-clock,Logging,Event Log,Distributed System,Vector Clock,我有一堆日志文件,其中包括事件日志及其向量时钟。现在,在比较任意两个事件的向量时钟时,取向量时钟每个分量的平方和的根,并使用结果与另一个进行比较,然后得出值较小的一个在另一个之前的结论,是否正确 不,如果有办法把它降到一个值,我们就用它来代替向量 要比较向量时钟,需要逐段比较整个向量 class VectorClock { private long[] clocks; ... /** * This is before other iff both conditi
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;
}
}
类向量时钟{
私人长时钟;
...
/**
*这是在满足以下两个条件之前:
*-每个进程的时钟小于或等于其他进程中的自身时钟;以及
*-至少有一个进程的时钟严格低于其
*在其他地方拥有自己的时钟
*/
公共布尔值isBefore(矢量时钟其他){
布尔值isBefore=false;
对于(int i=0;i0)
return false;//注意,即使isBefore为true,也可能返回false
否则如果(cmp<0)
isBefore=true;
}
返回之前;
}
}
您可以仅使用最小值和最大值进行不太精确的传球:
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;
}
}
类向量时钟摘要{
私有长最小值,最大值;
...
公共tribool isBefore(VectorClock其他){
如果(最大值<其他最小值)
返回true;
否则如果(最小值>其他最大值)
返回false;
其他的
也许会回来;
}
}
谢谢Michael,我最终使用了您上面建议的方法。