in reply to Comparing two arrays
Here’s another way to do it: scan the arrays to convert them to a vector using some form of “run-length encoding.” For instance, a list containing the position of the next '1' and the number of '1's that occur. Now for the magic: use a Digest algorithm of some sort ... could be CRC, SHA1, could be anything ... to convert that vector into a single value that can be used as a hash.
Actually, if you use a truly-decent message digest algorithm, like SHA1, you probably won’t have to do anything else, because one and only one vector will map to the same hash value. You have to preprocess each array one time to compute its message-digest hash, but from there on out you might not have to examine the array contents at all. A comparison of the digests ought to be sufficient. Aside from the overhead of passing through each array one time to calculate its digest, the overhead of laborious comparison ... disappears.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing two arrays
by roboticus (Chancellor) on Dec 16, 2013 at 13:43 UTC | |
by BrowserUk (Patriarch) on Dec 16, 2013 at 13:53 UTC | |
by roboticus (Chancellor) on Dec 16, 2013 at 16:19 UTC | |
by BrowserUk (Patriarch) on Dec 16, 2013 at 17:21 UTC | |
by roboticus (Chancellor) on Dec 16, 2013 at 21:19 UTC | |
| |
by BrowserUk (Patriarch) on Dec 16, 2013 at 16:30 UTC | |
|
Re^2: Comparing two arrays
by choroba (Cardinal) on Dec 16, 2013 at 13:21 UTC | |
|
Re^2: Comparing two arrays
by BrowserUk (Patriarch) on Dec 16, 2013 at 15:23 UTC | |
| |
|
Re^2: Comparing two arrays
by GotToBTru (Prior) on Dec 31, 2013 at 21:38 UTC |