Need ideas for a compression algorithm

Background: I am creating a crash generation system on the Internet where the user can select fragments for his avatar (for example, body, background, eyes, mouth, jacket, pants, etc.). and then an image is created from these selections. For performance reasons, I then intend to do the following: from the list of selected items, create a file name containing their identifiers, and save the image under this file name. Then, when the request comes for the image, the web server will serve it directly. If the image is not found, the 404-handler will generate it. And then the problem is:

Question: I would like to compress the list of integers as short as possible, consisting only of ASCII characters (used for file names and URLs). Integers will be unique and greater than 0 (0 by itself will not be among them). I expect that there may be about 20 of them, and they will not exceed 200, but this is just an assumption (although I would be surprised if they passed in 500 years). Order is not important.

What do you recommend me to do?

Update: . I seem to have made a fundamental mistake. I wanted to avoid storing each generated avatar in the database, instead storing all the necessary information in the file name. Thus, I was hoping to avoid unnecessary use of the database and thus improve performance. However, today it seemed to me that people might want to change their avatars and expect them to be updated wherever they were used. Therefore, the file name must be constant. This leaves only one option - I will need to save the information about the avatar in the database. And then I could also use a GUID or some other random strings for file names.

Thank you for your help, everyone, and sorry for the false alarm. :(

+3
source share
3

(9 ) , Base64.

+1

, ; ASCII-85 ? http://en.wikipedia.org/wiki/Ascii85

, UTF-8, , , -85.

Doug Currie, ASCII-85 . base64, , .

-1

, md5 , 128- . 32- ASCII- base64 22-.

, , .

This saves a small space for each file name (128 bits instead of 180), and it does not depend on the number of values ​​and the range of each value, so even if you go beyond 20 elements or a maximum value of 500 will not affect the length of the file name.

-1
source

Source: https://habr.com/ru/post/1778554/


All Articles