{"id":402452,"date":"2024-06-29T16:30:51","date_gmt":"2024-06-29T16:30:51","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=402452"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=402452","title":{"rendered":"<span>\u041a\u0440\u0430\u0441\u0438\u0432\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e PATRICIA (\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 C++)<\/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>\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a, \u0445\u0430\u0431\u0440\u043e\u0432\u0447\u0430\u043d\u0435! \u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u043e\u043a\u0443\u043d\u0443\u0442\u044c \u0432\u0430\u0441 \u0432 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435, \u0432\u0441\u0435\u043c\u0438 \u0437\u0430\u0431\u044b\u0442\u043e\u0435, \u0433\u0434\u0435-\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e PATRICIA, \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e \u0435\u0435 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u0421++, \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u043d\u043e, \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u044c\u0442\u0435\u0441\u044c.<\/p>\n<hr\/>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a64\/450\/b18\/a64450b187d7a968fd711ae9f88c9539.png\" width=\"1024\" height=\"1185\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a64\/450\/b18\/a64450b187d7a968fd711ae9f88c9539.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438 \u0438 \u0441\u0440\u0430\u0437\u0443 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041f\u0430\u0442\u0440\u0438\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043c\u0435\u0448\u0435\u043d\u0438\u0435 trie \u0438 DST \u0434\u0435\u0440\u0435\u0432\u0430, \u043d\u0430 \u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a, \u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0431\u0438\u0442\u0430.<\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0438\u043c\u0435\u0435\u0442:<\/p>\n<ol>\n<li>\n<p>\u041a\u043b\u044e\u0447(<code>string key<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435(<code>int value<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0434\u0435\u043a\u0441 \u0431\u0438\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430(<code>size_t index<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043f\u0440\u0430\u0432\u0443\u044e \u0438 \u043b\u0435\u0432\u0443\u044e \u0432\u0435\u0440\u0448\u0438\u043d\u0443(<code>Node *right, *left<\/code>)<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cpp\">struct Patricia::Node{     std::string key;     int value;     size_t index;     Node *right, *left;      Node(const std::string&amp; key, const int&amp; value, const int&amp; index)         : key(key), value(value), index(index), left(nullptr), right(nullptr) { }      ~Node(){} };<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0441\u0430\u043c\u043e\u0439 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u043e \u0435\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445, \u0438\u0445 \u043d\u0435\u043c\u043d\u043e\u0433\u043e. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043f\u0440\u0430\u0432\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043a\u043e\u0440\u043d\u044f &#8212; <code>nullptr<\/code> <strong>\u0432\u0441\u0435\u0433\u0434\u0430<\/strong>. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043a\u0430\u0436\u0434\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438, \u043a\u0440\u043e\u043c\u0435 \u043a\u043e\u0440\u043d\u044f \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441, \u0438 \u0432\u0441\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 <strong>\u0432\u0441\u0435\u0433\u0434\u0430<\/strong> \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u0435\u0440\u0435\u0432\u0430 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0440\u043d\u044f, \u0430 \u043f\u043e\u0438\u0441\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043b\u0435\u0432\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043e\u0442 \u043a\u043e\u0440\u043d\u044f. \u0412-\u0442\u0440\u0435\u0442\u044c\u0438\u0445, \u043b\u0438\u0441\u0442\u043e\u043c \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430, \u043e\u0434\u0438\u043d \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0431\u044f. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">typedef class Patricia{ private:     struct Node;     Node *root = nullptr; public: } patr;<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438 (\u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c value \u0432\u0435\u0440\u0448\u0438\u043d):<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b10\/dfb\/53d\/b10dfb53d32031d7864f6ce3258f21c0.png\" alt=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438 1\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438 1\" width=\"1092\" height=\"667\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b10\/dfb\/53d\/b10dfb53d32031d7864f6ce3258f21c0.png\"\/><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438 1<\/figcaption><\/figure>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0441\u043f\u0440\u0430\u0432\u0430 \u0441\u0432\u0435\u0440\u0445\u0443 \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u043d \u0448\u0430\u0431\u043b\u043e\u043d, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432 \u0446\u0435\u043d\u0442\u0440\u0435 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441 \u0431\u0438\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u043d\u0430\u0445\u043e\u0434\u044f\u0441\u044c \u0432 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u0435. \u0412\u043d\u0438\u0437\u0443 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0441\u0430\u043c \u043a\u043b\u044e\u0447. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0435\u0440\u0435\u0432\u0430(1).<\/p>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0430\u043b\u0444\u0430\u0432\u0438\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043b\u044e\u0447\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0430\u0442\u0438\u043d\u0441\u043a\u0438\u0435 \u0431\u0443\u043a\u0432\u044b \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0431\u0438\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u043b\u0430\u0442\u0438\u043d\u0441\u043a\u043e\u0439 \u0431\u0443\u043a\u0432\u044b, \u043d\u0430\u043c \u044d\u0442\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f(\u0441\u043e\u0432\u0435\u0442\u0443\u044e \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043a\u043b\u0430\u0434\u043a\u0443).<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/92e\/a6e\/047\/92ea6e047f541117604097be0fff3b0b.png\" alt=\"\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0431\u0430\u0439\u0442(\u0441\u0438\u043c\u0432\u043e\u043b) \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f 8 \u0431\u0438\u0442\u0430\u043c\u0438, \u043d\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c\u0438 5-\u044e \u0431\u0438\u0442\u0430\u043c\u0438\" title=\"\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0431\u0430\u0439\u0442(\u0441\u0438\u043c\u0432\u043e\u043b) \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f 8 \u0431\u0438\u0442\u0430\u043c\u0438, \u043d\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c\u0438 5-\u044e \u0431\u0438\u0442\u0430\u043c\u0438\" width=\"670\" height=\"452\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/92e\/a6e\/047\/92ea6e047f541117604097be0fff3b0b.png\"\/><figcaption>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0431\u0430\u0439\u0442(\u0441\u0438\u043c\u0432\u043e\u043b) \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f 8 \u0431\u0438\u0442\u0430\u043c\u0438, \u043d\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c\u0438 5-\u044e \u0431\u0438\u0442\u0430\u043c\u0438<\/figcaption><\/figure>\n<h2>\u041f\u043e\u0438\u0441\u043a<\/h2>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0443\u0437\u0435\u043b \u0441 \u043a\u043b\u044e\u0447\u043e\u043c &#171;a&#187;, \u0435\u0433\u043e \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 00001. \u0412\u0430\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u0434\u0435\u0442 \u043d\u0435 \u0441 0, \u0430 \u0441 1, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c &#8216;1&#8217; \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 5.<\/p>\n<p>\u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0440\u043d\u044f, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c <code>nullptr<\/code>, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c, \u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u0441 \u043b\u0435\u0432\u043e\u0433\u043e \u0443\u0437\u043b\u0430, \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u043e \u0443\u0437\u0435\u043b \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c <strong>1<\/strong> \u0438 \u043a\u043b\u044e\u0447\u043e\u043c &#171;y&#187;. \u0411\u0435\u0440\u0435\u043c <abbr title=\"\u0418\u043d\u0434\u0435\u043a\u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u0443 \u043d\u0430\u0441 1 \u0438 \u043a\u043b\u044e\u0447 &quot;y&quot;\">\u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441<\/abbr> \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0431\u0438\u0442 \u0438\u0437 <abbr title=\"\u041f\u043e\u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u043a\u043b\u044e\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0449\u0435\u043c, \u0443 \u043d\u0430\u0441 &quot;a&quot; - 00001\">\u0438\u0441\u043a\u043e\u043c\u043e\u0439 \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438<\/abbr> \u0432 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0438\u0442 \u0440\u0430\u0432\u0435\u043d &#8212; 0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043b\u0435\u0432\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0443\u0437\u0435\u043b \u0440\u0430\u0432\u0435\u043d \u0438\u043d\u0434\u0435\u043a\u0441\u0443 <strong>2<\/strong> \u0438 \u043a\u043b\u044e\u0447\u0443 &#171;l&#187;, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0431\u0438\u0442 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430(&#171;\u0430&#187;) \u043f\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443(2). \u0411\u0438\u0442 \u0440\u0430\u0432\u0435\u043d &#8212; 0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043d\u043e\u0432\u0430 \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043b\u0435\u0432\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0443\u0437\u0435\u043b \u0440\u0430\u0432\u0435\u043d \u0438\u043d\u0434\u0435\u043a\u0441\u0443 <strong>4<\/strong> \u0438 \u043a\u043b\u044e\u0447\u0443 &#171;b&#187;, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0431\u0438\u0442 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430(&#171;\u0430&#187;) \u043f\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443(4). \u0411\u0438\u0442 \u0440\u0430\u0432\u0435\u043d &#8212; 0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043d\u043e\u0432\u0430 \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043b\u0435\u0432\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e.<\/p>\n<p>\u041f\u043e\u0438\u0441\u043a \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0443\u0437\u043b\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443, \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 &#8212; <strong>0<\/strong>, \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 &#8212; <strong>4<\/strong>. \u041f\u043e\u0438\u0441\u043a \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430: &#171;\u0430&#187;, \u0438\u043d\u0434\u0435\u043a\u0441 0 &#8212; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u043e\u0439 \u043d\u0430\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0438\u0441\u043a\u0430\u043b\u0438.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d97\/9f2\/9b9\/d979f29b983f47c1be7b3fc480535f4a.png\" alt=\"\u0422\u0435\u043c\u043d\u043e \u043e\u0440\u0430\u043d\u0436\u0435\u0432\u044b\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0443\u0437\u043b\u044b, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u0421\u0438\u043d\u0438\u043c - \u0441\u0442\u0440\u0435\u043b\u043a\u0438, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u041a\u0440\u0430\u0441\u043d\u044b\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0443\u0437\u0435\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f \u043f\u043e\u0438\u0441\u043a \u0421\u0432\u0435\u0440\u0445\u0443 \u0432 \u043a\u0440\u0430\u0441\u043d\u043e\u043c \u043e\u0431\u0440\u0430\u043c\u043b\u0435\u043d\u0438\u0438 \u0443\u043a\u0430\u0437\u0430\u043d \u043c\u0435\u0442\u043e\u0434, \u043a\u043b\u044e\u0447 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0449\u0435\u043c \u0438 \u0435\u0433\u043e \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430\" title=\"\u0422\u0435\u043c\u043d\u043e \u043e\u0440\u0430\u043d\u0436\u0435\u0432\u044b\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0443\u0437\u043b\u044b, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u0421\u0438\u043d\u0438\u043c - \u0441\u0442\u0440\u0435\u043b\u043a\u0438, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u041a\u0440\u0430\u0441\u043d\u044b\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0443\u0437\u0435\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f \u043f\u043e\u0438\u0441\u043a \u0421\u0432\u0435\u0440\u0445\u0443 \u0432 \u043a\u0440\u0430\u0441\u043d\u043e\u043c \u043e\u0431\u0440\u0430\u043c\u043b\u0435\u043d\u0438\u0438 \u0443\u043a\u0430\u0437\u0430\u043d \u043c\u0435\u0442\u043e\u0434, \u043a\u043b\u044e\u0447 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0449\u0435\u043c \u0438 \u0435\u0433\u043e \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430\" width=\"1077\" height=\"772\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d97\/9f2\/9b9\/d979f29b983f47c1be7b3fc480535f4a.png\"\/><figcaption>\u0422\u0435\u043c\u043d\u043e \u043e\u0440\u0430\u043d\u0436\u0435\u0432\u044b\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0443\u0437\u043b\u044b, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u0421\u0438\u043d\u0438\u043c &#8212; \u0441\u0442\u0440\u0435\u043b\u043a\u0438, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u041a\u0440\u0430\u0441\u043d\u044b\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0443\u0437\u0435\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f \u043f\u043e\u0438\u0441\u043a \u0421\u0432\u0435\u0440\u0445\u0443 \u0432 \u043a\u0440\u0430\u0441\u043d\u043e\u043c \u043e\u0431\u0440\u0430\u043c\u043b\u0435\u043d\u0438\u0438 \u0443\u043a\u0430\u0437\u0430\u043d \u043c\u0435\u0442\u043e\u0434, \u043a\u043b\u044e\u0447 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0449\u0435\u043c \u0438 \u0435\u0433\u043e \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430<\/figcaption><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 Search. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f currentNode \u0438 prevNode, \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 <code>currentNode->index &lt;= prevNode->index<\/code>.<\/p>\n<pre><code class=\"cpp\">Patricia::Node* Patricia::Search(const std::string&amp; findKey) const{     Node *currentNode = root->left, *prevNode = root;      while(currentNode->index > prevNode->index){         \/\/ Index of char that we need to check         size_t charIndex = (currentNode->index - 1) \/ BIT_COUNT;<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0411\u0435\u0440\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u0437 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0443\u0437\u043b\u0430, \u0432\u044b\u0447\u0438\u0442\u0430\u044f 1. \u0414\u0430\u043b\u044c\u0448\u0435 \u0434\u0435\u043b\u0438\u043c \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 <abbr title=\"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a, \u0443 \u043d\u0430\u0441 5\">BIT_COUNT<\/abbr>. \u0412\u044b\u0447\u0438\u0442\u0430\u0435\u043c 1 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u043d\u0435 \u0441 0, \u0430 \u0441 1. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0438\u0437 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438 1 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 &#171;m&#187;, \u0443 \u043d\u0435\u0435 \u0438\u043d\u0434\u0435\u043a\u0441 5 &#8212; 1 = 4, \u043f\u0440\u0438 \u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043d\u0430 BIT_COUNT \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c 0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b, \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043d\u0435 \u0432\u044b\u0447\u0438\u0442\u0430\u043b\u0438, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0431\u044b \u0438\u043d\u0434\u0435\u043a\u0441 1, \u0447\u0442\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"cpp\">    \/\/ FindKey is less than need char     if(charIndex >= findKey.size()){       \/\/ Remember prevNode       prevNode = currentNode;       \/\/ Only '0'       currentNode = currentNode->left;       continue;     }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u044b, \u0442\u043e \u043c\u044b &#171;\u043a\u0430\u043a \u0431\u044b&#187; \u0431\u0435\u0440\u0435\u043c \u0431\u0438\u0442 \u0438\u0437 \u043d\u0443\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430, \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u0430\u0432\u043d\u0430 &#8212; 00000, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u044b \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0431\u0438\u0442 0, \u0430 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e \u043b\u0435\u0432\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e, \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044f \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0432 <code>prevNode<\/code>.<\/p>\n<pre><code class=\"cpp\">char currentChar = findKey[charIndex];         \/\/ How many times should we shift to the right         int offset = (BIT_COUNT - 1 - ((currentNode->index - 1) % BIT_COUNT));         \/\/ Get current bit         bool currentBit = (currentChar >> offset) &amp; 1;          \/\/ Remember prevNode         prevNode = currentNode;         \/\/ If '1' go right, '0' go left         currentBit  ? currentNode = currentNode->right                     : currentNode = currentNode->left;     }     return currentNode;<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430, \u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0437\u044f\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438. \u0412\u044b\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435, \u0442.\u0435. \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0434\u043e \u0441\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0431\u0438\u0442\u043e\u0432\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443, \u0447\u0442\u043e\u0431 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0431\u0438\u0442 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u0440\u0430\u0439\u043d\u0435\u043c \u043f\u0440\u0430\u0432\u043e\u043c \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u0437\u044f\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0431\u0438\u0442 \u0438\u0437 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 10001, \u0442\u043e\u0433\u0434\u0430 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u043e 4.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u0438\u0442, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <strong>\u0418 <\/strong>\u0438 <strong>\u0441\u0434\u0432\u0438\u0433\u0430,<\/strong> \u043f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u0435\u0441\u043b\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0431\u0438\u0442\u043e\u0432\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 &#8216;1&#8217;, \u0442\u043e <code>currentBit = true<\/code>, \u0435\u0441\u043b\u0438 &#8216;0&#8217;, \u0442\u043e <code>false<\/code>.<\/p>\n<p>\u0417\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0432\u0435\u0440\u0448\u0438\u043d\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0433\u0430\u0442\u044c \u0435\u0435. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b. \u0418\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 Search \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c <code>currentNode<\/code>, \u043a\u043e\u0433\u0434\u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u0431\u0443\u0434\u0435\u0442 &lt;= \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b. \u041f\u043e\u043b\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">Patricia::Node* Patricia::Search(const std::string&amp; findKey) const{     Node *currentNode = root->left, *prevNode = root;      while(currentNode->index > prevNode->index){         \/\/ Index of char that we need to check         size_t charIndex = (currentNode->index - 1) \/ BIT_COUNT;          \/\/ findKey is less than need char         if(charIndex >= findKey.size()){           \/\/ Remember prevNode             prevNode = currentNode;             \/\/ Only '0'             currentNode = currentNode->left;             continue;         }          char currentChar = findKey[charIndex];         \/\/ How many times should we shift to the right         int offset = (BIT_COUNT - 1 - ((currentNode->index - 1) % BIT_COUNT));         \/\/ Get current bit         bool currentBit = (currentChar >> offset) &amp; 1;          \/\/ Remember prevNode         prevNode = currentNode;         \/\/ If '1' go right, '0' go left         currentBit  ? currentNode = currentNode->right                     : currentNode = currentNode->left;     }     return currentNode; }<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044f \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u0440\u043d\u044f, \u0432\u0441\u0435 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435, \u0438 \u043a\u0430\u0436\u0434\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c Search \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u0440\u043d\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0434\u0440\u0443\u0433\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0442\u043e \u043c\u043e\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 <abbr title=\"\u041d\u0430 2 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u0438\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a root->left, \u0435\u0441\u043b\u0438 root = nullptr, \u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043a\u0440\u0430\u0448\u043d\u0435\u0442\u0441\u044f&#187;>\u0441\u043b\u043e\u043c\u0430\u0442\u044c \u0432\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443<\/abbr> :\u0441<\/p>\n<h2>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u044b \u0432 \u0434\u0435\u0440\u0435\u0432\u043e<\/h2>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u044b \u0432 \u0434\u0435\u0440\u0435\u0432\u043e:<\/p>\n<ol>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u0443, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u0432\u044b\u0434\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e (2).<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0431\u0438\u0442\u043e\u0432\u0443\u044e \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u0441\u043d\u043e\u0432\u0430 \u043e\u0442 \u043a\u043e\u0440\u043d\u044f, \u043d\u0430\u0439\u0442\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u0435 <strong><abbr title=\"\u042d\u0442\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0430\u044f \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0438\u0437 \u043f. 2\">\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439<\/abbr><\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0443\u0437\u0435\u043b \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u043e\u0439 \u0438 \u0435\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0432\u044f\u0437\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0443\u044e \u0432\u0435\u0440\u0448\u0438\u043d\u0443, \u0434\u0440\u0443\u0433\u043e\u0439 \u043d\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0443\u044e(\u0438\u0437 \u043f. 3). <\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cpp\">void Patricia::Add(const std::string&amp; key, int value){     if(!root){         root = new Node(key, value, 0);         root->left = root;         return;     }      Node *foundNode = Search(key);     if(foundNode->key == key)         throw std::runtime_error(\"\\t\\\"\" + key + \"\\\" already exist!\\n\");<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u044f \u0443\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u0440\u043d\u044f, \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u0441\u043e\u0437\u0434\u0430\u044e \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e, \u0438\u043d\u0430\u0447\u0435 \u043d\u0430\u0445\u043e\u0436\u0443 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e \u043a\u043b\u044e\u0447 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439, \u0435\u0441\u043b\u0438 \u0440\u0430\u0432\u043d\u044b, \u0442\u043e \u0432\u044b\u0434\u0430\u044e \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<pre><code class=\"cpp\">bool run = true;     size_t charIndex = 0;     while(run){         char foundedKey = (foundNode->key.size() > charIndex                             ? foundNode->key[charIndex] : '\\0');         char inputKey   = (key.size() > charIndex ? key[charIndex] : '\\0');         for(size_t i = 0; i &lt; BIT_COUNT; ++i){             bool foundedKeyBit = foundedKey >> (BIT_COUNT - 1 - i) &amp; 1;             bool inputKeyBit = inputKey >> (BIT_COUNT - 1 - i) &amp; 1;             if(foundedKeyBit != inputKeyBit){                 Insert(key, value, charIndex * BIT_COUNT + i + 1);                 run = false;                 break;             }         }         ++charIndex;     }<\/code><\/pre>\n<p>Run \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u043b\u0430\u0433\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0446\u0438\u043a\u043b\u0430 while, <code>charIndex<\/code> &#8212; \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0439, \u043d\u0443\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0439. <code>foundedKey<\/code> &#8212; \u0431\u0435\u0440\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0438\u0437 \u043a\u043b\u044e\u0447\u0430 \u0443\u0437\u043b\u0430, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432\u044b\u0445\u043e\u0434\u0438\u043c \u043b\u0438 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043a\u043b\u044e\u0447\u0430, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u0431\u0435\u0440\u0435\u043c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b <code>'\\0'<\/code>. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441 <code>inputKey<\/code> &#8212; \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0435\u0440\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b \u0438\u0437 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430. <\/p>\n<p>\u0412 \u0446\u0438\u043a\u043b\u0435 for \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0431\u0438\u0442\u0430\u043c, \u0432\u0437\u044f\u0442\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0438 \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f. <code>bool foundedKeyBit<\/code> &#8212; \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u0442 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u043e\u0433\u043e <strong>\u0418<\/strong> \u0441 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441 <code>inputKeyBit<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0431\u0438\u0442\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0435\u0441\u0442\u044c, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e Insert, \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0434\u0432\u0430 \u0446\u0438\u043a\u043b\u0430. \u0417\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434 Add.<\/p>\n<h2>\u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0443\u0437\u043b\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u043e<\/h2>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u043e\u0438\u0441\u043a\u0430, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0431 \u0438\u043d\u0434\u0435\u043a\u0441\u0435 \u043d\u0435\u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u0431\u0438\u0442\u043e\u0432 \u0438 \u043e\u0434\u043d\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0447\u0430\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cpp\">void Patricia::Insert(const std::string&amp; key, const int&amp; value,                       const size_t&amp; index){     Node *currentNode = root->left, *prevNode = root;      while(currentNode->index > prevNode->index &amp;&amp; currentNode->index &lt;= index){         size_t charIndex = (currentNode->index - 1) \/ BIT_COUNT;         \/\/ FindKey is less than need char         if(charIndex >= key.size()){             prevNode = currentNode;             \/\/ Only '0'             currentNode = currentNode->left;             continue;         }         char currentChar = key[charIndex]; \/\/ If findkey.size less than currentNode->index         int offset = (BIT_COUNT - 1 - ((currentNode->index - 1) % BIT_COUNT));         bool currentBit = (currentChar >> offset) &amp; 1;          \/\/ Remember prevNode         prevNode = currentNode;         \/\/ If '1' go right, '0' go left         currentBit  ? currentNode = currentNode->right                     : currentNode = currentNode->left;     }<\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435, \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u0447\u0442\u043e <code>currentNode<\/code> &#8212; \u0432\u0435\u0440\u0448\u0438\u043d\u0430, \u0438\u043d\u0434\u0435\u043a\u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u0448\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0443\u0437\u043b\u0430, \u0430 <code>prevNode<\/code> &#8212; \u0432\u0435\u0440\u0448\u0438\u043d\u0430, \u0438\u043d\u0434\u0435\u043a\u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0438\u0436\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0443\u0437\u043b\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0438\u0445:<\/p>\n<pre><code class=\"cpp\">char getCharFromKey = key[(index - 1) \/ BIT_COUNT];     bool getBit= getCharFromKey >> (BIT_COUNT - 1 - (index - 1) % BIT_COUNT) &amp; 1;     Node *newNode = new Node(key, value, index);      if(prevNode->left == currentNode)         prevNode->left = newNode;     else         prevNode->right = newNode;      getBit  ? (newNode->right = newNode, newNode->left = currentNode)             : (newNode->left = newNode, newNode->right = currentNode); }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0435 3 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b, \u0442\u043e <code>getCharFromKey<\/code> \u0440\u0430\u0432\u0435\u043d \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 <code>(index - 1) \/ BIT_COUNT<\/code>. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438 \u0431\u0438\u0442 \u0438\u0437 \u0441\u0438\u043c\u0432\u043e\u043b\u0430. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0443\u0437\u0435\u043b \u0441 \u0442\u0440\u0435\u043c\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<p><code>prevNode<\/code> &#8212; \u044d\u0442\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u0430-\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0443\u0437\u043b\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0434\u043e \u0435\u0433\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0441 \u0440\u0435\u0431\u0435\u043d\u043a\u043e\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u0443\u0437\u043b\u0430. \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e <code>prevNode->left == currentNode<\/code>, \u0435\u0441\u043b\u0438 <code>true<\/code>, \u0442\u043e \u043e\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0443\u0445\u043e\u0434\u0438\u043c \u0432\u043b\u0435\u0432\u043e \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 \u043d\u043e\u0432\u044b\u0439 \u0443\u0437\u0435\u043b, \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u043b\u0435\u0432\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0441 \u043d\u043e\u0432\u044b\u043c \u0443\u0437\u043b\u043e\u043c.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u0434\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0443\u0437\u043b\u0430. \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0431\u0438\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0438\u0437 <code>getBit<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0431\u0438\u0442 \u0438\u0437 \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u043d\u0434\u0435\u043a\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Add, \u0440\u0430\u0432\u0435\u043d <code>true<\/code>, \u0442\u043e \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0430\u0432\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u043e\u0432\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0431\u044f, \u0430 \u043b\u0435\u0432\u044b\u0439 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u0443-\u0440\u0435\u0431\u0435\u043d\u043a\u0430. \u0418\u043d\u0430\u0447\u0435 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:<\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u044e_1 \u043d\u043e\u0432\u044b\u0439 \u0443\u0437\u0435\u043b \u0441 \u043a\u043b\u044e\u0447\u043e\u043c &#171;n&#187; &#8212; 01110.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ce7\/d4f\/7f9\/ce7d4f7f93cd339ee3ce8d97f52404ba.png\" alt=\"\u0421\u0438\u043d\u0438\u043c - \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c \u041a\u0440\u0430\u0441\u043d\u044b\u043c - \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430\" title=\"\u0421\u0438\u043d\u0438\u043c - \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c \u041a\u0440\u0430\u0441\u043d\u044b\u043c - \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430\" width=\"1077\" height=\"772\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ce7\/d4f\/7f9\/ce7d4f7f93cd339ee3ce8d97f52404ba.png\"\/><figcaption>\u0421\u0438\u043d\u0438\u043c &#8212; \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c \u041a\u0440\u0430\u0441\u043d\u044b\u043c &#8212; \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430<\/figcaption><\/figure>\n<p>\u041f\u043e\u0438\u0441\u043a \u0432\u044b\u0434\u0430\u043b \u043d\u0430\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 &#8212; \u0432\u0435\u0440\u0448\u0438\u043d\u0443 &#171;l&#187; \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c 2. \u0418\u0449\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u043c \u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0431\u0438\u0442\u0430\u0445. l &#8212; 01100, n &#8212; 01110, \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u0432 4 \u0431\u0438\u0442\u0435. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e Insert.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f76\/0ed\/4fc\/f760ed4fc1da55269c37aa24d28de244.png\" alt=\"\u0421\u0438\u043d\u0438\u043c - \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u0416\u0435\u043b\u0442\u044b\u0439 - \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0417\u0435\u043b\u0435\u043d\u044b\u0439 - \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0440\u0435\u0431\u0435\u043d\u043e\u043a\" title=\"\u0421\u0438\u043d\u0438\u043c - \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u0416\u0435\u043b\u0442\u044b\u0439 - \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0417\u0435\u043b\u0435\u043d\u044b\u0439 - \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0440\u0435\u0431\u0435\u043d\u043e\u043a\" width=\"1077\" height=\"772\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f76\/0ed\/4fc\/f760ed4fc1da55269c37aa24d28de244.png\"\/><figcaption>\u0421\u0438\u043d\u0438\u043c &#8212; \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u0416\u0435\u043b\u0442\u044b\u0439 &#8212; \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0417\u0435\u043b\u0435\u043d\u044b\u0439 &#8212; \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0440\u0435\u0431\u0435\u043d\u043e\u043a<\/figcaption><\/figure>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f Insert \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0434\u0432\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043d\u0430\u0434\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u0443\u044e. \u0417\u0435\u043b\u0435\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0438\u043c\u0435\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u0432\u044b\u0448\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e(4), \u0430 \u0436\u0435\u043b\u0442\u0430\u044f &#8212; \u043d\u0438\u0436\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/768\/928\/ddf\/768928ddf7edccc38fb1c64824cd606a.png\" width=\"1077\" height=\"965\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/768\/928\/ddf\/768928ddf7edccc38fb1c64824cd606a.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0424\u0443\u0445&#8230; \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u043e\u0442\u0434\u043e\u0445\u043d\u0435\u043c, \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043d\u0430 5 \u0441\u0435\u043a\u0443\u043d\u0434, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<h2>\u0424\u0443\u043d\u043a\u0446\u0438\u044f At<\/h2>\n<pre><code class=\"cpp\">int&amp; Patricia::At(const std::string&amp; findKey) const{     if(!root)         throw std::runtime_error(\"\\t\\\"\" + findKey + \"\\\" hadn't found!\\n\");      Node* get = Search(findKey);      if(get->key == findKey)         return get->value;      throw std::runtime_error(\"\\t\\\"\" + findKey + \"\\\" hadn't found!\\n\"); }<\/code><\/pre>\n<p>\u042f \u0434\u0443\u043c\u0430\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u0447\u0435\u0433\u043e, \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043a\u043e\u0440\u0435\u043d\u044c, \u0434\u0430\u043b\u044c\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0438\u0441\u043a\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u0443\u0437\u0435\u043b, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 &#8212; \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0438\u043d\u0430\u0447\u0435 \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u0443\u0432\u0435\u0440\u0435\u043d \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u0430 \u043d\u0435 \u0443\u0434\u0430\u043b\u0438\u0442\u0441\u044f.<\/p>\n<p>\u041d\u0443, \u043e\u0442\u0434\u043e\u0445\u043d\u0443\u043b\u0438, \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 &#8212; \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435. \u0417\u0434\u0435\u0441\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 4 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0443\u0437\u043b\u0430:<\/p>\n<ol>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0439 \u0443\u0437\u0435\u043b &#8212; \u043a\u043e\u0440\u0435\u043d\u044c \u0438 \u043e\u043d \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435, \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043a\u043e\u0440\u0435\u043d\u044c \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c <code>nullptr<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0439 <abbr title=\"\u041b\u0438\u0441\u0442\u043e\u043c \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u0437\u0435\u043b \u043e\u0434\u0438\u043d \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0431\u044f\">\u0443\u0437\u0435\u043b &#8212; \u043b\u0438\u0441\u0442<\/abbr>, \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0441 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u043c\u0441\u044f \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u043c \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 <abbr title=\"\u0412\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0410 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0411, \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u0443\u0437\u043b\u0430 \u0411 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u0443\u0437\u0435\u043b \u0410\">\u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446<\/abbr> \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 &#8212; \u043b\u0438\u0441\u0442, \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u0441 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0430\u0439\u0442\u0438 3 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u0410 &#8212; \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0439 \u0443\u0437\u0435\u043b, \u0411 &#8212; \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0443\u0437\u043b\u0430, \u0412 &#8212; \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0443\u0437\u043b\u0430.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/afa\/04d\/f96\/afa04df96408712ff0df18ea70ea589a.png\" width=\"1007\" height=\"965\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/afa\/04d\/f96\/afa04df96408712ff0df18ea70ea589a.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u0443 &#171;t&#187;, \u0435\u0435 \u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0410, \u0435\u0435 \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u0432\u0435\u0440\u0448\u0438\u043d\u0430 &#171;z&#187;, \u043e\u043d\u0430 \u0436\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0411, \u0435\u0435 \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u0432\u0435\u0440\u0448\u0438\u043d\u0430 &#171;y&#187;, \u043e\u043d\u0430 \u0436\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0412. \u0422\u0435\u043f\u0435\u0440\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0443\u0437\u043b\u0430 \u0410:<\/p>\n<ol>\n<li>\n<p>\u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u044e\u0447 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443\u0437\u043b\u0430 \u0411 \u0432 \u0443\u0437\u0435\u043b \u0410.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0443\u0437\u043b\u0430 \u0411 \u0441 \u0440\u0435\u0431\u0435\u043d\u043a\u043e\u043c \u0443\u0437\u043b\u0430 \u0411.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0412 \u0441 \u0411 \u043d\u0430 \u0410.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0411.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/13e\/0e8\/3a7\/13e0e83a79d9398c8dc5f4e08bfd5822.png\" width=\"1007\" height=\"790\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/13e\/0e8\/3a7\/13e0e83a79d9398c8dc5f4e08bfd5822.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e. \u041d\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f, \u0430 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u043b\u0438\u0431\u043e \u0438\u043c\u0435\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0432 \u0441\u0430\u043c\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f, \u043b\u0438\u0431\u043e \u043a\u0430\u043a-\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f. \u0422\u0430\u043a \u043a\u0430\u043a \u044f \u0434\u0435\u043b\u0430\u043b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u044e, \u0442\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f, \u0432\u0435\u0434\u044c \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u043f\u0430\u043c\u044f\u0442\u0438, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 3 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0440\u0442\u0435\u0436\u0438, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0438\u043a\u0430\u043a \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0430\u0441\u044c:<\/p>\n<pre><code>std::tuple&lt;Patricia::Node*, Patricia::Node*, Patricia::Node*>                       Patricia::SearchE(const std::string&amp; findKey) const{     Node *currentNode = root->left, *prevNode = root, *prevPrevNode = root;     while(currentNode->index > prevNode->index){         size_t charIndex = (currentNode->index - 1) \/ BIT_COUNT;      \/\/ FindKey is less than need char     if(charIndex &amp;gt;= findKey.size()){         prevPrevNode = prevNode;         prevNode = currentNode;         \/\/ Only '0'         currentNode = currentNode-&amp;gt;left;         continue;     }      char currentChar = findKey[charIndex];\/\/ If findkey.size less than currentNode-&amp;gt;index     int offset = (BIT_COUNT - 1 - ((currentNode-&amp;gt;index - 1) % BIT_COUNT));     bool currentBit = (currentChar &amp;gt;&amp;gt; offset) &amp;amp; 1;      \/\/ Remember prevNode &amp;amp; prevPrevNove     prevPrevNode = prevNode;     prevNode = currentNode;     \/\/ If '1' go right, '0' go left     currentBit  ? currentNode = currentNode-&amp;gt;right                 : currentNode = currentNode-&amp;gt;left; }  return std::make_tuple(currentNode, prevNode, prevPrevNode);  }<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431 \u043d\u0435 \u0441\u043b\u043e\u043c\u0430\u0442\u044c \u043f\u0441\u0438\u0445\u0438\u043a\u0443 \u0441:<\/p>\n<pre><code class=\"cpp\">void Patricia::Erase(const std::string&amp; key){     if(!root)         throw std::runtime_error(\"\\t\\\"\" + key + \"\\\" hadn't found!\\n\");      \/\/ Get delete node, owner delete node and parent owner     std::tuple&lt;Node*, Node*, Node*> delOwnerParentTuple = SearchE(key);     \/\/ A     Node *deleteNode = std::get&lt;0>(delOwnerParentTuple);     \/\/ \u0411     Node *ownerDeleteNode = std::get&lt;1>(delOwnerParentTuple);     \/\/ \u0411 parent     Node *parentOwnerDeleteNode = std::get&lt;2>(delOwnerParentTuple);      if(deleteNode->key != key)         throw std::runtime_error(\"\\t\\\"\" + key + \"\\\" hadn't found!\\n\");          \/\/ If delete node is root and it's one     if(deleteNode == root &amp;&amp; root->left == root){         delete root;         root = nullptr;         return;     }<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0449\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043a\u043e\u0440\u0442\u0435\u0436 \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0435\u0433\u043e \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430, \u0438\u0445 \u0436\u0435 \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043d\u0443\u0436\u043d\u044b\u0439 \u043a\u043b\u044e\u0447. \u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 1 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0440\u0435\u043d\u044c \u043e\u0434\u0438\u043d \u0432 \u0434\u0435\u0440\u0435\u0432\u0435, \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c.<\/p>\n<pre><code class=\"cpp\">    \/\/ If delete node is leaf     if(ownerDeleteNode == deleteNode){         if(parentOwnerDeleteNode->right == deleteNode)             if(deleteNode->right == deleteNode)                 parentOwnerDeleteNode->right = deleteNode->left;             else                 parentOwnerDeleteNode->right = deleteNode->right;         else             if(deleteNode->right == deleteNode)                 parentOwnerDeleteNode->left = deleteNode->left;             else                 parentOwnerDeleteNode->left = deleteNode->right;         delete deleteNode;         return;     }      \/\/ Get owner owner delete node     std::tuple&lt;Node*, Node*, Node*> ownerOwnerTuple =                                                 SearchE(ownerDeleteNode->key);     Node *ownerOwnerDelNode = std::get&lt;1>(ownerOwnerTuple);      \/\/ Change item from owner delete node to delete node     deleteNode->key = ownerDeleteNode->key;     deleteNode->value = ownerDeleteNode->value;<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0439 \u0443\u0437\u0435\u043b &#8212; \u043b\u0438\u0441\u0442, \u0442\u043e \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0438 \u043f\u0440\u0435\u0434\u043a\u0430. \u0418\u043d\u0430\u0447\u0435 \u043e\u043f\u044f\u0442\u044c \u0438\u0449\u0435\u043c, \u043d\u043e \u0443\u0436\u0435 \u0443\u0437\u0435\u043b \u0411, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0435\u0433\u043e \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446, \u0432 \u043a\u043e\u0440\u0442\u0435\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c 2 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e std::get&lt;1> \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 20. \u041c\u0435\u043d\u044f\u0435\u043c \u043a\u043b\u044e\u0447 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <abbr title=\"\u0423\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0443\u0437\u043b\u0430\">\u0443\u0437\u043b\u0430 \u0410<\/abbr> \u043d\u0430 \u043a\u043b\u044e\u0447 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <abbr title=\"\u0412\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0443\u0437\u043b\u0430\">\u0443\u0437\u043b\u0430 \u0411<\/abbr>.<\/p>\n<pre><code class=\"cpp\">    \/\/ If owner delete node is leaf     if(ownerOwnerDelNode == ownerDeleteNode){         if(parentOwnerDeleteNode->right == ownerDeleteNode)             parentOwnerDeleteNode->right = deleteNode;         else             parentOwnerDeleteNode->left = deleteNode;     }     else{         \/\/ Tie parent owner delete node with child         if(parentOwnerDeleteNode->right == ownerDeleteNode)             if(ownerDeleteNode->right == deleteNode)                 parentOwnerDeleteNode->right = ownerDeleteNode->left;             else                 parentOwnerDeleteNode->right = ownerDeleteNode->right;         else             if(ownerDeleteNode->right == deleteNode)                 parentOwnerDeleteNode->left = ownerDeleteNode->left;             else                 parentOwnerDeleteNode->left = ownerDeleteNode->right;          if(ownerOwnerDelNode->right == ownerDeleteNode)             ownerOwnerDelNode->right = deleteNode;         else             ownerOwnerDelNode->left = deleteNode;     }     delete ownerDeleteNode; }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0437\u0435\u043b \u0411 &#8212; \u043b\u0438\u0441\u0442, \u0442\u043e \u0442\u043e\u0433\u0434\u0430 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0441 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u043c \u0443\u0437\u043b\u043e\u043c. \u0418\u043d\u0430\u0447\u0435 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0438 \u0440\u0435\u0431\u0435\u043d\u043a\u0430 \u0443\u0437\u043b\u0430 \u0411, \u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0412 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u0443\u0437\u043b\u0443 \u0410, \u0432 \u043a\u043e\u043d\u0446\u0435 \u0434\u0432\u0443\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0411.<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 &#8212; \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0432\u0441\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0447\u0442\u043e\u0431 \u043d\u0435 \u0431\u044b\u043b\u043e \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<h2>\u0424\u0443\u043d\u043a\u0446\u0438\u044f Clear<\/h2>\n<p>\u041e\u0434\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0443 \u043c\u0435\u043d\u044f \u0432 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435, \u0434\u0440\u0443\u0433\u0430\u044f \u0432 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u043c, \u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0432\u0441\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">void Patricia::Clear(){     if(!root)         return;     if(root != root->left)         ClearNode(root->left);     delete root;     root = nullptr; }<\/code><\/pre>\n<p>\u041f\u0443\u0431\u043b\u0438\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u0440\u0435\u043d\u044c, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u043e\u0434\u0438\u043d \u0432 \u0434\u0435\u0440\u0435\u0432\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435 \u043e\u0434\u0438\u043d, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u0447\u0438\u0449\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430:<\/p>\n<pre><code class=\"cpp\">void Patricia::ClearNode(Node *node){     if(node->left->index > node->index)         ClearNode(node->left);     if(node->right->index > node->index)         ClearNode(node->right);      delete node; }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0432\u0430\u0442\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0443\u0437\u043b\u0430, \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0434\u0435\u0442\u0435\u0439 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0443\u0437\u043b\u0430, \u0430 \u043f\u043e\u0442\u043e\u043c \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0441\u0430\u043c\u0443 \u0432\u0435\u0440\u0448\u0438\u043d\u0443.<\/p>\n<h2>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441<\/h2>\n<p>\u0411\u0440\u0430\u0432\u043e, \u0442\u044b \u0434\u043e\u0448\u0435\u043b \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0438 \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0432\u044b\u0441\u0442\u0440\u0435\u043b\u0438\u043b \u0441\u0435\u0431\u0435 \u0432 \u043d\u043e\u0433\u0443, \u0434\u0430\u0432\u0430\u0439 \u043f\u043e\u0440\u0430\u0434\u0443\u0435\u043c\u0441\u044f, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430\u0448\u0435\u0439 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">\/\/ patr.hpp #pragma once #include &lt;string> #include &lt;tuple>  \/\/ Bits u need in one char const int BIT_COUNT = 5;  typedef class Patricia{ private:     struct Node;     Node *root = nullptr;     \/\/ Search but return 3 nodes     std::tuple&lt;Node*, Node*, Node*> SearchE(const std::string&amp; findKey) const;     \/\/ Search return only 1 node     Node* Search(const std::string&amp; findKey) const;     \/\/ Insert node to tree     void Insert(const std::string&amp; key, const int&amp; value, const size_t&amp; index);     void ClearNode(Node *node); public:     \/\/ Get value from map     int&amp; At(const std::string&amp; findKey) const;     \/\/ Create node with key value and insert to tree     void Add(const std::string&amp; key, int value);     \/\/ Delete node from tree     void Erase(const std::string&amp; key);     void Clear();     ~Patricia(){ Clear(); } } patr;<\/code><\/pre>\n<h2>\u0421\u043e\u0432\u043c\u0435\u0449\u0430\u0435\u043c \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c<\/h2>\n<pre><code class=\"cpp\">#include \"patr.hpp\" #include &lt;iostream> #include &lt;time.h>  int main(){     patr test;     std::string command;     time_t start = clock();     while(std::cin >> command &amp;&amp; command != \"\\x4\"){         if(command == \"+\"){             std::string key; std::cin >> key;             int value; std::cin >> value;             try{                 test.Add(key, value);                 std::cout &lt;&lt; \"\\tSuccessfully!\\n\";             }             catch(const std::runtime_error&amp; e){                 std::cout &lt;&lt; e.what();             }         }         else if(command == \"-\"){             std::string key; std::cin >> key;             try{                 test.Erase(key);                 std::cout &lt;&lt; \"\\tSuccessfully!\\n\";             }             catch(const std::runtime_error&amp; e){                 std::cout &lt;&lt; e.what();             }         }         else if(command == \"clear\" || command == \"new\"){             test.Clear();         }         else if(command == \"get\"){             try{                 std::string key; std::cin >> key;                 std::cout &lt;&lt; test.At(key) &lt;&lt; '\\n';             }             catch(const std::runtime_error&amp; e){                 std::cout &lt;&lt; e.what();             }         }         else if(command != \"\\n\"){             std::cout &lt;&lt; \"\\tCommand \\\"\" + command + \"\\\" isn't available\\n\";         }     }     std::cout &lt;&lt; \"Time: \" &lt;&lt; (double)(clock() - start)\/CLOCKS_PER_SEC &lt;&lt; '\\n';     return 0; } <\/code><\/pre>\n<p>\u0412\u0432\u043e\u0434\u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b(\u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0432\u0435\u0441\u0442\u0438 \u0441\u0432\u043e\u0438) \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u0432\u0435\u0434\u0435\u043c Ctrl+D. \u041a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>+ (key) (value) &#8212; \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0437\u0435\u043b \u0432 \u0434\u0435\u0440\u0435\u0432\u043e<\/p>\n<\/li>\n<li>\n<p>&#8212; (key) &#8212; \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0443\u0437\u0435\u043b \u0438\u0437 \u0434\u0435\u0440\u0435\u0432\u0430<\/p>\n<\/li>\n<li>\n<p>get (key) &#8212; \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 int, \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u044e\u0447<\/p>\n<\/li>\n<li>\n<p>clear &#8212; \u043e\u0447\u0438\u0449\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u0435\u0440\u0435\u0432\u043e<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u044b\u0432\u043e\u0436\u0443 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438, \u0447\u0442\u043e\u0431 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0441\u0435\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 O(h), \u0433\u0434\u0435 h &#8212; \u0432\u044b\u0441\u043e\u0442\u0430 \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0448\u043b\u0438 \u0441\u044e\u0434\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u043c\u043d\u043e\u0439, \u0442\u043e \u0432\u044b \u043c\u043e\u043b\u043e\u0434\u0446\u044b, \u0430 \u044f \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043b \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043c\u0430\u043b\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u0440\u043e \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u044e, \u043e\u043d\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0430\u044f, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041d\u043e \u044f \u0441\u043c\u043e\u0433 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u044e \u0441 \u0441\u0438\u043b\u044c\u043d\u043e\u0439 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c. \u041d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0441\u043a\u0438\u0434\u044b\u0432\u0430\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438, \u0447\u0442\u043e\u0431 \u0432\u0430\u043c \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0449\u0435 \u043f\u043e \u043d\u0438\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438 \u0447\u0438\u0442\u0430\u0442\u044c.<\/p>\n<p><a href=\"https:\/\/github.com\/SaharBezKofe\/PATRICIA\" rel=\"noopener noreferrer nofollow\"><strong>GitHub<\/strong><\/a><\/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\/575720\/\"> https:\/\/habr.com\/ru\/articles\/575720\/<\/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>\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a, \u0445\u0430\u0431\u0440\u043e\u0432\u0447\u0430\u043d\u0435! \u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u043e\u043a\u0443\u043d\u0443\u0442\u044c \u0432\u0430\u0441 \u0432 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435, \u0432\u0441\u0435\u043c\u0438 \u0437\u0430\u0431\u044b\u0442\u043e\u0435, \u0433\u0434\u0435-\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e PATRICIA, \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e \u0435\u0435 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u0421++, \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u043d\u043e, \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u044c\u0442\u0435\u0441\u044c.<\/p>\n<hr\/>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438 \u0438 \u0441\u0440\u0430\u0437\u0443 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041f\u0430\u0442\u0440\u0438\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043c\u0435\u0448\u0435\u043d\u0438\u0435 trie \u0438 DST \u0434\u0435\u0440\u0435\u0432\u0430, \u043d\u0430 \u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a, \u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0431\u0438\u0442\u0430.<\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0438\u043c\u0435\u0435\u0442:<\/p>\n<ol>\n<li>\n<p>\u041a\u043b\u044e\u0447(<code>string key<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435(<code>int value<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0434\u0435\u043a\u0441 \u0431\u0438\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430(<code>size_t index<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043f\u0440\u0430\u0432\u0443\u044e \u0438 \u043b\u0435\u0432\u0443\u044e \u0432\u0435\u0440\u0448\u0438\u043d\u0443(<code>Node *right, *left<\/code>)<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cpp\">struct Patricia::Node{     std::string key;     int value;     size_t index;     Node *right, *left;      Node(const std::string&amp; key, const int&amp; value, const int&amp; index)         : key(key), value(value), index(index), left(nullptr), right(nullptr) { }      ~Node(){} };<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0441\u0430\u043c\u043e\u0439 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u043e \u0435\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445, \u0438\u0445 \u043d\u0435\u043c\u043d\u043e\u0433\u043e. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043f\u0440\u0430\u0432\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043a\u043e\u0440\u043d\u044f &#8212; <code>nullptr<\/code> <strong>\u0432\u0441\u0435\u0433\u0434\u0430<\/strong>. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043a\u0430\u0436\u0434\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438, \u043a\u0440\u043e\u043c\u0435 \u043a\u043e\u0440\u043d\u044f \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441, \u0438 \u0432\u0441\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 <strong>\u0432\u0441\u0435\u0433\u0434\u0430<\/strong> \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u0435\u0440\u0435\u0432\u0430 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0440\u043d\u044f, \u0430 \u043f\u043e\u0438\u0441\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043b\u0435\u0432\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043e\u0442 \u043a\u043e\u0440\u043d\u044f. \u0412-\u0442\u0440\u0435\u0442\u044c\u0438\u0445, \u043b\u0438\u0441\u0442\u043e\u043c \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430, \u043e\u0434\u0438\u043d \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0431\u044f. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">typedef class Patricia{ private:     struct Node;     Node *root = nullptr; public: } patr;<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438 (\u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c value \u0432\u0435\u0440\u0448\u0438\u043d):<\/p>\n<figure class=\"full-width\"><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438 1<\/figcaption><\/figure>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0441\u043f\u0440\u0430\u0432\u0430 \u0441\u0432\u0435\u0440\u0445\u0443 \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u043d \u0448\u0430\u0431\u043b\u043e\u043d, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432 \u0446\u0435\u043d\u0442\u0440\u0435 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441 \u0431\u0438\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u043d\u0430\u0445\u043e\u0434\u044f\u0441\u044c \u0432 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u0435. \u0412\u043d\u0438\u0437\u0443 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0441\u0430\u043c \u043a\u043b\u044e\u0447. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0435\u0440\u0435\u0432\u0430(1).<\/p>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0430\u043b\u0444\u0430\u0432\u0438\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043b\u044e\u0447\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0430\u0442\u0438\u043d\u0441\u043a\u0438\u0435 \u0431\u0443\u043a\u0432\u044b \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0431\u0438\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u043b\u0430\u0442\u0438\u043d\u0441\u043a\u043e\u0439 \u0431\u0443\u043a\u0432\u044b, \u043d\u0430\u043c \u044d\u0442\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f(\u0441\u043e\u0432\u0435\u0442\u0443\u044e \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043a\u043b\u0430\u0434\u043a\u0443).<\/p>\n<figure class=\"full-width\"><figcaption>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0431\u0430\u0439\u0442(\u0441\u0438\u043c\u0432\u043e\u043b) \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f 8 \u0431\u0438\u0442\u0430\u043c\u0438, \u043d\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c\u0438 5-\u044e \u0431\u0438\u0442\u0430\u043c\u0438<\/figcaption><\/figure>\n<h2>\u041f\u043e\u0438\u0441\u043a<\/h2>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0443\u0437\u0435\u043b \u0441 \u043a\u043b\u044e\u0447\u043e\u043c &#171;a&#187;, \u0435\u0433\u043e \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 00001. \u0412\u0430\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u0434\u0435\u0442 \u043d\u0435 \u0441 0, \u0430 \u0441 1, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c &#8216;1&#8217; \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 5.<\/p>\n<p>\u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0440\u043d\u044f, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c <code>nullptr<\/code>, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c, \u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u0441 \u043b\u0435\u0432\u043e\u0433\u043e \u0443\u0437\u043b\u0430, \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u043e \u0443\u0437\u0435\u043b \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c <strong>1<\/strong> \u0438 \u043a\u043b\u044e\u0447\u043e\u043c &#171;y&#187;. \u0411\u0435\u0440\u0435\u043c <abbr title=\"\u0418\u043d\u0434\u0435\u043a\u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u0443 \u043d\u0430\u0441 1 \u0438 \u043a\u043b\u044e\u0447 &quot;y&quot;\">1 \u0438 \u043a\u043b\u044e\u0447 &quot;y&quot;&#187;>\u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441<\/abbr> \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0431\u0438\u0442 \u0438\u0437 <abbr title=\"\u041f\u043e\u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u043a\u043b\u044e\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0449\u0435\u043c, \u0443 \u043d\u0430\u0441 &quot;a&quot; - 00001\">\u0435\u043c, \u0443 \u043d\u0430\u0441&quot;a&quot; &#8212; 00001&#8243;>\u0438\u0441\u043a\u043e\u043c\u043e\u0439 \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438<\/abbr> \u0432 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0438\u0442 \u0440\u0430\u0432\u0435\u043d &#8212; 0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043b\u0435\u0432\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0443\u0437\u0435\u043b \u0440\u0430\u0432\u0435\u043d \u0438\u043d\u0434\u0435\u043a\u0441\u0443 <strong>2<\/strong> \u0438 \u043a\u043b\u044e\u0447\u0443 &#171;l&#187;, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0431\u0438\u0442 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430(&#171;\u0430&#187;) \u043f\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443(2). \u0411\u0438\u0442 \u0440\u0430\u0432\u0435\u043d &#8212; 0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043d\u043e\u0432\u0430 \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043b\u0435\u0432\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0443\u0437\u0435\u043b \u0440\u0430\u0432\u0435\u043d \u0438\u043d\u0434\u0435\u043a\u0441\u0443 <strong>4<\/strong> \u0438 \u043a\u043b\u044e\u0447\u0443 &#171;b&#187;, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0431\u0438\u0442 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430(&#171;\u0430&#187;) \u043f\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443(4). \u0411\u0438\u0442 \u0440\u0430\u0432\u0435\u043d &#8212; 0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043d\u043e\u0432\u0430 \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043b\u0435\u0432\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e.<\/p>\n<p>\u041f\u043e\u0438\u0441\u043a \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0443\u0437\u043b\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443, \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 &#8212; <strong>0<\/strong>, \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 &#8212; <strong>4<\/strong>. \u041f\u043e\u0438\u0441\u043a \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430: &#171;\u0430&#187;, \u0438\u043d\u0434\u0435\u043a\u0441 0 &#8212; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u043e\u0439 \u043d\u0430\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0438\u0441\u043a\u0430\u043b\u0438.<\/p>\n<figure class=\"full-width\"><figcaption>\u0422\u0435\u043c\u043d\u043e \u043e\u0440\u0430\u043d\u0436\u0435\u0432\u044b\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0443\u0437\u043b\u044b, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u0421\u0438\u043d\u0438\u043c &#8212; \u0441\u0442\u0440\u0435\u043b\u043a\u0438, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u041a\u0440\u0430\u0441\u043d\u044b\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0443\u0437\u0435\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f \u043f\u043e\u0438\u0441\u043a \u0421\u0432\u0435\u0440\u0445\u0443 \u0432 \u043a\u0440\u0430\u0441\u043d\u043e\u043c \u043e\u0431\u0440\u0430\u043c\u043b\u0435\u043d\u0438\u0438 \u0443\u043a\u0430\u0437\u0430\u043d \u043c\u0435\u0442\u043e\u0434, \u043a\u043b\u044e\u0447 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0449\u0435\u043c \u0438 \u0435\u0433\u043e \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430<\/figcaption><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 Search. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f currentNode \u0438 prevNode, \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 <code>currentNode->index &lt;= prevNode->index<\/code>.<\/p>\n<pre><code class=\"cpp\">Patricia::Node* Patricia::Search(const std::string&amp; findKey) const{     Node *currentNode = root->left, *prevNode = root;      while(currentNode->index > prevNode->index){         \/\/ Index of char that we need to check         size_t charIndex = (currentNode->index - 1) \/ BIT_COUNT;<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0411\u0435\u0440\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u0437 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0443\u0437\u043b\u0430, \u0432\u044b\u0447\u0438\u0442\u0430\u044f 1. \u0414\u0430\u043b\u044c\u0448\u0435 \u0434\u0435\u043b\u0438\u043c \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 <abbr title=\"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a, \u0443 \u043d\u0430\u0441 5\">\u0442\u044c \u0438\u0437 \u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a, \u0443 \u043d\u0430\u0441 5&#8243;>BIT_COUN<\/abbr>. \u0412\u044b\u0447\u0438\u0442\u0430\u0435\u043c 1 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u043d\u0435 \u0441 0, \u0430 \u0441 1. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0438\u0437 \u043f\u0430\u0442\u0440\u0438\u0446\u0438\u0438 1 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 &#171;m&#187;, \u0443 \u043d\u0435\u0435 \u0438\u043d\u0434\u0435\u043a\u0441 5 &#8212; 1 = 4, \u043f\u0440\u0438 \u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043d\u0430 BIT_COUNT \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c 0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b, \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043d\u0435 \u0432\u044b\u0447\u0438\u0442\u0430\u043b\u0438, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0431\u044b \u0438\u043d\u0434\u0435\u043a\u0441 1, \u0447\u0442\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"cpp\">    \/\/ FindKey is less than need char     if(charIndex >= findKey.size()){       \/\/ Remember prevNode       prevNode = currentNode;       \/\/ Only '0'       currentNode = currentNode->left;       continue;     }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u044b, \u0442\u043e \u043c\u044b &#171;\u043a\u0430\u043a \u0431\u044b&#187; \u0431\u0435\u0440\u0435\u043c \u0431\u0438\u0442 \u0438\u0437 \u043d\u0443\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430, \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u0430\u0432\u043d\u0430 &#8212; 00000, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u044b \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0431\u0438\u0442 0, \u0430 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e \u043b\u0435\u0432\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e, \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044f \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0432 <code>prevNode<\/code>.<\/p>\n<pre><code class=\"cpp\">char currentChar = findKey[charIndex];         \/\/ How many times should we shift to the right         int offset = (BIT_COUNT - 1 - ((currentNode->index - 1) % BIT_COUNT));         \/\/ Get current bit         bool currentBit = (currentChar >> offset) &amp; 1;          \/\/ Remember prevNode         prevNode = currentNode;         \/\/ If '1' go right, '0' go left         currentBit  ? currentNode = currentNode->right                     : currentNode = currentNode->left;     }     return currentNode;<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430, \u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0437\u044f\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438. \u0412\u044b\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435, \u0442.\u0435. \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0434\u043e \u0441\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0431\u0438\u0442\u043e\u0432\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443, \u0447\u0442\u043e\u0431 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0431\u0438\u0442 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u0440\u0430\u0439\u043d\u0435\u043c \u043f\u0440\u0430\u0432\u043e\u043c \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u0437\u044f\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0431\u0438\u0442 \u0438\u0437 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 10001, \u0442\u043e\u0433\u0434\u0430 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u043e 4.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u0438\u0442, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <strong>\u0418 <\/strong>\u0438 <strong>\u0441\u0434\u0432\u0438\u0433\u0430,<\/strong> \u043f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u0435\u0441\u043b\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0431\u0438\u0442\u043e\u0432\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 &#8216;1&#8217;, \u0442\u043e <code>currentBit = true<\/code>, \u0435\u0441\u043b\u0438 &#8216;0&#8217;, \u0442\u043e <code>false<\/code>.<\/p>\n<p>\u0417\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0432\u0435\u0440\u0448\u0438\u043d\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0433\u0430\u0442\u044c \u0435\u0435. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b. \u0418\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 Search \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c <code>currentNode<\/code>, \u043a\u043e\u0433\u0434\u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u0431\u0443\u0434\u0435\u0442 &lt;= \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b. \u041f\u043e\u043b\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">Patricia::Node* Patricia::Search(const std::string&amp; findKey) const{     Node *currentNode = root->left, *prevNode = root;      while(currentNode->index > prevNode->index){         \/\/ Index of char that we need to check         size_t charIndex = (currentNode->index - 1) \/ BIT_COUNT;          \/\/ findKey is less than need char         if(charIndex >= findKey.size()){           \/\/ Remember prevNode             prevNode = currentNode;             \/\/ Only '0'             currentNode = currentNode->left;             continue;         }          char currentChar = findKey[charIndex];         \/\/ How many times should we shift to the right         int offset = (BIT_COUNT - 1 - ((currentNode->index - 1) % BIT_COUNT));         \/\/ Get current bit         bool currentBit = (currentChar >> offset) &amp; 1;          \/\/ Remember prevNode         prevNode = currentNode;         \/\/ If '1' go right, '0' go left         currentBit  ? currentNode = currentNode->right                     : currentNode = currentNode->left;     }     return currentNode; }<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044f \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u0440\u043d\u044f, \u0432\u0441\u0435 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435, \u0438 \u043a\u0430\u0436\u0434\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c Search \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u0440\u043d\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0434\u0440\u0443\u0433\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0442\u043e \u043c\u043e\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 <abbr title=\"\u041d\u0430 2 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u0438\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a root->\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a root->left, \u0435\u0441\u043b\u0438 root = nullptr, \u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043a\u0440\u0430\u0448\u043d\u0435\u0442\u0441\u044f&#187;>\u0441\u043b\u043e\u043c\u0430\u0442\u044c \u0432\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c<\/abbr> :\u0441<\/p>\n<h2>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u044b \u0432 \u0434\u0435\u0440\u0435\u0432\u043e<\/h2>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u044b \u0432 \u0434\u0435\u0440\u0435\u0432\u043e:<\/p>\n<ol>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u0443, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u0432\u044b\u0434\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e (2).<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0431\u0438\u0442\u043e\u0432\u0443\u044e \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u0441\u043d\u043e\u0432\u0430 \u043e\u0442 \u043a\u043e\u0440\u043d\u044f, \u043d\u0430\u0439\u0442\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u0435 <strong><abbr title=\"\u042d\u0442\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0430\u044f \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0438\u0437 \u043f. 2\">\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0438\u0437 \u043f. 2&#8243;>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u043e<\/abbr><\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0443\u0437\u0435\u043b \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u043e\u0439 \u0438 \u0435\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0432\u044f\u0437\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0443\u044e \u0432\u0435\u0440\u0448\u0438\u043d\u0443, \u0434\u0440\u0443\u0433\u043e\u0439 \u043d\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0443\u044e(\u0438\u0437 \u043f. 3). <\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cpp\">void Patricia::Add(const std::string&amp; key, int value){     if(!root){         root = new Node(key, value, 0);         root->left = root;         return;     }      Node *foundNode = Search(key);     if(foundNode->key == key)         throw std::runtime_error(\"\\t\\\"\" + key + \"\\\" already exist!\\n\");<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u044f \u0443\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u0440\u043d\u044f, \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u0441\u043e\u0437\u0434\u0430\u044e \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e, \u0438\u043d\u0430\u0447\u0435 \u043d\u0430\u0445\u043e\u0436\u0443 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e \u043a\u043b\u044e\u0447 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439, \u0435\u0441\u043b\u0438 \u0440\u0430\u0432\u043d\u044b, \u0442\u043e \u0432\u044b\u0434\u0430\u044e \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<pre><code class=\"cpp\">bool run = true;     size_t charIndex = 0;     while(run){         char foundedKey = (foundNode->key.size() > charIndex                             ? foundNode->key[charIndex] : '\\0');         char inputKey   = (key.size() > charIndex ? key[charIndex] : '\\0');         for(size_t i = 0; i &lt; BIT_COUNT; ++i){             bool foundedKeyBit = foundedKey >> (BIT_COUNT - 1 - i) &amp; 1;             bool inputKeyBit = inputKey >> (BIT_COUNT - 1 - i) &amp; 1;             if(foundedKeyBit != inputKeyBit){                 Insert(key, value, charIndex * BIT_COUNT + i + 1);                 run = false;                 break;             }         }         ++charIndex;     }<\/code><\/pre>\n<p>Run \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u043b\u0430\u0433\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0446\u0438\u043a\u043b\u0430 while, <code>charIndex<\/code> &#8212; \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0439, \u043d\u0443\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0439. <code>foundedKey<\/code> &#8212; \u0431\u0435\u0440\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0438\u0437 \u043a\u043b\u044e\u0447\u0430 \u0443\u0437\u043b\u0430, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432\u044b\u0445\u043e\u0434\u0438\u043c \u043b\u0438 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043a\u043b\u044e\u0447\u0430, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u0431\u0435\u0440\u0435\u043c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b <code>'\\0'<\/code>. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441 <code>inputKey<\/code> &#8212; \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0435\u0440\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b \u0438\u0437 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430. <\/p>\n<p>\u0412 \u0446\u0438\u043a\u043b\u0435 for \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0431\u0438\u0442\u0430\u043c, \u0432\u0437\u044f\u0442\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0438 \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f. <code>bool foundedKeyBit<\/code> &#8212; \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u0442 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u043e\u0433\u043e <strong>\u0418<\/strong> \u0441 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441 <code>inputKeyBit<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0431\u0438\u0442\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0435\u0441\u0442\u044c, \u0442\u043e<\/p>\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-402452","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/402452","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=402452"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/402452\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=402452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=402452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=402452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}