Any body know of a method of comparing 2 arrays for eqaulity without comparing every single element. Lets say you have 2 arrays with three elements each and you want to know if they are equal as in:

array1 4,600,3
array2 4,600,3

Yah i know i'm being lazy.
Maybe its impossible.
But any thoughts appreciated.

Posted on 2001-09-13 17:19:16 by titan
My mind is cluttered right now, so excuse me if this is way off (or some of the syntax wrong).

I'll assume your array is bytes..and the names for the pointer to the beginning of each array are "array1" and "array2". Now, I'll assume the length of the arrays (same length) is stored in arraylength

push ebx
push ecx
xor ebx,ebx
xor ecx,ecx
inc ebx
cmp ebx, arraylength
je @F
cmp ,
inc ecx
je @B
pop ecx
pop ebx

I have the feeling i screwed a lot up there.
Posted on 2001-09-13 18:24:13 by vcv
That works fine when pasted into my program.

Clarify something for me

je @B
je @F

These mean jump back and forward respectively?

Never used c so i'm syntactically lost.

Also what is the amount of memory i can jump.

256 bytes i think it was when i used debug.

Maybe half that.

Cant remember.

Posted on 2001-09-13 22:09:37 by titan
Jcc instructions can use a relitive signed 8-bit or 32-bit value. The 16-bit case is special in that it always clears the top word of EIP. So, yes -- the small version of the instruction is limited to a signed byte -128 thru 127.
Posted on 2001-09-13 22:31:44 by bitRAKE

If the arrays are both the same size then you can do a simple byte scan to see if they are different, if the array is made of DWORD members, you can do a DWORD scan which will be a lot faster. Just keep in mind that and array is still a byte sequence in memory so you can for the purpose you have in mind just treat them like a memory comparison.

Posted on 2001-09-13 23:30:47 by hutch--
To follow up Hutch's start, the code would be something like this:

mov esi, offset array1
mov edi, offset array2
mov ecx, array_length

shr ecx, 2 ; divide by 4 for # of DWORD compares
repe cmpsd ; repeat while CX>0, and Z flag = 0
; compare ESI double to EDI double and set Z flag!

mov ecx, array_length
and ecx, 3 ; get any remainder from the inital divide by 4
repe cmpsb ; do the same to the string of bytes

This should work, but i didnt test it.

Hope this helps...
Posted on 2001-09-14 01:47:03 by NaN
Just a note, if you sort the data AS it is entered into the array,
or sort the array before comparison
then a binary search will be your fastest solution. if the array is sorted, the algorithm scans at most [ log N ] + 1 where n is the size of the array.. I need to reseach this to be completely sure
i am correct. so please don't quote me on this.

Posted on 2001-09-14 02:03:41 by prs
Arrays of what?
Posted on 2001-09-14 04:00:11 by The Svin