Why not just check them against a copy of the previous set of values?
The effort to simply check all 10 is linear, small and constant. It is unlikely that a hash function would be faster (you can't avoid reading the values, and that's pretty much all the work required to do a compare), and even it were, having the same hash code doesn't tell you the values haven't changed, so you still have to compare all 10 sometimes.
If getting the answer wrong occasionally is OK, you could just XOR all ten values (assumed to be modest size binary integers) for a hashcode, and check against that. That would avoid reading the old/new values, cutting the read count in half. Given all the other work the PLC is doing, I doubt if this savings is anything other than nanoscopic.
发布评论
评论(1)
为什么不直接对照前一组值的副本来检查它们呢?
简单地检查所有 10 项的工作量是线性的、小且恒定的。哈希函数不太可能更快(您无法避免读取值,这几乎是进行比较所需的所有工作),即使是这样,具有相同的哈希码也不会告诉您值没有改变,所以有时您仍然必须比较所有 10 个值。
如果偶尔得到错误的答案是可以的,您可以对哈希码的所有十个值(假设是适当大小的二进制整数)进行异或,然后进行检查。这将避免读取旧/新值,从而将读取计数减少一半。考虑到 PLC 正在做的所有其他工作,我怀疑这种节省是否只是纳米级的。
Why not just check them against a copy of the previous set of values?
The effort to simply check all 10 is linear, small and constant. It is unlikely that a hash function would be faster (you can't avoid reading the values, and that's pretty much all the work required to do a compare), and even it were, having the same hash code doesn't tell you the values haven't changed, so you still have to compare all 10 sometimes.
If getting the answer wrong occasionally is OK, you could just XOR all ten values (assumed to be modest size binary integers) for a hashcode, and check against that. That would avoid reading the old/new values, cutting the read count in half. Given all the other work the PLC is doing, I doubt if this savings is anything other than nanoscopic.