Re: working with byte arrays
From: Peter (-)
Date: 11/13/04
- Next message: Vince: "Another flexgrid question"
- Previous message: Peter: "Re: working with byte arrays"
- In reply to: Rick Rothstein: "Re: working with byte arrays"
- Next in thread: J French: "Re: working with byte arrays"
- Reply: J French: "Re: working with byte arrays"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 13 Nov 2004 10:31:29 +0100
Thanks, Rick
I like this solution because it is simple and easy, Thanks again
I haven't make any performance tests yet but I could think that it would be
faster than my current solution because the whole comparisson is done inside
InstrB(no VB loop is running).
Thanks for the hint to check the size of the arrays, in my project all
bytearrays start at index 0 therefore I just need to concentrate on Ubound.
Regards
Peter
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> schrieb im Newsbeitrag
news:%231WmiwNyEHA.3024@TK2MSFTNGP14.phx.gbl...
>> I have also made a function
>> IsEqualByte(a() as byte,b() as byte) as boolean
>> because you can not do something like
>> if a=b then...
>> My IsEqualByte just compares each byte of both arrays, to my surprise
> a byte
>> array comparisson with 1MB of size was very fast
>> for i=0 toUBound(a) 'as I use the bytearrays as a replacement for
> strings
>> all arrays start at index 0
>> if a(i)<>b(i) then...
>> next i
>> If you know a better way to compare two byte arrays then please let me
> know.
>
> Not sure if this is "better", but you could use your just-gained
> knowledge of InstrB...
>
> Function AreArraysEqual(A() As Byte, B() As Byte) As Boolean
> If InStrB(1, A, B) = 1 And _
> LBound(A) = LBound(B) And UBound(A) = UBound(B) Then
> AreArraysEqual = True
> End If
> End Function
>
> or, as a one-liner....
>
> Function AreArraysEqual(A() As Byte, B() As Byte) As Boolean
> AreArraysEqual = (InStrB(1, A, B) = 1 And _
> LBound(A) = LBound(B) And UBound(A) = UBound(B))
> End Function
>
>
> Now, the criteria for equality above is that not only are they
> byte-for-byte equivalent, but that the two arrays both have the same
> lower and upper bounds. If you always start all of your arrays with the
> same lower bound, then these can be simplified to these...
>
> Function AreArraysEqual(A() As Byte, B() As Byte) As Boolean
> If InStrB(1, A, B) = 1 And _
> UBound(A) = UBound(B) Then
> AreArraysEqual = True
> End If
> End Function
>
> or, as a one-liner....
>
> Function AreArraysEqual(A() As Byte, B() As Byte) As Boolean
> AreArraysEqual = (InStrB(1, A, B) = 1 And _
> UBound(A) = UBound(B))
> End Function
>
> Now, if you don't care about the equality of the array bounds, only that
> the arrays are the same size and that each of their positional
> equivalent values are equal, then the above could be modified as
> follows...
>
> Function AreArraysEqual(A() As Byte, B() As Byte) As Boolean
> If InStrB(1, A, B) = 1 And _
> UBound(A) - LBound(A) = UBound(B) - LBound(B) Then
> AreArraysEqual = True
> End If
> End Function
>
> or, as the one-liner...
>
> Function AreArraysEqual(A() As Byte, B() As Byte) As Boolean
> AreArraysEqual = (InStrB(1, A, B) = 1 And _
> UBound(A) - LBound(A) = UBound(B) - LBound(B))
> End Function
>
> Rick - MVP
>
- Next message: Vince: "Another flexgrid question"
- Previous message: Peter: "Re: working with byte arrays"
- In reply to: Rick Rothstein: "Re: working with byte arrays"
- Next in thread: J French: "Re: working with byte arrays"
- Reply: J French: "Re: working with byte arrays"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|