python-intelhex / intelhex

Python IntelHex library
BSD 3-Clause "New" or "Revised" License
198 stars 106 forks source link

Check two IntelHex objects equality #57

Open diggit opened 2 years ago

diggit commented 2 years ago

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 commented 2 years ago

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

bialix commented 2 years ago

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

diggit commented 2 years ago

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.

bialix commented 2 years ago

Unfortunately, internally it has to repack data for comparing.

diggit commented 2 years ago

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?

bialix commented 2 years ago

Yes, that's correct.

bialix commented 2 years ago

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.