Answer the question
In order to leave comments, you need to log in
How to get the numeric hash of a file?
There are a lot of files. But based on the content, you need to generate a unique name with the following requirements:
- the name contains 0-9 and az (no capital letters)
- the shorter the name, the better
- you need to minimize collisions
- for the same files - the same name.
- should not load the server.
Md5 creates long files, I want to reduce their number.
Answer the question
In order to leave comments, you need to log in
Calculate the hash of each file. If such a hash has already been met - give the same name as before given the same hash. If not met - give a new name.
You generate a new name with the simplest increment. Those. the first file is "0". The second file is "1". The third file is "2". The tenth file is "a".
This approach is not rational if you later need to determine whether there is already a file with such a hash, because. the filename does not reflect the hash. But there is no mention of this in the terms. Well and as a last resort you can store the table "hash-name".
CRC-4; 2 CRC-8; 3 CRC-16; 4 CRC-32 choose which one you like best. But uniqueness is not guaranteed. Guarantees only that for the same files will be the same.
Want to get a short name = get a renaming problem when there are a lot of files and collisions appear
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question