algorithm - Checksum for an integer array? -


i have array of size 4,9,16 or 25 (according input) , numbers in array same less 1 (if array size 9 biggest element in array 8) the numbers start 0 , algorithm generate sort of checksum array can compare 2 arrays equal without looping through whole array , checking each element 1 one.

where can sort of information? need simple possible. thank you.

edit: clear on want:

-all numbers in array distinct, [0,1,1,2] not valid because there repeated element (1)

-the position of numbers matter, [0,1,2,3] not same [3,2,1,0]

-the array contain number 0, should taken consideration.

edit:

okay tried implement fletcher's algorithm here: http://en.wikipedia.org/wiki/fletcher%27s_checksum#straightforward

int fletcher(int array[], int size){   int i;   int sum1=0;   int sum2=0;   for(i=0;i<size;i++){     sum1=(sum1+array[i])%255;     sum2=(sum2+sum1)%255;   }   return (sum2 << 8) | sum1; } 

to honest have no idea return line unfortunately, algorithm not work. arrays [2,1,3,0] , [1,3,2,0] same checksum.

edit2:

okay here's one, adler checksum http://en.wikipedia.org/wiki/adler-32#example_implementation

#define mod 65521;  unsigned long adler(int array[], int size){   int i;   unsigned long a=1;   unsigned long b=0;   for(i=0;i<size;i++){     a=(a+array[i])%mod;     b=(b+a)%mod;   }   return (b <<16) | a; } 

this not work. arrays [2,0,3,1] , [1,3,0,2] generate same checksum. i'm losing hope here, ideas?

let's take case of array of 25 integers. explain can contains permutations of unique integers 0 24. according this page, there 25! (25 factorial) possible permutations, 15511210043330985984000000. far more 32bit integer can contains.

the conclusion have collision, no matter how hard try.

now, here simple algorithm account position:

int checksum(int[] array, int size) {   int c = 0;   for(int = 0; < size; i++) {     c += array[i];     c = c << 3 | c >> (32 - 3); // rotate little     c ^= 0xffffffff; // invert fun   }   return c; } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -