I want to create a file index on EEPROM for memory disk.
In order to recude cost, I have to save shortPathFilename ( 8.3 file format) instead of full name, but I can't sure, is that OK ( all function correct ) to save 8.3 filename only?
Is it possbile to happen any error on 8.3 format file name instead of full filename.
The 8.3 version of the full name uses the first 6 (if all DOS "legal") characters of the full name and then a ~ with a sequential number; so if there are some file names that start the same, the first one created would have an 8.3 flename ending ~1, the next one would end ~2 etc. So they are unique. But say the earliest one gets deleted after you did the transfer, and then another file of "like" name gets created, i think it would be ~1 and the index would be pointing to the "wrong" file. That is probably worse than if that new file was created; a non-existant file is a lot easier to determine than the fact of a replacement IF only the 8.3 name was saved.
You can do that, the VFAT file system takes care of the 8.3 names remaining unique.
If you're really strapped for space you could save some hash of the long file name as 32 or 64 bits, that would be more compact and would work with other file systems, like NTFS, that don't make short names.
One good hash algorithm is to add up all the characters, multiplying the total by some prime (like 13) each time. Simple and you only risk a 1 in 2^32 or 2^64 chance of collision.
If number A is worthless, then number A*B will be worthless since B is some arbitrary un-related number (odd, even, integer, rational, irrational, whatever). There would seem to be at least one step that is missing...
On Sat, 04 Mar 2006 19:29:01 -0800, Boki top-posted:
$ cat hasher.c /* hasher.c */ #include #include
char mystring[256];
int main(int argc, char **argv) { unsigned int tot; int i, j; tot = 0; for (;;) { printf("-> "); gets (mystring); if ((j = strlen(mystring)) < 1) exit(0); for (i = 0; i < j; i++) { tot = (tot * 13) + (unsigned int) mystring[i]; tot %= 4999; } printf("%s hashes to %d\\n", mystring, tot); } }
$ gcc hasher.c -o hasher /tmp/cc0qtaZC.o(.text+0x30): In function `main': : warning: the `gets' function is dangerous and should not be used. richgrise@thunderbird:~/Programming/C/hash $ hasher
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.