A
A
Alexey Lebedev2015-08-15 10:55:13
ASP.NET
Alexey Lebedev, 2015-08-15 10:55:13

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

4 answer(s)
G
GavriKos, 2015-08-15
@GavriKos

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".

A
Ai Lab, 2015-08-15
@vpuhoff

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.

S
sim3x, 2015-08-15
@sim3x

Want to get a short name = get a renaming problem when there are a lot of files and collisions appear

S
SagePtr, 2015-08-15
@SagePtr

- the shorter the name, the better
- it is necessary to minimize collisions

These two points are mutually exclusive.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question