{"id":377445,"date":"2024-05-29T15:00:56","date_gmt":"2024-05-29T15:00:56","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=377445"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=377445","title":{"rendered":"<span>\u00abHello, World!\u00bb \u043e\u0442 \u043c\u0438\u0440\u0430 \u0441\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0425\u0430\u0444\u0444\u043c\u0430\u043d\u0430<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u0443\u044e \u0442\u0435\u043c\u0443 \u0431\u044b\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u0435 \u043e\u0434\u043d\u0430 \u0441\u043e\u0442\u043d\u044f \u0441\u0442\u0430\u0442\u0435\u0439, \u043d\u043e \u0432\u043e \u0432\u0441\u0435\u0445, \u0447\u0442\u043e \u0432\u0438\u0434\u0435\u043b, \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u043e \u0442\u0438\u043f\u0443 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u043e\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0445\u043e\u0442\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0447\u0430\u0441\u0442\u043e\u0442 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f \u0438 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0434\u0432\u0435 \u0431\u0443\u043a\u0432\u044b \u0438\u0437 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0442\u0435\u043b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C++.<\/p>\n<p>\u041a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0425\u0430\u0444\u0444\u043c\u0430\u043d\u0430 \u0434\u043b\u044f \u0441\u0436\u0430\u0442\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0447\u0430\u0441\u0442\u043e\u0442 \u043a\u0430\u0436\u0434\u043e\u0439 \u0431\u0443\u043a\u0432\u044b \u0432 \u0444\u0430\u0439\u043b\u0435 \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0431\u0443\u043a\u0432\u044b \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0436\u0430\u0442\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0436\u0430\u0442\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0434\u0432\u0430 \u0447\u0442\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u0431\u0443\u043a\u0432, \u043f\u043e\u0442\u043e\u043c \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0431\u0443\u043a\u0432\u0443 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430 \u043d\u0430 \u0435\u0451 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0451\u0442\u0430 \u0447\u0430\u0441\u0442\u043e\u0442 \u0431\u0443\u043a\u0432 \u0432 \u0444\u0430\u0439\u043b\u0435. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0434\u043b\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0432\u0435\u043a\u0442\u043e\u0440 <strong>letter_count<\/strong>, \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 &lt;\u0431\u0443\u043a\u0432\u0430, \u0447\u0430\u0441\u0442\u043e\u0442\u0430>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0447\u0430\u0441\u0442\u043e\u0442\u0435 \u0431\u0443\u043a\u0432\u044b, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443, \u0440\u0430\u0432\u043d\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0431\u0443\u043a\u0432\u044b \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435.<\/p>\n<pre><code class=\"cpp\">void count_frequency(const std::string &amp;filename, std::vector&lt;uint64_t> &amp;letter_count) {     std::ifstream file(filename, std::ios_base::binary);      uint8_t c;      while ( file.read((char* )&amp;c, 1) )         letter_count[c]++;      file.close(); }  struct data_about_letter_vector {     std::vector&lt;uint8_t> letter_vector;     uint64_t count; };  void create_alphabet(std::vector&lt;data_about_letter_vector> &amp;alphabet, const std::vector&lt;uint64_t> &amp;letter_count) {     size_t size = 0;          for (size_t i = 0; i &lt; 256; i++)          if ( letter_count[i] ) {             alphabet[size].letter_vector.push_back(i);             alphabet[size].count = letter_count[i];              size++;         }          alphabet.resize(size); }  void count_frequency_and_create_alphabet(const std::string &amp;filename, std::vector&lt;data_about_letter_vector> &amp;alphabet) {     std::vector&lt;uint64_t> letter_count(256);     count_frequency(filename, letter_count);      create_alphabet(alphabet, letter_count); }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0431\u0443\u043a\u0432\u044b \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5c1\/f82\/ffc\/5c1f82ffcebf72287ab0236c8c6bf042.png\" alt=\"\u0421\u043b\u043e\u0432\u0435\u0441\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432.\" title=\"\u0421\u043b\u043e\u0432\u0435\u0441\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432.\" width=\"1004\" height=\"375\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5c1\/f82\/ffc\/5c1f82ffcebf72287ab0236c8c6bf042.png\"\/><\/p>\n<div><figcaption>\u0421\u043b\u043e\u0432\u0435\u0441\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432.<\/figcaption><\/div>\n<\/figure>\n<pre><code class=\"cpp\">bool compare(const data_about_letter_vector &amp;left, const data_about_letter_vector &amp;right) {     return left.count > right.count; }  void create_elementary_codes(std::vector&lt;uint64_t> &amp;B, std::vector&lt;uint8_t> &amp;shift, const std::string &amp;filename) {        std::vector&lt;data_about_letter_vector> alphabet(256);     count_frequency_and_create_alphabet(filename, alphabet);      size_t size = alphabet.size();          std::sort(alphabet.begin(), alphabet.end(), compare);      while ( size > 2 ) {         size_t pos0 = size - 2, pos1 = pos0 + 1;          for ( uint8_t a : alphabet[pos0].letter_vector )             shift[a]++;          for ( uint8_t a : alphabet[pos1].letter_vector ) {             B[a] = ( 1ULL &lt;&lt; shift[a] ) | B[a];             shift[a]++;         }          data_about_letter_vector temp;          for ( uint8_t a : alphabet[pos0].letter_vector )             temp.letter_vector.push_back(a);          for ( uint8_t a : alphabet[pos1].letter_vector )             temp.letter_vector.push_back(a);                  temp.count = alphabet[pos0].count + alphabet[pos1].count;          size -= 2;          alphabet.resize(size);          uint8_t pos_to_insert = size;          while ( pos_to_insert &amp;&amp; ( alphabet[ pos_to_insert - 1 ].count &lt; temp.count ) )             pos_to_insert--;          alphabet.insert(alphabet.begin() + pos_to_insert, temp);          size++;     }          if ( size == 1 )          shift[ alphabet[0].letter_vector[0] ]++;     else {         size_t pos0 = size - 2, pos1 = pos0 + 1;          for ( uint8_t a : alphabet[pos0].letter_vector )             shift[a]++;          for ( uint8_t a : alphabet[pos1].letter_vector ) {             B[a] = ( 1ULL &lt;&lt; shift[a] ) | B[a];             shift[a]++;         }     } }<\/code><\/pre>\n<p>\u042d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0435 \u043a\u043e\u0434\u044b \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u0441\u0436\u0430\u0442\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0435 \u043a\u043e\u0434\u044b, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0434\u0432\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u043e\u0434\u0438\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u0431\u0443\u043a\u0432 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430(\u0432\u0435\u043a\u0442\u043e\u0440 <strong>B<\/strong>), \u0434\u0440\u0443\u0433\u043e\u0439 \u0434\u043b\u0438\u043d\u0443 \u044d\u0442\u043e\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430(\u0432\u0435\u043a\u0442\u043e\u0440 <strong>shift<\/strong>). \u041f\u043e\u043c\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u043e\u0434\u0438\u043d \u0438\u0437\u044a\u044f\u043d, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0431\u0430\u0439\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0431\u0430\u0439\u0442 \u043d\u0435 \u0431\u044b\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0448\u0443 \u0435\u0433\u043e \u0434\u043b\u0438\u043d\u0443 \u0432 \u0431\u0438\u0442\u0430\u0445 \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f.<\/p>\n<pre><code class=\"cpp\">void write_elementary_codes_into_file(const std::vector&lt;uint64_t> &amp;B, const std::vector&lt;uint8_t> &amp;shift, const uint8_t &amp;length_of_last_byte, const uint8_t &amp;last_byte) {     std::ofstream out(\"data_for_decompress.bin\", std::ios_base::binary);      out.write((char* )&amp;length_of_last_byte, 1);          out.write((char* )&amp;last_byte, 1);      out.write((char* )&amp;( B[0] ), 2048);      out.write((char* )&amp;( shift[0] ), 256);      out.close(); }  void compress_file(const std::vector&lt;uint64_t> &amp;B, const std::vector&lt;uint8_t> &amp;shift, const std::string &amp;filename) {     std::cout &lt;&lt; \"\u041d\u0430\u0447\u0430\u043b\u043e \u0441\u0436\u0430\u0442\u0438\u044f\\n\";      uint8_t byte = 0, length = 0;      std::ofstream out(\"compressed_data.bin\", std::ios_base::binary);     std::ifstream file(filename, std::ios_base::binary);      uint8_t c;      while ( file.read((char* )(&amp;c), 1) ) {         uint64_t elementary_code = B[c];         uint8_t s = shift[c];         uint64_t mask = ( 1ULL &lt;&lt; s ) - 1;          while ( s ) {             uint8_t need_bit_length = 8 - length;              if ( need_bit_length > s ) {                 byte |= elementary_code &lt;&lt; ( need_bit_length - s );                 length += s;                 s = 0;             }             else {                 s -= need_bit_length;                 byte |= elementary_code >> s;                 mask >>= need_bit_length;                 elementary_code &amp;= mask;                 out.write((char* )&amp;byte, 1);                 byte = 0;                 length = 0;             }         }     }      out.close();     file.close();      write_elementary_codes_into_file(B, shift, length, byte); }<\/code><\/pre>\n<p>\u0421 \u0441\u0436\u0430\u0442\u0438\u0435\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438, \u0434\u0430\u043b\u0435\u0435 \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u0435. \u0414\u043b\u044f \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0440\u0430\u043d\u0435\u0435 \u0432 \u0444\u0430\u0439\u043b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u043c \u043a\u043e\u0434\u0430\u043c.<\/p>\n<p>\u041a\u043e\u0434 \u0434\u043b\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0431\u044b\u043b \u0443\u043a\u0440\u0430\u0434\u0435\u043d, \u043d\u043e \u0431\u044b\u043b\u0430 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u043e. <\/p>\n<p>\u041f\u043e\u0438\u0441\u043a \u043f\u043e \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c\u0443 \u0434\u0435\u0440\u0435\u0432\u0443 \u0434\u043b\u044f \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u0431\u0443\u043a\u0432\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043e\u0442 \u043a\u043e\u0440\u043d\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e \u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c(1 &#8212; \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043f\u0440\u0430\u0432\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043c\u043a\u0443, 0 &#8212; \u043a \u043b\u0435\u0432\u043e\u043c\u0443) \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043c \u043b\u0438\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u0443\u043a\u0432\u0443. <strong>way<\/strong> &#8212; \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u043a\u043e\u0434, \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 <strong>B<\/strong>, <strong>way_length<\/strong> &#8212; \u044d\u0442\u043e \u0434\u043b\u0438\u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 <strong>shift.<\/strong><\/p>\n<pre><code class=\"cpp\">class Tree_element {     public:         bool data_exist;         uint8_t data;         Tree_element* left;         Tree_element* right;         Tree_element(); };  class Binary_tree {     public:         Tree_element* root;         Binary_tree();         ~Binary_tree();         void delete_tree(Tree_element* current);         void insert(const uint8_t &amp;letter, const uint64_t &amp;way, const uint8_t &amp;way_length); };  Tree_element::Tree_element()  {     data_exist = false;     left = nullptr;     right = nullptr; }  Binary_tree::Binary_tree() {     root = new Tree_element(); }  void Binary_tree::delete_tree(Tree_element* current) {     if ( current != nullptr ) {         delete_tree(current->left);         delete_tree(current->right);         delete current;     } }  Binary_tree::~Binary_tree() {     delete_tree(root); }  void Binary_tree::insert(const uint8_t &amp;letter, const uint64_t &amp;way, const uint8_t &amp;way_length) {     uint64_t mask = 1ULL &lt;&lt; ( way_length - 1 );      Tree_element* current = root;      while ( mask ){         if ( way &amp; mask ) {             if ( current->right != nullptr )                 current = current->right;             else {                 current->right = new Tree_element();                 current = current->right;             }         }         else {             if ( current->left != nullptr )                 current = current->left;             else {                 current->left = new Tree_element();                 current = current->left;             }         }          mask >>= 1;     }      current->data = letter;     current->data_exist = true; }<\/code><\/pre>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f.<\/p>\n<pre><code class=\"cpp\">void read_data_for_decompress(std::vector&lt;uint64_t> &amp;B, std::vector&lt;uint8_t> &amp;shift, uint8_t &amp;length_of_last_byte, uint8_t &amp;last_byte) {     std::ifstream file(\"data_for_decompress.bin\", std::ios_base::binary);      file.read((char* )&amp;length_of_last_byte, 1);          file.read((char* )&amp;last_byte, 1);      file.read((char* )&amp;( B[0] ), 2048);      file.read((char* )&amp;( shift[0] ), 256);      file.close(); }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u043c \u043a\u043e\u0434\u0430\u043c.<\/p>\n<pre><code class=\"cpp\">void create_binary_tree_of_elementary_codes(const std::vector&lt;uint8_t> &amp;alphabet, const std::vector&lt;uint64_t> &amp;B, const std::vector&lt;uint8_t> &amp;shift, Binary_tree &amp;tree) {     size_t size = alphabet.size();      for (size_t i = 0; i &lt; size; i++)         tree.insert(alphabet[i], B[ alphabet[i] ], shift[ alphabet[i] ]); }<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0436\u0430\u0442\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"cpp\">void decompress_data_from_file(Tree_element* const root, const std::string &amp;filename, uint8_t &amp;length_of_last_byte, const uint8_t &amp;last_byte) {     std::cout &lt;&lt; \"\u041d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f\\n\";      std::ifstream reading(\"compressed_data.bin\", std::ios_base::binary);      std::ofstream writing(filename, std::ios_base::binary);     Tree_element* current = root;      uint8_t byte = 0;      while ( reading.read((char* )&amp;byte, 1) ) {         uint8_t mask = 1 &lt;&lt; 7;          while ( mask ) {               do {                 if ( byte &amp; mask )                     current = current->right;                 else                     current = current->left;                                  mask >>= 1;             } while ( mask &amp;&amp; !current->data_exist );              if ( current->data_exist ) {                 writing.write( (char* )&amp;( current->data ), 1);                 current = root;             }          }     }      uint8_t mask = 1 &lt;&lt; 7;      while ( length_of_last_byte ) {                   do {             if ( last_byte &amp; mask )                 current = current->right;             else                 current = current->left;                          mask >>= 1;             length_of_last_byte--;         } while ( !current->data_exist );          writing.write( (char* )&amp;( current->data ), 1);         current = root;     }          reading.close();     writing.close(); }<\/code><\/pre>\n<p>\u041f\u043b\u044e\u0441\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>\u041a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0425\u0430\u0444\u0444\u043c\u0430\u043d\u0430 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0430\u043b\u0444\u0430\u0432\u0438\u0442, \u0430\u043b\u0444\u0430\u0432\u0438\u0442 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0443 <strong>shift<\/strong>, \u0435\u0441\u043b\u0438 \u0434\u043b\u0438\u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0431\u0443\u043a\u0432\u044b \u0440\u0430\u0432\u043d\u0430 \u043d\u0443\u043b\u044e, \u0442\u043e \u0431\u0443\u043a\u0432\u044b \u043d\u0435\u0442 \u0432 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0435.<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u0438\u043d\u0443\u0441\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>\u041a\u043e\u0441\u0442\u044b\u043b\u0438 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0435\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u0431\u0430\u0439\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0443\u0447\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e &lt;<strong>vector<\/strong>>, &lt;<strong>string<\/strong>> \u0438 &lt;<strong>algorithm<\/strong>>(\u043e\u0442\u0441\u044e\u0434\u0430 \u0432\u0437\u044f\u0442\u0430 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430).<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0431\u043e\u0440\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0443\u043a\u0432\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0411\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. 2 + 256 * 8 + 256 \u0431\u0430\u0439\u0442.<\/p>\n<\/li>\n<\/ol>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043e\u043d\u0430 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u0434\u043b\u044f \u0441\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e3d\/c16\/5ca\/e3dc165ca2b59e709509c117f36f360d.png\" alt=\"\u0425\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u043a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0425\u0430\u0444\u0444\u043c\u0430\u043d\u0430.\" title=\"\u0425\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u043a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0425\u0430\u0444\u0444\u043c\u0430\u043d\u0430.\" width=\"1101\" height=\"234\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e3d\/c16\/5ca\/e3dc165ca2b59e709509c117f36f360d.png\"\/><\/p>\n<div><figcaption>\u0425\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u043a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0425\u0430\u0444\u0444\u043c\u0430\u043d\u0430.<\/figcaption><\/div>\n<\/figure>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0425\u0430\u0444\u0444\u043c\u0430\u043d\u0430 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0441\u0436\u0438\u043c\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u043e. \u0421 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0445\u0443\u0436\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u043d\u0438\u0445 \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e.<\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434, \u0440\u0430\u0437\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u0438, <a href=\"https:\/\/github.com\/hououinksinonimo\/HuffmanCoder\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a><\/p>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435\u043c \u043a\u043d\u0438\u0433\u0438: \u0412\u0430\u0442\u043e\u043b\u0438\u043d \u0414., \u0420\u0430\u0442\u0443\u0448\u043d\u044f\u043a \u0410., \u0421\u043c\u0438\u0440\u043d\u043e\u0432 \u041c., \u042e\u043a\u0438\u043d \u0412. &#171;\u041c\u0435\u0442\u043e\u0434\u044b \u0441\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0423\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0430\u0440\u0445\u0438\u0432\u0430\u0442\u043e\u0440\u043e\u0432, \u0441\u0436\u0430\u0442\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u0432\u0438\u0434\u0435\u043e.&#187; &#8212; \u041c.: \u0414\u0418\u0410\u041b\u041e\u0413-\u041c\u0418\u0424\u0418, 2003. &#8212; 384 \u0441  <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/818065\/\"> https:\/\/habr.com\/ru\/articles\/818065\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u0443\u044e \u0442\u0435\u043c\u0443 \u0431\u044b\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u0435 \u043e\u0434\u043d\u0430 \u0441\u043e\u0442\u043d\u044f \u0441\u0442\u0430\u0442\u0435\u0439, \u043d\u043e \u0432\u043e \u0432\u0441\u0435\u0445, \u0447\u0442\u043e \u0432\u0438\u0434\u0435\u043b, \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u043e \u0442\u0438\u043f\u0443 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u043e\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0445\u043e\u0442\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0447\u0430\u0441\u0442\u043e\u0442 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f \u0438 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0434\u0432\u0435 \u0431\u0443\u043a\u0432\u044b \u0438\u0437 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0442\u0435\u043b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C++.<\/p>\n<p>\u041a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0425\u0430\u0444\u0444\u043c\u0430\u043d\u0430 \u0434\u043b\u044f \u0441\u0436\u0430\u0442\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0447\u0430\u0441\u0442\u043e\u0442 \u043a\u0430\u0436\u0434\u043e\u0439 \u0431\u0443\u043a\u0432\u044b \u0432 \u0444\u0430\u0439\u043b\u0435 \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0431\u0443\u043a\u0432\u044b \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0436\u0430\u0442\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0436\u0430\u0442\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0434\u0432\u0430 \u0447\u0442\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u0431\u0443\u043a\u0432, \u043f\u043e\u0442\u043e\u043c \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0431\u0443\u043a\u0432\u0443 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430 \u043d\u0430 \u0435\u0451 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0451\u0442\u0430 \u0447\u0430\u0441\u0442\u043e\u0442 \u0431\u0443\u043a\u0432 \u0432 \u0444\u0430\u0439\u043b\u0435. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0434\u043b\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0432\u0435\u043a\u0442\u043e\u0440 <strong>letter_count<\/strong>, \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 &lt;\u0431\u0443\u043a\u0432\u0430, \u0447\u0430\u0441\u0442\u043e\u0442\u0430>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0447\u0430\u0441\u0442\u043e\u0442\u0435 \u0431\u0443\u043a\u0432\u044b, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443, \u0440\u0430\u0432\u043d\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0431\u0443\u043a\u0432\u044b \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435.<\/p>\n<pre><code class=\"cpp\">void count_frequency(const std::string &amp;filename, std::vector&lt;uint64_t> &amp;letter_count) {     std::ifstream file(filename, std::ios_base::binary);      uint8_t c;      while ( file.read((char* )&amp;c, 1) )         letter_count[c]++;      file.close(); }  struct data_about_letter_vector {     std::vector&lt;uint8_t> letter_vector;     uint64_t count; };  void create_alphabet(std::vector&lt;data_about_letter_vector> &amp;alphabet, const std::vector&lt;uint64_t> &amp;letter_count) {     size_t size = 0;          for (size_t i = 0; i &lt; 256; i++)          if ( letter_count[i] ) {             alphabet[size].letter_vector.push_back(i);             alphabet[size].count = letter_count[i];              size++;         }          alphabet.resize(size); }  void count_frequency_and_create_alphabet(const std::string &amp;filename, std::vector&lt;data_about_letter_vector> &amp;alphabet) {     std::vector&lt;uint64_t> letter_count(256);     count_frequency(filename, letter_count);      create_alphabet(alphabet, letter_count); }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0431\u0443\u043a\u0432\u044b \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0421\u043b\u043e\u0432\u0435\u0441\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432.<\/figcaption><\/div>\n<\/figure>\n<pre><code class=\"cpp\">bool compare(const data_about_letter_vector &amp;left, const data_about_letter_vector &amp;right) {     return left.count > right.count; }  void create_elementary_codes(std::vector&lt;uint64_t> &amp;B, std::vector&lt;uint8_t> &amp;shift, const std::string &amp;filename) {        std::vector&lt;data_about_letter_vector> alphabet(256);     count_frequency_and_create_alphabet(filename, alphabet);      size_t size = alphabet.size();          std::sort(alphabet.begin(), alphabet.end(), compare);      while ( size > 2 ) {         size_t pos0 = size - 2, pos1 = pos0 + 1;          for ( uint8_t a : alphabet[pos0].letter_vector )             shift[a]++;          for ( uint8_t a : alphabet[pos1].letter_vector ) {             B[a] = ( 1ULL &lt;&lt; shift[a] ) | B[a];             shift[a]++;         }          data_about_letter_vector temp;          for ( uint8_t a : alphabet[pos0].letter_vector )             temp.letter_vector.push_back(a);          for ( uint8_t a : alphabet[pos1].letter_vector )             temp.letter_vector.push_back(a);                  temp.count = alphabet[pos0].count + alphabet[pos1].count;          size -= 2;          alphabet.resize(size);          uint8_t pos_to_insert = size;          while ( pos_to_insert &amp;&amp; ( alphabet[ pos_to_insert - 1 ].count &lt; temp.count ) )             pos_to_insert--;          alphabet.insert(alphabet.begin() + pos_to_insert, temp);          size++;     }          if ( size == 1 )          shift[ alphabet[0].letter_vector[0] ]++;     else {         size_t pos0 = size - 2, pos1 = pos0 + 1;          for ( uint8_t a : alphabet[pos0].letter_vector )             shift[a]++;          for ( uint8_t a : alphabet[pos1].letter_vector ) {             B[a] = ( 1ULL &lt;&lt; shift[a] ) | B[a];             shift[a]++;         }     } }<\/code><\/pre>\n<p>\u042d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0435 \u043a\u043e\u0434\u044b \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u0441\u0436\u0430\u0442\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0435 \u043a\u043e\u0434\u044b, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0434\u0432\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u043e\u0434\u0438\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u0431\u0443\u043a\u0432 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430(\u0432\u0435\u043a\u0442\u043e\u0440 <strong>B<\/strong>), \u0434\u0440\u0443\u0433\u043e\u0439 \u0434\u043b\u0438\u043d\u0443 \u044d\u0442\u043e\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430(\u0432\u0435\u043a\u0442\u043e\u0440 <strong>shift<\/strong>). \u041f\u043e\u043c\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u043e\u0434\u0438\u043d \u0438\u0437\u044a\u044f\u043d, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0431\u0430\u0439\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0431\u0430\u0439\u0442 \u043d\u0435 \u0431\u044b\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0448\u0443 \u0435\u0433\u043e \u0434\u043b\u0438\u043d\u0443 \u0432 \u0431\u0438\u0442\u0430\u0445 \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f.<\/p>\n<pre><code class=\"cpp\">void write_elementary_codes_into_file(const std::vector&lt;uint64_t> &amp;B, const std::vector&lt;uint8_t> &amp;shift, const uint8_t &amp;length_of_last_byte, const uint8_t &amp;last_byte) {     std::ofstream out(\"data_for_decompress.bin\", std::ios_base::binary);      out.write((char* )&amp;length_of_last_byte, 1);          out.write((char* )&amp;last_byte, 1);      out.write((char* )&amp;( B[0] ), 2048);      out.write((char* )&amp;( shift[0] ), 256);      out.close(); }  void compress_file(const std::vector&lt;uint64_t> &amp;B, const std::vector&lt;uint8_t> &amp;shift, const std::string &amp;filename) {     std::cout &lt;&lt; \"\u041d\u0430\u0447\u0430\u043b\u043e \u0441\u0436\u0430\u0442\u0438\u044f\\n\";      uint8_t byte = 0, length = 0;      std::ofstream out(\"compressed_data.bin\", std::ios_base::binary);     std::ifstream file(filename, std::ios_base::binary);      uint8_t c;      while ( file.read((char* )(&amp;c), 1) ) {         uint64_t elementary_code = B[c];         uint8_t s = shift[c];         uint64_t mask = ( 1ULL &lt;&lt; s ) - 1;          while ( s ) {             uint8_t need_bit_length = 8 - length;              if ( need_bit_length > s ) {                 byte |= elementary_code &lt;&lt; ( need_bit_length - s );                 length += s;                 s = 0;             }             else {                 s -= need_bit_length;                 byte |= elementary_code >> s;                 mask >>= need_bit_length;                 elementary_code &amp;= mask;                 out.write((char* )&amp;byte, 1);                 byte = 0;                 length = 0;             }         }     }      out.close();     file.close();      write_elementary_codes_into_file(B, shift, length, byte); }<\/code><\/pre>\n<p>\u0421 \u0441\u0436\u0430\u0442\u0438\u0435\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438, \u0434\u0430\u043b\u0435\u0435 \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u0435. \u0414\u043b\u044f \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0440\u0430\u043d\u0435\u0435 \u0432 \u0444\u0430\u0439\u043b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u043c \u043a\u043e\u0434\u0430\u043c.<\/p>\n<p>\u041a\u043e\u0434 \u0434\u043b\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0431\u044b\u043b \u0443\u043a\u0440\u0430\u0434\u0435\u043d, \u043d\u043e \u0431\u044b\u043b\u0430 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u043e. <\/p>\n<p>\u041f\u043e\u0438\u0441\u043a \u043f\u043e \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c\u0443 \u0434\u0435\u0440\u0435\u0432\u0443 \u0434\u043b\u044f \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u0431\u0443\u043a\u0432\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043e\u0442 \u043a\u043e\u0440\u043d\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e \u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c(1 &#8212; \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043f\u0440\u0430\u0432\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043c\u043a\u0443, 0 &#8212; \u043a \u043b\u0435\u0432\u043e\u043c\u0443) \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043c \u043b\u0438\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u0443\u043a\u0432\u0443. <strong>way<\/strong> &#8212; \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u043a\u043e\u0434, \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 <strong>B<\/strong>, <strong>way_length<\/strong> &#8212; \u044d\u0442\u043e \u0434\u043b\u0438\u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 <strong>shift.<\/strong><\/p>\n<pre><code class=\"cpp\">class Tree_element {     public:         bool data_exist;         uint8_t data;         Tree_element* left;         Tree_element* right;         Tree_element(); };  class Binary_tree {     public:         Tree_element* root;         Binary_tree();         ~Binary_tree();         void delete_tree(Tree_element* current);         void insert(const uint8_t &amp;letter, const uint64_t &amp;way, const uint8_t &amp;way_length); };  Tree_element::Tree_element()  {     data_exist = false;     left = nullptr;     right = nullptr; }  Binary_tree::Binary_tree() {     root = new Tree_element(); }  void Binary_tree::delete_tree(Tree_element* current) {     if ( current != nullptr ) {         delete_tree(current->left);         delete_tree(current->right);         delete current;     } }  Binary_tree::~Binary_tree() {     delete_tree(root); }  void Binary_tree::insert(const uint8_t &amp;letter, const uint64_t &amp;way, const uint8_t &amp;way_length) {     uint64_t mask = 1ULL &lt;&lt; ( way_length - 1 );      Tree_element* current = root;      while ( mask ){         if ( way &amp; mask ) {             if ( current->right != nullptr )                 current = current->right;             else {                 current->right = new Tree_element();                 current = current->right;             }         }         else {             if ( current->left != nullptr )                 current = current->left;             else {                 current->left = new Tree_element();                 current = current->left;             }         }          mask >>= 1;     }      current->data = letter;     current->data_exist = true; }<\/code><\/pre>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f.<\/p>\n<pre><code class=\"cpp\">void read_data_for_decompress(std::vector&lt;uint64_t> &amp;B, std::vector&lt;uint8_t> &amp;shift, uint8_t &amp;length_of_last_byte, uint8_t &amp;last_byte) {     std::ifstream file(\"data_for_decompress.bin\", std::ios_base::binary);      file.read((char* )&amp;length_of_last_byte, 1);          file.read((char* )&amp;last_byte, 1);      file.read((char* )&amp;( B[0] ), 2048);      file.read((char* )&amp;( shift[0] ), 256);      file.close(); }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u043c \u043a\u043e\u0434\u0430\u043c.<\/p>\n<pre><code class=\"cpp\">void create_binary_tree_of_elementary_codes(const std::vector&lt;uint8_t> &amp;alphabet, const std::vector&lt;uint64_t> &amp;B, const std::vector&lt;uint8_t> &amp;shift, Binary_tree &amp;tree) {     size_t size = alphabet.size();      for (size_t i = 0; i &lt; size; i++)         tree.insert(alphabet[i], B[ alphabet[i] ], shift[ alphabet[i] ]); }<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0436\u0430\u0442\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"cpp\">void decompress_data_from_file(Tree_element* const root, const std::string &amp;filename, uint8_t &amp;length_of_last_byte, const uint8_t &amp;last_byte) {     std::cout &lt;&lt; \"\u041d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f\\n\";      std::ifstream reading(\"compressed_data.bin\", std::ios_base::binary);      std::ofstream writing(filename, std::ios_base::binary);     Tree_element* current = root;      uint8_t byte = 0;      while ( reading.read((char* )&amp;byte, 1) ) {         uint8_t mask = 1 &lt;&lt; 7;          while ( mask ) {               do {                 if ( byte &amp; mask )                     current = current->right;                 else                     current = current->left;                                  mask >>= 1;             } while ( mask &amp;&amp; !current->data_exist );              <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-377445","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/377445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=377445"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/377445\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=377445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=377445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=377445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}