intelhex icon indicating copy to clipboard operation
intelhex copied to clipboard

Check two IntelHex objects equality

Open diggit opened this issue 3 years ago • 7 comments

Hi, I am looking for effective way of hex file data comparison, mainly equality check. Is there already some effective way of comparison?

Did you consider overriding of __eq__ ?

diggit avatar Mar 30 '22 12:03 diggit

~~Using equality check over output of segments() seems to work.~~ My second question remains.

diggit avatar Mar 30 '22 13:03 diggit

Due to internal data storage model there is no effective way for byte to byte comparison, that's actually O(n) operation.

bialix avatar Mar 30 '22 15:03 bialix

By "effective way", I meant something what does not have to repack data and do other unnecessary operations. Preferably in __eq__. O(n) is fine and probably expected.

diggit avatar Mar 31 '22 06:03 diggit

Unfortunately, internally it has to repack data for comparing.

bialix avatar Mar 31 '22 07:03 bialix

I peeked into sources and IntelHex._buf seems like dict of address->data. Equality comparison then would be just comparison of those dicts when taking account few other option (offset,...). Am I wrong?

diggit avatar Mar 31 '22 12:03 diggit

Yes, that's correct.

bialix avatar Mar 31 '22 13:03 bialix

Sorry, it seems I haven't thought enough about your question. So basically all you need is to compare this._buf to other._buf. Yep, that should be easy addition. Patches welcome, and please provide some tests.

~~Also, there is hexdiff.py script to compare two Intel Hex files, you might look into using it.~~ Actually, no, sorry.

bialix avatar Mar 31 '22 13:03 bialix