Tanto per far inviperire cesko e visto che non ti 'frega' della collisione:
Provo anche cosi', anche se shellare non mi appassiona troppo... ora nel fine settimana provo. Attualmente faccio cosi':
PUBLIC FUNCTION CompareFiles(snew AS String, sold AS String) AS Boolean
DIM file1, file2 AS stream
DIM s1, s2 AS String
DIM res AS Boolean
res = TRUE
IF Stat(snew).size <> Stat(sold).Size THEN
res = FALSE
ENDIF
IF res = TRUE THEN
file1 = OPEN snew FOR READ
file2 = OPEN sold FOR READ
DO
'2048 e' un valore di prova, che cambiero' a seconda dei test
READ #file1, s1, -2048
READ #file2, s2, -2048
IF s1 <> s2 THEN
res = FALSE
BREAK
ENDIF
IF Len(s1) <> 2048 THEN BREAK
LOOP
CLOSE #file1
CLOSE #file2
ENDIF
RETURN res
END
La cosa che mi da' fastidio di cio' e' il fatto di dovere fare una funzione apposita, quella che mi piace e' invece il fatto che mi risparmio un componente...
Girellando sulla Wiki ho trovato questa funzione in C++ sulla Wiki francese:
unsigned long hash(unsigned char *str)
{
unsigned long hash = 5381;
while(*str!='\0') {
int c = *str;
/* hash = hash*33 + c */
hash = ((hash << 5) + hash) + c;
str++;
}
return hash;
}
E' la funzione di hash di Bernstein, una delle più semplici. Non dovrebbe essere un grosso problema adattarla in Gambas e farci un piccolo algoritmo di checksum.