Question

This is a PLC program so the values can change without knowledge. can someone think of a hash algo that will check if 5 to 10 integers have changed since last cycle. I need this to be as fast as possible.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top