{"id":427344,"date":"2024-07-25T21:38:11","date_gmt":"2024-07-25T21:38:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=427344"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=427344","title":{"rendered":"<span>JavaScript: \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b. \u0427\u0430\u0441\u0442\u044c 2<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg\" data-blurred=\"true\"\/> <\/p>\n<p> \u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f!<\/p>\n<p> <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 <a href=\"https:\/\/github.com\/trekhleb\/javascript-algorithms\">\u044d\u0442\u043e\u043c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>. \u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0435\u0440\u0438\u0438.<\/p>\n<p> <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/826424\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a><\/li>\n<\/ul>\n<p> <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0442\u0430\u043a\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u0430\u043a \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u043a\u0443\u0447\u0430, \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u0438 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e.<\/p>\n<p> <\/p>\n<p>\u041a\u043e\u0434, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 \u044d\u0442\u043e\u0439 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u0441\u0435\u0440\u0438\u0438, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/github.com\/harryheman\/algorithms-data-structures\">\u044d\u0442\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>.<\/p>\n<p> <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e? \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\n<p><a name=\"habracut\"><\/a> <\/p>\n<h2 id=\"5-hesh-tablica\">5. \u0425\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430<\/h2>\n<p> <\/p>\n<p><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/strong><\/p>\n<p> <\/p>\n<ul>\n<li><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A5%D0%B5%D1%88-%D1%82%D0%B0%D0%B1%D0%BB%D0%B8%D1%86%D0%B0\">\u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u044f<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=cWbuK7C13HQ\">YouTube<\/a><\/li>\n<\/ul>\n<p> <\/p>\n<p>\u0425\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 (hash table) \u2014 \u044d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 &#171;\u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432&#187; \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u0430\u0440\u044b &#171;\u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435&#187;. \u0425\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0443\u044e \u0445\u044d\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u044e (hash function), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u043b\u044e\u0447 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0441\u043c. <a href=\"https:\/\/www.youtube.com\/watch?v=xV8USnjKGCU\">\u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u0432\u0438\u0434\u0435\u043e \u043f\u0440\u043e \u0445\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a>). \u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u043b\u044e\u0447\u043e\u043c \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0438\u043c\u044f \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u0435\u0433\u043e \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b:<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/rx\/lo\/u4\/rxlou4t-at0bmzeeno2bll_2igs.png\" data-src=\"https:\/\/habrastorage.org\/webt\/rx\/lo\/u4\/rxlou4t-at0bmzeeno2bll_2igs.png\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p>\u0412 \u0438\u0434\u0435\u0430\u043b\u0435 \u0445\u044d\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043d\u0435\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u044b\u0435 \u0445\u044d\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439. \u0422\u0430\u043a\u0438\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u044f\u043c\u0438 (collisions). \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f: \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u0446\u0435\u043f\u043e\u0447\u043a\u0430\u043c\u0438 \u0438 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0439 \u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u0435\u0439.<\/p>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0432\u044f\u0437\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 (linked list) (\u0441\u043c. \u0447\u0430\u0441\u0442\u044c 1, \u0440\u0430\u0437\u0434\u0435\u043b 1):<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/et\/dn\/jw\/etdnjwllpuzxjxnp4l5uwjvqk0i.png\" data-src=\"https:\/\/habrastorage.org\/webt\/et\/dn\/jw\/etdnjwllpuzxjxnp4l5uwjvqk0i.png\"\/> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0439 \u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443:<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/oi\/io\/li\/oiiolihgcyn10bwjxkj4zhtqkcc.png\" data-src=\"https:\/\/habrastorage.org\/webt\/oi\/io\/li\/oiiolihgcyn10bwjxkj4zhtqkcc.png\"\/> <\/p>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong><\/p>\n<p> <\/p>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ data-structures\/hash-table.js \/\/ \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441\u0432\u044f\u0437\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \/\/ (\u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0439) import LinkedList from '.\/linked-list'  \/\/ \u0414\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \/\/ (\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435) const defaultHashTableSize = 32  \/\/ \u0425\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 export default class HashTable {   constructor(size = defaultHashTableSize) {     \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438     \/\/ \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0435\u0435 \u043f\u0443\u0441\u0442\u044b\u043c\u0438 \u0441\u0432\u044f\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u0438\u0441\u043a\u0430\u043c\u0438     this.buckets = new Array(size).fill(null).map(() =&gt; new LinkedList())     \/\/ \u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043a\u043b\u044e\u0447\u0435\u0439     this.keys = {}   } }<\/code><\/pre>\n<p> <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0443\u044e \u0445\u044d\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043a\u043b\u044e\u0447 \u0432 \u0445\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \/\/ (\u0445\u044d\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u044f) hash(key) {   \/\/ \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u044d\u0448\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0443\u043c\u043c\u0430 \u043a\u043e\u0434\u043e\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043a\u043b\u044e\u0447\u0430   \/\/ https:\/\/developer.mozilla.org\/ru\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/charCodeAt   const hash = [...key].reduce((acc, char) =&gt; acc + char.charCodeAt(0), 0)   \/\/ \u0425\u044d\u0448 (\u0438\u043d\u0434\u0435\u043a\u0441) \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b   return hash % this.buckets.length }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043a\u043b\u044e\u0447\u0443:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 set(key, value) {   \/\/ \u0425\u044d\u0448\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u044e\u0447   \/\/ (\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430)   const index = this.hash(key)   \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0445\u044d\u0448 \u043f\u043e \u043a\u043b\u044e\u0447\u0443   this.keys[key] = index   \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a   const bucket = this.buckets[index]   \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0443\u0437\u0435\u043b   \/\/ (\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0443\u0437\u043b\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442)   const node = bucket.find({ cb: (value) =&gt; value.key === key })   \/\/ \u0415\u0441\u043b\u0438 \u0443\u0437\u0435\u043b \u043d\u0435 \u043d\u0430\u0438\u0306\u0434\u0435\u043d   if (!node) {     \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0443\u0437\u0435\u043b     bucket.append({ key, value })   } else {     \/\/ \u0418\u043d\u0430\u0447\u0435, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443\u0437\u043b\u0430     node.value.value = value   } }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043a\u043b\u044e\u0447\u0443:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 remove(key) {   \/\/ \u0425\u044d\u0448\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u044e\u0447   const index = this.hash(key)   \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0445\u044d\u0448 \u043f\u043e \u043a\u043b\u044e\u0447\u0443   delete this.keys[key]   \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a   const bucket = this.buckets[index]   \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0443\u0437\u0435\u043b   const node = bucket.find({ cb: (value) =&gt; value.key === key })   \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0439 \u0443\u0437\u0435\u043b \u0438\u043b\u0438 `null`,   \/\/ \u0435\u0441\u043b\u0438 \u0443\u0437\u0435\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442   return node ? bucket.remove(node.value) : null }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043a\u043b\u044e\u0447\u0443:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 get(key) {   \/\/ \u0425\u044d\u0448\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u044e\u0447   const index = this.hash(key)   \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a   const bucket = this.buckets[index]   \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0443\u0437\u0435\u043b   const node = bucket.find({ cb: (value) =&gt; value.key === key })   \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443\u0437\u043b\u0430 \u0438\u043b\u0438 `null`,   \/\/ \u0435\u0441\u043b\u0438 \u0443\u0437\u0435\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442   return node ? node.value.value : null }<\/code><\/pre>\n<p> <\/p>\n<p>\u041d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 has(key) {   \/\/ https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Object\/hasOwn   return Object.hasOwn(this.keys, key) }  \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438 getKeys() {   return Object.keys(this.keys) }  \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f getValues() {   \/\/ \u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432   return this.buckets.reduce((acc, bucket) =&gt; {     return acc.concat(       \/\/ \u041c\u0435\u0442\u043e\u0434 `toArray` \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0432\u044f\u0437\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0432 \u043c\u0430\u0441\u0441\u0438\u0432       bucket.toArray().map((node) =&gt; node.value.value),     )   }, []) }<\/code><\/pre>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/ \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441\u0432\u044f\u0437\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \/\/ (\u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0439) import LinkedList from '.\/linked-list'  \/\/ \u0414\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \/\/ (\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435) const defaultSize = 32  \/\/ \u0425\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 export default class HashTable {   constructor(size = defaultSize) {     \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438     \/\/ \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0435\u0435 \u043f\u0443\u0441\u0442\u044b\u043c\u0438 \u0441\u0432\u044f\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u0438\u0441\u043a\u0430\u043c\u0438     this.buckets = new Array(size).fill(null).map(() =&gt; new LinkedList())     \/\/ \u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043a\u043b\u044e\u0447\u0435\u0439     this.keys = {}   }    \/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043a\u043b\u044e\u0447 \u0432 \u0445\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435   \/\/ (\u0445\u044d\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u044f)   hash(key) {     \/\/ \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u044d\u0448\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0443\u043c\u043c\u0430 \u043a\u043e\u0434\u043e\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043a\u043b\u044e\u0447\u0430     \/\/ https:\/\/developer.mozilla.org\/ru\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/charCodeAt     const hash = [...key].reduce((acc, char) =&gt; acc + char.charCodeAt(0), 0)     \/\/ \u0425\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b     return hash % this.buckets.length   }    \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443   set(key, value) {     \/\/ \u0425\u044d\u0448\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u044e\u0447     \/\/ (\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430)     const index = this.hash(key)     \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0445\u044d\u0448 \u043f\u043e \u043a\u043b\u044e\u0447\u0443     this.keys[key] = index     \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a     const bucket = this.buckets[index]     \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0443\u0437\u0435\u043b     \/\/ (\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0443\u0437\u043b\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442)     const node = bucket.find({ cb: (value) =&gt; value.key === key })     \/\/ \u0415\u0441\u043b\u0438 \u0443\u0437\u0435\u043b \u043d\u0435 \u043d\u0430\u0438\u0306\u0434\u0435\u043d     if (!node) {       \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0443\u0437\u0435\u043b       bucket.append({ key, value })     } else {       \/\/ \u0418\u043d\u0430\u0447\u0435, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443\u0437\u043b\u0430       node.value.value = value     }   }    \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443   remove(key) {     \/\/ \u0425\u044d\u0448\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u044e\u0447     const index = this.hash(key)     \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0445\u044d\u0448 \u043f\u043e \u043a\u043b\u044e\u0447\u0443     delete this.keys[key]     \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a     const bucket = this.buckets[index]     \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0443\u0437\u0435\u043b     const node = bucket.find({ cb: (value) =&gt; value.key === key })     \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0439 \u0443\u0437\u0435\u043b \u0438\u043b\u0438 `null`,     \/\/ \u0435\u0441\u043b\u0438 \u0443\u0437\u0435\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442     return node ? bucket.remove(node.value) : null   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443   get(key) {     \/\/ \u0425\u044d\u0448\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u044e\u0447     const index = this.hash(key)     \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a     const bucket = this.buckets[index]     \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0443\u0437\u0435\u043b     const node = bucket.find({ cb: (value) =&gt; value.key === key })     \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443\u0437\u043b\u0430 \u0438\u043b\u0438 `null`,     \/\/ \u0435\u0441\u043b\u0438 \u0443\u0437\u0435\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442     return node ? node.value.value : null   }    \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043b\u044e\u0447\u0430   has(key) {     \/\/ https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Object\/hasOwn     return Object.hasOwn(this.keys, key)   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438   getKeys() {     return Object.keys(this.keys)   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f   getValues() {     \/\/ \u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432     return this.buckets.reduce((acc, bucket) =&gt; {       return acc.concat(         \/\/ \u041c\u0435\u0442\u043e\u0434 `toArray` \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0432\u044f\u0437\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0432 \u043c\u0430\u0441\u0441\u0438\u0432         bucket.toArray().map((node) =&gt; node.value.value),       )     }, [])   } }<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<p><strong>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong><\/p>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/ data-structures\/__tests__\/hash-table.test.js import HashTable from '..\/hash-table'  describe('HashTable', () =&gt; {   it('\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430', () =&gt; {     const defaultHashTable = new HashTable()     expect(defaultHashTable.buckets.length).toBe(32)      const biggerHashTable = new HashTable(64)     expect(biggerHashTable.buckets.length).toBe(64)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0445\u044d\u0448 \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439', () =&gt; {     const hashTable = new HashTable()      expect(hashTable.hash('a')).toBe(1)     expect(hashTable.hash('b')).toBe(2)     expect(hashTable.hash('abc')).toBe(6)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c, \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u044f\u043c\u0438', () =&gt; {     const hashTable = new HashTable(3)      expect(hashTable.hash('a')).toBe(1)     expect(hashTable.hash('b')).toBe(2)     expect(hashTable.hash('c')).toBe(0)     expect(hashTable.hash('d')).toBe(1)      hashTable.set('a', 'sky-old')     hashTable.set('a', 'sky')     hashTable.set('b', 'sea')     hashTable.set('c', 'earth')     hashTable.set('d', 'ocean')      expect(hashTable.has('x')).toBe(false)     expect(hashTable.has('b')).toBe(true)     expect(hashTable.has('c')).toBe(true)      const stringifier = (value) =&gt; `${value.key}:${value.value}`      expect(hashTable.buckets[0].toString(stringifier)).toBe('c:earth')     expect(hashTable.buckets[1].toString(stringifier)).toBe('a:sky,d:ocean')     expect(hashTable.buckets[2].toString(stringifier)).toBe('b:sea')      expect(hashTable.get('a')).toBe('sky')     expect(hashTable.get('d')).toBe('ocean')     expect(hashTable.get('x')).toBeNull()      hashTable.remove('a')      expect(hashTable.remove('not-existing')).toBeNull()      expect(hashTable.get('a')).toBeNull()     expect(hashTable.get('d')).toBe('ocean')      hashTable.set('d', 'ocean-new')     expect(hashTable.get('d')).toBe('ocean-new')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u044b', () =&gt; {     const hashTable = new HashTable()      hashTable.set('objectKey', { prop1: 'a', prop2: 'b' })      const object = hashTable.get('objectKey')     expect(object).toBeDefined()     expect(object.prop1).toBe('a')     expect(object.prop2).toBe('b')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438', () =&gt; {     const hashTable = new HashTable(3)      hashTable.set('a', 'sky-old')     hashTable.set('a', 'sky')     hashTable.set('b', 'sea')     hashTable.set('c', 'earth')     hashTable.set('d', 'ocean')      expect(hashTable.getKeys()).toEqual(['a', 'b', 'c', 'd'])     expect(hashTable.has('a')).toBe(true)     expect(hashTable.has('x')).toBe(false)      hashTable.remove('a')      expect(hashTable.has('a')).toBe(false)     expect(hashTable.has('b')).toBe(true)     expect(hashTable.has('x')).toBe(false)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f', () =&gt; {     const hashTable = new HashTable(3)      hashTable.set('a', 'alpha')     hashTable.set('b', 'beta')     hashTable.set('c', 'gamma')      expect(hashTable.getValues()).toEqual(['gamma', 'alpha', 'beta'])   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0443\u0441\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b', () =&gt; {     const hashTable = new HashTable()     expect(hashTable.getValues()).toEqual([])   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0439', () =&gt; {     const hashTable = new HashTable(3)      \/\/ \u041a\u043b\u044e\u0447\u0438 `ab` \u0438 `ba` \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0445\u044d\u0448.     \/\/ \u041d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430     hashTable.set('ab', 'one')     hashTable.set('ba', 'two')      hashTable.set('ac', 'three')      expect(hashTable.getValues()).toEqual(['one', 'two', 'three'])   }) })<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u044b:<\/p>\n<p> <\/p>\n<pre><code class=\"bash\">npm run test .\/data-structures\/__tests__\/hash-table<\/code><\/pre>\n<p> <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/fn\/v7\/a2\/fnv7a2nxeekiywcuseehkfitve0.png\" data-src=\"https:\/\/habrastorage.org\/webt\/fn\/v7\/a2\/fnv7a2nxeekiywcuseehkfitve0.png\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e! \u0414\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p> <\/p>\n<h2 id=\"6-kucha\">6. \u041a\u0443\u0447\u0430<\/h2>\n<p> <\/p>\n<p><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/strong><\/p>\n<p> <\/p>\n<ul>\n<li><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9A%D1%83%D1%87%D0%B0_(%D1%81%D1%82%D1%80%D1%83%D0%BA%D1%82%D1%83%D1%80%D0%B0_%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85)\">\u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u044f<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=bO6h0NbbUEg\">YouTube<\/a><\/li>\n<\/ul>\n<p> <\/p>\n<p>\u041a\u0443\u0447\u0430 (heap) \u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u0430 &#171;\u0434\u0435\u0440\u0435\u0432\u043e&#187; (tree), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 \u043a\u0443\u0447\u0438: \u0435\u0441\u043b\u0438 <code>B<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u0437\u043b\u043e\u043c-\u043f\u043e\u0442\u043e\u043c\u043a\u043e\u043c \u0443\u0437\u043b\u0430 <code>A<\/code>, \u0442\u043e <code>k(A) &gt;= k(B)<\/code>, \u0433\u0434\u0435 <code>k(X)<\/code> \u2014 \u043a\u043b\u044e\u0447 (\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440) \u0443\u0437\u043b\u0430. \u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043a\u043b\u044e\u0447\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u043c \u0443\u0437\u043b\u043e\u043c (root node) \u043a\u0443\u0447\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0430\u043a\u0438\u0435 \u043a\u0443\u0447\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 max-\u043a\u0443\u0447\u0430\u043c\u0438 (max heaps):<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/oj\/f2\/tw\/ojf2tw7pyohegjkuug9tbqbwyre.png\" data-src=\"https:\/\/habrastorage.org\/webt\/oj\/f2\/tw\/ojf2tw7pyohegjkuug9tbqbwyre.png\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e max-\u043a\u0443\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ra\/er\/en\/raerencrfmantpcrfbgdc6iqmji.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ra\/er\/en\/raerencrfmantpcrfbgdc6iqmji.png\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0435\u0440\u0435\u0432\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0440\u043d\u0443\u0442\u044c, \u0442\u043e \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u043c \u0443\u0437\u043b\u043e\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u0422\u0430\u043a\u0438\u0435 \u043a\u0443\u0447\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 min-\u043a\u0443\u0447\u0430\u043c\u0438:<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ir\/5v\/rd\/ir5vrdxssdly_uih82hq7slokr4.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ir\/5v\/rd\/ir5vrdxssdly_uih82hq7slokr4.png\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p>\u041d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e\u0433\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0437\u043b\u043e\u0432-\u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u043a\u0443\u0447\u0438, \u0445\u043e\u0442\u044f \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0438\u0445 \u0447\u0438\u0441\u043b\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0434\u0432\u0443\u0445 (\u0442\u0430\u043a\u0438\u0435 \u043a\u0443\u0447\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 &#171;\u0434\u0432\u043e\u0438\u0447\u043d\u044b\u043c\u0438&#187; \u0438\u043b\u0438 &#171;\u0431\u0438\u043d\u0430\u0440\u043d\u044b\u043c\u0438&#187; (binary)). \u041a\u0443\u0447\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f &#171;\u043e\u0447\u0435\u0440\u0435\u0434\u044c\u044e \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c&#187; (\u0441\u043c. \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437\u0434\u0435\u043b). \u041a\u0443\u0447\u0438 \u0438\u043c\u0435\u044e\u0442 \u0440\u0435\u0448\u0430\u044e\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u0445 \u043d\u0430 \u0433\u0440\u0430\u0444\u0430\u0445, \u0442\u0430\u043a\u0438\u0445, \u043a\u0430\u043a \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u043d\u0430 d-\u043a\u0443\u0447\u0430\u0445 \u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9F%D0%B8%D1%80%D0%B0%D0%BC%D0%B8%D0%B4%D0%B0%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F_%D1%81%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0\">\u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043f\u0438\u0440\u0430\u043c\u0438\u0434\u044b<\/a>.<\/p>\n<p> <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u0443\u0447\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/www.cs.usfca.edu\/~galles\/JavascriptVisual\/Heap.html\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p> <\/p>\n<p><strong>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c<\/strong><\/p>\n<p> <\/p>\n<p>\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u0443\u0447\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0435\u0435 \u0442\u0438\u043f\u0430.<\/p>\n<p> <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0422\u0438\u043f \u043a\u0443\u0447\u0438<\/th>\n<th>find-max<\/th>\n<th>delete-max<\/th>\n<th>insert<\/th>\n<th>increase-key<\/th>\n<th>meld<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/en.wikipedia.org\/wiki\/Binary_heap\">Binary<\/a><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(log n)<\/code><\/td>\n<td><code>O(log n)<\/code><\/td>\n<td><code>O(log n)<\/code><\/td>\n<td><code>\u0398(n)<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/en.wikipedia.org\/wiki\/Leftist_tree\">Leftist<\/a><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(log n)<\/code><\/td>\n<td><code>\u0398(log n)<\/code><\/td>\n<td><code>O(log n)<\/code><\/td>\n<td><code>\u0398(log n)<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/en.wikipedia.org\/wiki\/Binomial_heap\">Binomial<\/a><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(log n)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>O(log n)<\/code><\/td>\n<td><code>O(log n)<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/en.wikipedia.org\/wiki\/Fibonacci_heap\">Fibonacci<\/a><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(log n)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/en.wikipedia.org\/wiki\/Pairing_heap\">Pairing<\/a><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(log n)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>o(log n)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/en.wikipedia.org\/wiki\/Brodal_queue\">Brodal<\/a><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(log n)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/en.wikipedia.org\/w\/index.php?title=Rank-pairing_heap&amp;action=edit&amp;redlink=1\">Rank-pairing<\/a><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(log n)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/en.wikipedia.org\/wiki\/Fibonacci_heap\">Strict Fibonacci<\/a><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(log n)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/en.wikipedia.org\/wiki\/2%E2%80%933_heap\">2-3 heap<\/a><\/td>\n<td><code>O(log n)<\/code><\/td>\n<td><code>O(log n)<\/code><\/td>\n<td><code>O(log n)<\/code><\/td>\n<td><code>\u0398(1)<\/code><\/td>\n<td><code>?<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> <\/p>\n<p>\u0413\u0434\u0435:<\/p>\n<p> <\/p>\n<ul>\n<li><em>find-max (\u0438\u043b\u0438 find-min):<\/em> \u043f\u043e\u0438\u0441\u043a \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 max-\u043a\u0443\u0447\u0435 \u0438\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 min-\u043a\u0443\u0447\u0435, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e (\u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 <em>peek<\/em> \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438\u043b\u0438 \u0441\u0442\u0435\u043a\u0435)<\/li>\n<li><em>delete-max (or delete-min):<\/em> \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u0443\u0437\u043b\u0430<\/li>\n<li><em>insert:<\/em> \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u043a\u0443\u0447\u0443 \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (\u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 <em>push<\/em> \u0432 \u0441\u0442\u0435\u043a\u0435 \u0438\u043b\u0438 <em>enqueue<\/em> \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438)<\/li>\n<li><em>increase-key \u0438\u043b\u0438 decrease-key:<\/em> \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0443\u0437\u043b\u0430<\/li>\n<li><em>meld:<\/em> \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 2 \u043a\u0443\u0447 \u0432 1 \u0441 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u043e\u0432<\/li>\n<\/ul>\n<p> <\/p>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong><\/p>\n<p> <\/p>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u043a\u0443\u0447\u0438.<\/p>\n<p> <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e (\u0438\u043b\u0438 \u0441\u0443\u043f\u0435\u0440, \u0438\u043b\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e) \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f min- \u0438 max-\u043a\u0443\u0447. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ data-structures\/heap\/index.js \/\/ \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0443\u0437\u043b\u043e\u0432 import Comparator from '..\/..\/utils\/comparator'  \/\/ \u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f min- \u0438 max-\u043a\u0443\u0447 export default class Heap {   constructor(fn) {     \/\/ \u041a\u0443\u0447\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u0432     if (new.target === Heap) {       throw new TypeError('\u041a\u0443\u0447\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e!')     }     \/\/ \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0443\u0447\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430     this.heapContainer = []     \/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432     this.compare = new Comparator(fn)   } }<\/code><\/pre>\n<p> <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043b\u0435\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430 getLeftChildIndex(parentIndex) {   return 2 * parentIndex + 1 }  \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430 getRightChildIndex(parentIndex) {   return 2 * parentIndex + 2 }  \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u0440\u0435\u0434\u043a\u0430 getParentIndex(childIndex) {   return Math.floor((childIndex - 1) \/ 2) }  \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u0440\u0435\u0434\u043a\u0430 hasParent(childIndex) {   return this.getParentIndex(childIndex) &gt;= 0 }  \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043b\u0435\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430 hasLeftChild(parentIndex) {   return this.getLeftChildIndex(parentIndex) &lt; this.heapContainer.length }  \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430 hasRightChild(parentIndex) {   return this.getRightChildIndex(parentIndex) &lt; this.heapContainer.length }  \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u0435\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430 leftChild(parentIndex) {   return this.heapContainer[this.getLeftChildIndex(parentIndex)] }  \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430 rightChild(parentIndex) {   return this.heapContainer[this.getRightChildIndex(parentIndex)] }  \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u043a\u0430 parent(childIndex) {   return this.heapContainer[this.getParentIndex(childIndex)] }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0442\u0443 \u043a\u0443\u0447\u0438 isEmpty() {   return this.heapContainer.length === 0 }  \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0443\u0447\u0438 toString() {   return this.heapContainer.toString() }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u0443\u0447\u0438 \u0438 \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u0443\u0447\u0438 \/\/ (\u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u0434\u043b\u044f min-\u043a\u0443\u0447\u0438, \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0434\u043b\u044f max-\u043a\u0443\u0447\u0438; \/\/ \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f) peek() {   if (this.isEmpty()) {     return null   }    return this.heapContainer[0] }  \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u0443\u0447\u0438 poll() {   if (this.isEmpty()) {     return null   }    if (this.heapContainer.length === 1) {     return this.heapContainer.pop()   }    const item = this.heapContainer[0]   \/\/ \u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e   this.heapContainer[0] = this.heapContainer.pop()   \/\/ \u041f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u043c \u043a\u0443\u0447\u0443 \u0432\u043d\u0438\u0437   this.heapifyDown()   \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442   return item }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u0443\u0447\u0443 add(item) {   \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u043e\u043d\u0435\u0446 \u043a\u0443\u0447\u0438   this.heapContainer.push(item)   \/\/ \u041f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u043c \u043a\u0443\u0447\u0443 \u0432\u0432\u0435\u0440\u0445   this.heapifyUp()    return this }  \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043a\u0443\u0447\u0438. \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 remove(item, comparator = this.compare) {   \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432   const numberOfItemsToRemove = this.find(item, comparator).length    for (let i = 0; i &lt; numberOfItemsToRemove; i += 1) {     \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438,     \/\/ \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u0443\u0447\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f     const index = this.find(item, comparator).pop()      \/\/ \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f     if (index === this.heapContainer.length - 1) {       this.heapContainer.pop()     } else {       \/\/ \u0418\u043d\u0430\u0447\u0435, \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430 \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0432\u0448\u0435\u0435\u0441\u044f \u043c\u0435\u0441\u0442\u043e       this.heapContainer[index] = this.heapContainer.pop()       \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442       const parentItem = this.parent(index)        \/\/ \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u043a \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d,       \/\/ \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u043c \u043a\u0443\u0447\u0443 \u0432\u043d\u0438\u0437       if (         this.hasLeftChild(index) &amp;&amp;         (!parentItem ||           this.pairIsInCorrectOrder(parentItem, this.heapContainer[index]))       ) {         this.heapifyDown(index)       } else {         \/\/ \u0418\u043d\u0430\u0447\u0435, \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u043c \u043a\u0443\u0447\u0443 \u0432\u0432\u0435\u0440\u0445         this.heapifyUp(index)       }     }   }    return this }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u043f\u043e\u0438\u0441\u043a\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0440\u0430\u0432\u043d\u044b\u0445 `item`. \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 find(item, comparator = this.compare) {   const indices = []    for (let i = 0; i &lt; this.heapContainer.length; i += 1) {     if (comparator.equal(this.heapContainer[i], item)) {       indices.push(i)     }   }    return indices }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041c\u0435\u043d\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0435\u0441\u0442\u0430\u043c\u0438 swap(indexOne, indexTwo) {   const tmp = this.heapContainer[indexOne]   this.heapContainer[indexOne] = this.heapContainer[indexTwo]   this.heapContainer[indexTwo] = tmp }<\/code><\/pre>\n<p> <\/p>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0433\u043b\u0430\u0432\u043d\u044b\u0445 (\u0438 \u0441\u0430\u043c\u044b\u0445 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f) \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043a\u0443\u0447\u0438.<\/p>\n<p> <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u0443\u0447\u0438 \u0432\u0432\u0435\u0440\u0445:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u0442 \u043a\u0443\u0447\u0443 \u0432\u0432\u0435\u0440\u0445. \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 heapifyUp(customStartIndex) {   \/\/ \u0411\u0435\u0440\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 (\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0438\u043b\u0438 \u043d\u0438\u0436\u043d\u0438\u0439 \u043b\u0435\u0432\u044b\u0439 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435)   \/\/ \u0438 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430\u0432\u0435\u0440\u0445 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043e\u043d \u043d\u0435 \u0431\u0443\u0434\u0435\u0442   \/\/ \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u043f\u0440\u0435\u0434\u043a\u0443   let currentIndex = customStartIndex || this.heapContainer.length - 1    while (     this.hasParent(currentIndex) &amp;&amp;     !this.pairIsInCorrectOrder(       this.parent(currentIndex),       this.heapContainer[currentIndex],     )   ) {     this.swap(currentIndex, this.getParentIndex(currentIndex))     currentIndex = this.getParentIndex(currentIndex)   } }<\/code><\/pre>\n<p> <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u0443\u0447\u0438 \u0432\u043d\u0438\u0437:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u0442 \u043a\u0443\u0447\u0443 \u0432\u043d\u0438\u0437. \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 0) heapifyDown(customStartIndex = 0) {   \/\/ \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0435\u0434\u043a\u0430 \u0441 \u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c\u0438 \u0438   \/\/ \u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u043f\u0440\u0435\u0434\u043a\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u043c   \/\/ (\u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u043c \u0434\u043b\u044f min-\u043a\u0443\u0447\u0438, \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0434\u043b\u044f max-\u043a\u0443\u0447\u0438).   \/\/ \u0417\u0430\u0442\u0435\u043c \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430   let currentIndex = customStartIndex   let nextIndex = null    \/\/ \u041f\u043e\u043a\u0430 \u0435\u0441\u0442\u044c \u043b\u0435\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043c\u043e\u043a   while (this.hasLeftChild(currentIndex)) {     \/\/ \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u0430\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043c\u043e\u043a \u0438     \/\/ \u043f\u043e\u0442\u043e\u043c\u043a\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435     if (       this.hasRightChild(currentIndex) &amp;&amp;       this.pairIsInCorrectOrder(         this.rightChild(currentIndex),         this.leftChild(currentIndex),       )     ) {       \/\/ \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430       nextIndex = this.getRightChildIndex(currentIndex)     } else {       \/\/ \u0418\u043d\u0430\u0447\u0435, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441 \u043b\u0435\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430       nextIndex = this.getLeftChildIndex(currentIndex)     }      \/\/ \u041f\u0440\u0435\u0440\u044b\u0432\u0430\u0435\u043c \u0446\u0438\u043a\u043b, \u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435     if (       this.pairIsInCorrectOrder(         this.heapContainer[currentIndex],         this.heapContainer[nextIndex],       )     ) {       break     }      \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0435\u0441\u0442\u0430\u043c\u0438     this.swap(currentIndex, nextIndex)     \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441     currentIndex = nextIndex   } }<\/code><\/pre>\n<p> <\/p>\n<p>\u0417\u0430\u0433\u043b\u0443\u0448\u043a\u0430 (\u0438\u043b\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u0438\u043b\u0438 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442) \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u043f\u0430\u0440\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u0443\u0447\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0430 \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435. \/\/ \u0414\u043b\u044f min-\u043a\u0443\u0447\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d \u0432\u0442\u043e\u0440\u043e\u043c\u0443. \/\/ \u0414\u043b\u044f max-\u043a\u0443\u0447\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d \u0432\u0442\u043e\u0440\u043e\u043c\u0443. \/\/ \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \/\/ (min-\u043a\u0443\u0447\u0435\u0439 \u0438 max-\u043a\u0443\u0447\u0435\u0439) pairIsInCorrectOrder(firstElement, secondElement) {   throw new Error('\u041c\u0435\u0442\u043e\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d!') }<\/code><\/pre>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u0443\u0447\u0438:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/ \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0443\u0437\u043b\u043e\u0432 import Comparator from '..\/..\/utils\/comparator'  \/\/ \u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f min- \u0438 max-\u043a\u0443\u0447 export default class Heap {   constructor(fn) {     \/\/ \u041a\u0443\u0447\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u0432     if (new.target === Heap) {       throw new TypeError('\u041a\u0443\u0447\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e!')     }     \/\/ \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0443\u0447\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430     this.heapContainer = []     \/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432     this.compare = new Comparator(fn)   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043b\u0435\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430   getLeftChildIndex(parentIndex) {     return 2 * parentIndex + 1   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430   getRightChildIndex(parentIndex) {     return 2 * parentIndex + 2   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u0440\u0435\u0434\u043a\u0430   getParentIndex(childIndex) {     return Math.floor((childIndex - 1) \/ 2)   }    \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u0440\u0435\u0434\u043a\u0430   hasParent(childIndex) {     return this.getParentIndex(childIndex) &gt;= 0   }    \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043b\u0435\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430   hasLeftChild(parentIndex) {     return this.getLeftChildIndex(parentIndex) &lt; this.heapContainer.length   }    \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430   hasRightChild(parentIndex) {     return this.getRightChildIndex(parentIndex) &lt; this.heapContainer.length   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u0435\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430   leftChild(parentIndex) {     return this.heapContainer[this.getLeftChildIndex(parentIndex)]   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430   rightChild(parentIndex) {     return this.heapContainer[this.getRightChildIndex(parentIndex)]   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u043a\u0430   parent(childIndex) {     return this.heapContainer[this.getParentIndex(childIndex)]   }    \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0442\u0443 \u043a\u0443\u0447\u0438   isEmpty() {     return this.heapContainer.length === 0   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0443\u0447\u0438   toString() {     return this.heapContainer.toString()   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u0443\u0447\u0438   \/\/ (\u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u0434\u043b\u044f min-\u043a\u0443\u0447\u0438, \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0434\u043b\u044f max-\u043a\u0443\u0447\u0438;   \/\/ \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f)   peek() {     if (this.isEmpty()) {       return null     }      return this.heapContainer[0]   }    \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u0443\u0447\u0438   poll() {     if (this.isEmpty()) {       return null     }      if (this.heapContainer.length === 1) {       return this.heapContainer.pop()     }      const item = this.heapContainer[0]     \/\/ \u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e     this.heapContainer[0] = this.heapContainer.pop()     \/\/ \u041f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u043c \u043a\u0443\u0447\u0443 \u0432\u043d\u0438\u0437     this.heapifyDown()     \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442     return item   }    \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u0443\u0447\u0443   add(item) {     \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u043e\u043d\u0435\u0446 \u043a\u0443\u0447\u0438     this.heapContainer.push(item)     \/\/ \u041f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u043c \u043a\u0443\u0447\u0443 \u0432\u0432\u0435\u0440\u0445     this.heapifyUp()      return this   }    \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043a\u0443\u0447\u0438.   \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432   remove(item, comparator = this.compare) {     \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432     const numberOfItemsToRemove = this.find(item, comparator).length      for (let i = 0; i &lt; numberOfItemsToRemove; i += 1) {       \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438,       \/\/ \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u0443\u0447\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f       const index = this.find(item, comparator).pop()        \/\/ \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f       if (index === this.heapContainer.length - 1) {         this.heapContainer.pop()       } else {         \/\/ \u0418\u043d\u0430\u0447\u0435, \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430 \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0432\u0448\u0435\u0435\u0441\u044f \u043c\u0435\u0441\u0442\u043e         this.heapContainer[index] = this.heapContainer.pop()         \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442         const parentItem = this.parent(index)          \/\/ \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u043a \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d,         \/\/ \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u043c \u043a\u0443\u0447\u0443 \u0432\u043d\u0438\u0437         if (           this.hasLeftChild(index) &amp;&amp;           (!parentItem ||             this.pairIsInCorrectOrder(parentItem, this.heapContainer[index]))         ) {           this.heapifyDown(index)         } else {           \/\/ \u0418\u043d\u0430\u0447\u0435, \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u043c \u043a\u0443\u0447\u0443 \u0432\u0432\u0435\u0440\u0445           this.heapifyUp(index)         }       }     }      return this   }    \/\/ \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0440\u0430\u0432\u043d\u044b\u0445 `item`.   \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432   find(item, comparator = this.compare) {     const indices = []      for (let i = 0; i &lt; this.heapContainer.length; i += 1) {       if (comparator.equal(this.heapContainer[i], item)) {         indices.push(i)       }     }      return indices   }    \/\/ \u041c\u0435\u043d\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0435\u0441\u0442\u0430\u043c\u0438   swap(indexOne, indexTwo) {     const tmp = this.heapContainer[indexOne]     this.heapContainer[indexOne] = this.heapContainer[indexTwo]     this.heapContainer[indexTwo] = tmp   }    \/\/ \u041f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u0442 \u043a\u0443\u0447\u0443 \u0432\u0432\u0435\u0440\u0445.   \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438   heapifyUp(customStartIndex) {     \/\/ \u0411\u0435\u0440\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 (\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0438\u043b\u0438 \u043d\u0438\u0436\u043d\u0438\u0439 \u043b\u0435\u0432\u044b\u0439 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435)     \/\/ \u0438 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430\u0432\u0435\u0440\u0445 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043e\u043d \u043d\u0435 \u0431\u0443\u0434\u0435\u0442     \/\/ \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u043f\u0440\u0435\u0434\u043a\u0443     let currentIndex = customStartIndex || this.heapContainer.length - 1      while (       this.hasParent(currentIndex) &amp;&amp;       !this.pairIsInCorrectOrder(         this.parent(currentIndex),         this.heapContainer[currentIndex],       )     ) {       this.swap(currentIndex, this.getParentIndex(currentIndex))       currentIndex = this.getParentIndex(currentIndex)     }   }    \/\/ \u041f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u0435\u0442 \u043a\u0443\u0447\u0443 \u0432\u043d\u0438\u0437.   \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 0)   heapifyDown(customStartIndex = 0) {     \/\/ \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0435\u0434\u043a\u0430 \u0441 \u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c\u0438 \u0438     \/\/ \u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u043f\u0440\u0435\u0434\u043a\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u043c     \/\/ (\u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u043c \u0434\u043b\u044f min-\u043a\u0443\u0447\u0438 \u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0434\u043b\u044f max-\u043a\u0443\u0447\u0438).     \/\/ \u0417\u0430\u0442\u0435\u043c \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430     let currentIndex = customStartIndex     let nextIndex = null      \/\/ \u041f\u043e\u043a\u0430 \u0435\u0441\u0442\u044c \u043b\u0435\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043c\u043e\u043a     while (this.hasLeftChild(currentIndex)) {       \/\/ \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u0430\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043c\u043e\u043a \u0438       \/\/ \u043f\u043e\u0442\u043e\u043c\u043a\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435       if (         this.hasRightChild(currentIndex) &amp;&amp;         this.pairIsInCorrectOrder(           this.rightChild(currentIndex),           this.leftChild(currentIndex),         )       ) {         \/\/ \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430         nextIndex = this.getRightChildIndex(currentIndex)       } else {         \/\/ \u0418\u043d\u0430\u0447\u0435, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441 \u043b\u0435\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430         nextIndex = this.getLeftChildIndex(currentIndex)       }        \/\/ \u041f\u0440\u0435\u0440\u044b\u0432\u0430\u0435\u043c \u0446\u0438\u043a\u043b, \u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435       if (         this.pairIsInCorrectOrder(           this.heapContainer[currentIndex],           this.heapContainer[nextIndex],         )       ) {         break       }        \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0435\u0441\u0442\u0430\u043c\u0438       this.swap(currentIndex, nextIndex)       \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441       currentIndex = nextIndex     }   }    \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u043f\u0430\u0440\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u0443\u0447\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0430 \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.   \/\/ \u0414\u043b\u044f min-\u043a\u0443\u0447\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d \u0432\u0442\u043e\u0440\u043e\u043c\u0443.   \/\/ \u0414\u043b\u044f max-\u043a\u0443\u0447\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d \u0432\u0442\u043e\u0440\u043e\u043c\u0443.   \/\/ \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438   \/\/ (min-\u043a\u0443\u0447\u0435\u0439 \u0438 max-\u043a\u0443\u0447\u0435\u0439)   pairIsInCorrectOrder(firstElement, secondElement) {     throw new Error('\u041c\u0435\u0442\u043e\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d!')   } }<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <code>pairIsInCorrectOrder<\/code>.<\/p>\n<p> <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430 min-\u043a\u0443\u0447\u0438:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ data-structures\/heap\/min-heap.js import Heap from '.'  export default class MinHeap extends Heap {   pairIsInCorrectOrder(firstElement, secondElement) {     \/\/ \u041f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d \u0432\u0442\u043e\u0440\u043e\u043c\u0443     return this.compare.lessThanOrEqual(firstElement, secondElement)   } }<\/code><\/pre>\n<p> <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430 max-\u043a\u0443\u0447\u0438:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ data-structures\/heap\/max-heap.js import Heap from '.'  export default class MaxHeap extends Heap {   pairIsInCorrectOrder(firstElement, secondElement) {     \/\/ \u041f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d \u0432\u0442\u043e\u0440\u043e\u043c\u0443     return this.compare.greaterThanOrEqual(firstElement, secondElement)   } }<\/code><\/pre>\n<p> <\/p>\n<p><strong>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong><\/p>\n<p> <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u043a\u0443\u0447\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p> <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0441\u0443\u043f\u0435\u0440\u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ data-structures\/heap\/__tests__\/heap.test.js import Heap from '..'  describe('Heap', () =&gt; {   it('\u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u0443\u0447\u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e', () =&gt; {     const instantiateHeap = () =&gt; {       const heap = new Heap()       heap.add(5)     }      expect(instantiateHeap).toThrow()   }) })<\/code><\/pre>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 min-\u043a\u0443\u0447\u0438:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/ data-structures\/heap\/__tests__\/min-heap.test.js import MinHeap from '..\/min-heap' import Comparator from '..\/..\/..\/utils\/comparator'  describe('MinHeap', () =&gt; {   it('\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u0443\u044e min-\u043a\u0443\u0447\u0443', () =&gt; {     const minHeap = new MinHeap()      expect(minHeap).toBeDefined()     expect(minHeap.peek()).toBeNull()     expect(minHeap.isEmpty()).toBe(true)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043a\u0443\u0447\u0443 \u0438 \u043f\u0440\u043e\u0441\u0435\u044f\u0442\u044c \u0435\u0435 \u0432\u0432\u0435\u0440\u0445', () =&gt; {     const minHeap = new MinHeap()      minHeap.add(5)     expect(minHeap.isEmpty()).toBe(false)     expect(minHeap.peek()).toBe(5)     expect(minHeap.toString()).toBe('5')      minHeap.add(3)     expect(minHeap.peek()).toBe(3)     expect(minHeap.toString()).toBe('3,5')      minHeap.add(10)     expect(minHeap.peek()).toBe(3)     expect(minHeap.toString()).toBe('3,5,10')      minHeap.add(1)     expect(minHeap.peek()).toBe(1)     expect(minHeap.toString()).toBe('1,3,10,5')      minHeap.add(1)     expect(minHeap.peek()).toBe(1)     expect(minHeap.toString()).toBe('1,1,10,5,3')      expect(minHeap.poll()).toBe(1)     expect(minHeap.toString()).toBe('1,3,10,5')      expect(minHeap.poll()).toBe(1)     expect(minHeap.toString()).toBe('3,5,10')      expect(minHeap.poll()).toBe(3)     expect(minHeap.toString()).toBe('5,10')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043a\u0443\u0447\u0438 \u0438 \u043f\u0440\u043e\u0441\u0435\u044f\u0442\u044c \u0435\u0435 \u0432\u043d\u0438\u0437', () =&gt; {     const minHeap = new MinHeap()      minHeap.add(5)     minHeap.add(3)     minHeap.add(10)     minHeap.add(11)     minHeap.add(1)      expect(minHeap.toString()).toBe('1,3,10,11,5')      expect(minHeap.poll()).toBe(1)     expect(minHeap.toString()).toBe('3,5,10,11')      expect(minHeap.poll()).toBe(3)     expect(minHeap.toString()).toBe('5,11,10')      expect(minHeap.poll()).toBe(5)     expect(minHeap.toString()).toBe('10,11')      expect(minHeap.poll()).toBe(10)     expect(minHeap.toString()).toBe('11')      expect(minHeap.poll()).toBe(11)     expect(minHeap.toString()).toBe('')      expect(minHeap.poll()).toBeNull()     expect(minHeap.toString()).toBe('')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0435\u044f\u0442\u044c \u043a\u0443\u0447\u0443 \u0432\u043d\u0438\u0437 \u043f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0442\u043a\u0435', () =&gt; {     const minHeap = new MinHeap()      minHeap.add(3)     minHeap.add(12)     minHeap.add(10)      expect(minHeap.toString()).toBe('3,12,10')      minHeap.add(11)     expect(minHeap.toString()).toBe('3,11,10,12')      expect(minHeap.poll()).toBe(3)     expect(minHeap.toString()).toBe('10,11,12')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432', () =&gt; {     const minHeap = new MinHeap()      minHeap.add(3)     minHeap.add(12)     minHeap.add(10)     minHeap.add(11)     minHeap.add(11)      expect(minHeap.toString()).toBe('3,11,10,12,11')      expect(minHeap.find(5)).toEqual([])     expect(minHeap.find(3)).toEqual([0])     expect(minHeap.find(11)).toEqual([1, 4])   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043a\u0443\u0447\u0438 \u0441 \u0435\u0435 \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u043d\u0438\u0437', () =&gt; {     const minHeap = new MinHeap()      minHeap.add(3)     minHeap.add(12)     minHeap.add(10)     minHeap.add(11)     minHeap.add(11)      expect(minHeap.toString()).toBe('3,11,10,12,11')      expect(minHeap.remove(3).toString()).toEqual('10,11,11,12')     expect(minHeap.remove(3).peek()).toEqual(10)     expect(minHeap.remove(11).toString()).toEqual('10,12')     expect(minHeap.remove(3).peek()).toEqual(10)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043a\u0443\u0447\u0438 \u0441 \u0435\u0435 \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u0432\u0435\u0440\u0445', () =&gt; {     const minHeap = new MinHeap()      minHeap.add(3)     minHeap.add(10)     minHeap.add(5)     minHeap.add(6)     minHeap.add(7)     minHeap.add(4)     minHeap.add(6)     minHeap.add(8)     minHeap.add(2)     minHeap.add(1)      expect(minHeap.toString()).toBe('1,2,4,6,3,5,6,10,8,7')     expect(minHeap.remove(8).toString()).toEqual('1,2,4,6,3,5,6,10,7')     expect(minHeap.remove(7).toString()).toEqual('1,2,4,6,3,5,6,10')     expect(minHeap.remove(1).toString()).toEqual('2,3,4,6,10,5,6')     expect(minHeap.remove(2).toString()).toEqual('3,6,4,6,10,5')     expect(minHeap.remove(6).toString()).toEqual('3,5,4,10')     expect(minHeap.remove(10).toString()).toEqual('3,5,4')     expect(minHeap.remove(5).toString()).toEqual('3,4')     expect(minHeap.remove(3).toString()).toEqual('4')     expect(minHeap.remove(4).toString()).toEqual('')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043a\u0443\u0447\u0438, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f', () =&gt; {     const minHeap = new MinHeap()     minHeap.add('dddd')     minHeap.add('ccc')     minHeap.add('bb')     minHeap.add('a')      expect(minHeap.toString()).toBe('a,bb,ccc,dddd')      const comparator = new Comparator((a, b) =&gt; {       if (a.length === b.length) {         return 0       }        return a.length &lt; b.length ? -1 : 1     })      minHeap.remove('hey', comparator)     expect(minHeap.toString()).toBe('a,bb,dddd')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043a\u0443\u0447\u0438 \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0434\u0435\u0440\u0435\u0432\u0430', () =&gt; {     const minHeap = new MinHeap()      minHeap.add(1)     minHeap.add(2)     minHeap.add(3)     minHeap.add(4)     minHeap.add(5)     minHeap.add(6)     minHeap.add(7)     minHeap.add(8)     minHeap.add(9)      expect(minHeap.toString()).toBe('1,2,3,4,5,6,7,8,9')      minHeap.remove(2)     expect(minHeap.toString()).toBe('1,4,3,8,5,6,7,9')      minHeap.remove(4)     expect(minHeap.toString()).toBe('1,5,3,8,9,6,7')   }) })<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 max-\u043a\u0443\u0447\u0438:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/ data-structures\/heap\/__tests__\/max-heap.test.js import MaxHeap from '..\/max-heap' import Comparator from '..\/..\/..\/utils\/comparator'  describe('MaxHeap', () =&gt; {   it('\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u0443\u044e max-\u043a\u0443\u0447\u0443', () =&gt; {     const maxHeap = new MaxHeap()      expect(maxHeap).toBeDefined()     expect(maxHeap.peek()).toBeNull()     expect(maxHeap.isEmpty()).toBe(true)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043a\u0443\u0447\u0443 \u0438 \u043f\u0440\u043e\u0441\u0435\u044f\u0442\u044c \u0435\u0435 \u0432\u0432\u0435\u0440\u0445', () =&gt; {     const maxHeap = new MaxHeap()      maxHeap.add(5)     expect(maxHeap.isEmpty()).toBe(false)     expect(maxHeap.peek()).toBe(5)     expect(maxHeap.toString()).toBe('5')      maxHeap.add(3)     expect(maxHeap.peek()).toBe(5)     expect(maxHeap.toString()).toBe('5,3')      maxHeap.add(10)     expect(maxHeap.peek()).toBe(10)     expect(maxHeap.toString()).toBe('10,3,5')      maxHeap.add(1)     expect(maxHeap.peek()).toBe(10)     expect(maxHeap.toString()).toBe('10,3,5,1')      maxHeap.add(1)     expect(maxHeap.peek()).toBe(10)     expect(maxHeap.toString()).toBe('10,3,5,1,1')      expect(maxHeap.poll()).toBe(10)     expect(maxHeap.toString()).toBe('5,3,1,1')      expect(maxHeap.poll()).toBe(5)     expect(maxHeap.toString()).toBe('3,1,1')      expect(maxHeap.poll()).toBe(3)     expect(maxHeap.toString()).toBe('1,1')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043a\u0443\u0447\u0438 \u0438 \u043f\u0440\u043e\u0441\u0435\u044f\u0442\u044c \u0435\u0435 \u0432\u043d\u0438\u0437', () =&gt; {     const maxHeap = new MaxHeap()      maxHeap.add(5)     maxHeap.add(3)     maxHeap.add(10)     maxHeap.add(11)     maxHeap.add(1)      expect(maxHeap.toString()).toBe('11,10,5,3,1')      expect(maxHeap.poll()).toBe(11)     expect(maxHeap.toString()).toBe('10,3,5,1')      expect(maxHeap.poll()).toBe(10)     expect(maxHeap.toString()).toBe('5,3,1')      expect(maxHeap.poll()).toBe(5)     expect(maxHeap.toString()).toBe('3,1')      expect(maxHeap.poll()).toBe(3)     expect(maxHeap.toString()).toBe('1')      expect(maxHeap.poll()).toBe(1)     expect(maxHeap.toString()).toBe('')      expect(maxHeap.poll()).toBeNull()     expect(maxHeap.toString()).toBe('')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0435\u044f\u0442\u044c \u043a\u0443\u0447\u0443 \u0432\u043d\u0438\u0437 \u043f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0442\u043a\u0435', () =&gt; {     const maxHeap = new MaxHeap()      maxHeap.add(3)     maxHeap.add(12)     maxHeap.add(10)      expect(maxHeap.toString()).toBe('12,3,10')      maxHeap.add(11)     expect(maxHeap.toString()).toBe('12,11,10,3')      expect(maxHeap.poll()).toBe(12)     expect(maxHeap.toString()).toBe('11,3,10')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432', () =&gt; {     const maxHeap = new MaxHeap()      maxHeap.add(3)     maxHeap.add(12)     maxHeap.add(10)     maxHeap.add(11)     maxHeap.add(11)      expect(maxHeap.toString()).toBe('12,11,10,3,11')      expect(maxHeap.find(5)).toEqual([])     expect(maxHeap.find(12)).toEqual([0])     expect(maxHeap.find(11)).toEqual([1, 4])   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043a\u0443\u0447\u0438 \u0441 \u0435\u0435 \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u043d\u0438\u0437', () =&gt; {     const maxHeap = new MaxHeap()      maxHeap.add(3)     maxHeap.add(12)     maxHeap.add(10)     maxHeap.add(11)     maxHeap.add(11)      expect(maxHeap.toString()).toBe('12,11,10,3,11')      expect(maxHeap.remove(12).toString()).toEqual('11,11,10,3')     expect(maxHeap.remove(12).peek()).toEqual(11)     expect(maxHeap.remove(11).toString()).toEqual('10,3')     expect(maxHeap.remove(10).peek()).toEqual(3)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043a\u0443\u0447\u0438 \u0441 \u0435\u0435 \u043f\u0440\u043e\u0441\u0435\u0438\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u0432\u0435\u0440\u0445', () =&gt; {     const maxHeap = new MaxHeap()      maxHeap.add(3)     maxHeap.add(10)     maxHeap.add(5)     maxHeap.add(6)     maxHeap.add(7)     maxHeap.add(4)     maxHeap.add(6)     maxHeap.add(8)     maxHeap.add(2)     maxHeap.add(1)      expect(maxHeap.toString()).toBe('10,8,6,7,6,4,5,3,2,1')     expect(maxHeap.remove(4).toString()).toEqual('10,8,6,7,6,1,5,3,2')     expect(maxHeap.remove(3).toString()).toEqual('10,8,6,7,6,1,5,2')     expect(maxHeap.remove(5).toString()).toEqual('10,8,6,7,6,1,2')     expect(maxHeap.remove(10).toString()).toEqual('8,7,6,2,6,1')     expect(maxHeap.remove(6).toString()).toEqual('8,7,1,2')     expect(maxHeap.remove(2).toString()).toEqual('8,7,1')     expect(maxHeap.remove(1).toString()).toEqual('8,7')     expect(maxHeap.remove(7).toString()).toEqual('8')     expect(maxHeap.remove(8).toString()).toEqual('')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043a\u0443\u0447\u0438, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f', () =&gt; {     const maxHeap = new MaxHeap()     maxHeap.add('a')     maxHeap.add('bb')     maxHeap.add('ccc')     maxHeap.add('dddd')      expect(maxHeap.toString()).toBe('dddd,ccc,bb,a')      const comparator = new Comparator((a, b) =&gt; {       if (a.length === b.length) {         return 0       }        return a.length &lt; b.length ? -1 : 1     })      maxHeap.remove('hey', comparator)     expect(maxHeap.toString()).toBe('dddd,a,bb')   }) })<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u044b:<\/p>\n<p> <\/p>\n<pre><code class=\"bash\">npm run test .\/data-structures\/heap<\/code><\/pre>\n<p> <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ci\/7e\/d4\/ci7ed4irdsdl-chkftaeksjtifa.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ci\/7e\/d4\/ci7ed4irdsdl-chkftaeksjtifa.png\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<h2 id=\"7-ochered-s-prioritetom\">7. \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c<\/h2>\n<p> <\/p>\n<p><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/strong><\/p>\n<p> <\/p>\n<ul>\n<li><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9E%D1%87%D0%B5%D1%80%D0%B5%D0%B4%D1%8C_%D1%81_%D0%BF%D1%80%D0%B8%D0%BE%D1%80%D0%B8%D1%82%D0%B5%D1%82%D0%BE%D0%BC_(%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5)\">\u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u044f<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=y_2toG5-j_M\">YouTube<\/a><\/li>\n<\/ul>\n<p> <\/p>\n<p>\u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c (priority queue) \u2014 \u044d\u0442\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c (\u0441\u043c. \u0447\u0430\u0441\u0442\u044c 1, \u0440\u0430\u0437\u0434\u0435\u043b 3) \u0438\u043b\u0438 \u0441\u0442\u0435\u043a (\u0441\u043c. \u0447\u0430\u0441\u0442\u044c 1, \u0440\u0430\u0437\u0434\u0435\u043b 4), \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u043d\u0435\u0439 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u043c\u0435\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 &#171;\u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442&#187; (priority). \u042d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u0438\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u0441 \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u0438\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c. \u0415\u0441\u043b\u0438 \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442, \u043e\u043d\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438\u0445 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.<\/p>\n<p> <\/p>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u0447\u0430\u0441\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0443\u0447, \u043e\u043d\u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f. \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u2014 \u044d\u0442\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0430\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f, \u0432\u0440\u043e\u0434\u0435 &#171;\u0441\u043f\u0438\u0441\u043a\u0430&#187; (list) \u0438\u043b\u0438 &#171;\u043a\u0430\u0440\u0442\u044b&#187; (map). \u041a\u0430\u043a \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0432\u044f\u0437\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 (\u0441\u043c. \u0447\u0430\u0441\u0442\u044c 1, \u0440\u0430\u0437\u0434\u0435\u043b 1) \u0438\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0442\u0430\u043a \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0443\u0447\u0438 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430.<\/p>\n<p> <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/priority-queue-visualizer.vercel.app\/\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p> <\/p>\n<p><strong>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c<\/strong><\/p>\n<p> <\/p>\n<p>\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 O(n) \u0438\u043b\u0438 O(n*log(n)) (\u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438).<\/p>\n<p> <\/p>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong><\/p>\n<p> <\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f min-\u043a\u0443\u0447\u0435\u0439 (\u0441\u043c. \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0440\u0430\u0437\u0434\u0435\u043b).<\/p>\n<p> <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ data-structures\/priority-queue.js \/\/ \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0443\u0437\u043b\u043e\u0432 import Comparator from '..\/utils\/comparator' \/\/ \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 min-\u043a\u0443\u0447\u0438 import MinHeap from '.\/heap\/min-heap'  \/\/ \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c. \/\/ \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 min-\u043a\u0443\u0447\u0438 export default class PriorityQueue extends MinHeap {   constructor() {     \/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c min-\u043a\u0443\u0447\u0443     super()     \/\/ \u041a\u0430\u0440\u0442\u0430 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u0432     this.priorities = new Map()     \/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432     this.compare = new Comparator(this.comparePriorities.bind(this))   } }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\/\u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442. \/\/ \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 (\u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 `priority`), \/\/ \u0442\u0435\u043c \"\u0432\u044b\u0448\u0435\" \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 add(item, priority = 0) {   \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b   this.priorities.set(item, priority)   \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u0443\u0447\u0443   super.add(item)    return this }  \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 remove(item, compare) {   \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043a\u0443\u0447\u0438   super.remove(item, compare)   \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b   this.priorities.delete(item)    return this }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442. \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 changePriority(item, priority) {   \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438   this.remove(item, new Comparator(this.compareValues))   \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441 \u043d\u043e\u0432\u044b\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c   this.add(item, priority)    return this }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u043f\u043e\u0438\u0441\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0418\u0449\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e. \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 findByValue(item) {   return this.find(item, new Comparator(this.compareValues)) }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 hasValue(item) {   return this.findByValue(item).length &gt; 0 }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430\u043c \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b comparePriorities(a, b) {   \/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439,   \/\/ \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0435\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b   return this.compareValues(this.priorities.get(a), this.priorities.get(b)) }  \/\/ \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f compareValues(a, b) {   if (a === b) {     return 0   }   return a &lt; b ? -1 : 1 }<\/code><\/pre>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/ \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0443\u0437\u043b\u043e\u0432 import Comparator from '..\/utils\/comparator' \/\/ \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 min-\u043a\u0443\u0447\u0438 import MinHeap from '.\/heap\/min-heap'  \/\/ \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c. \/\/ \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 min-\u043a\u0443\u0447\u0438 export default class PriorityQueue extends MinHeap {   constructor() {     \/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c min-\u043a\u0443\u0447\u0443     super()     \/\/ \u041a\u0430\u0440\u0442\u0430 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u0432     this.priorities = new Map()     \/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432     this.compare = new Comparator(this.comparePriorities.bind(this))   }    \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c.   \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442.   \/\/ \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 (\u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 `priority`),   \/\/ \u0442\u0435\u043c \"\u0432\u044b\u0448\u0435\" \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438   add(item, priority = 0) {     \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b     this.priorities.set(item, priority)     \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u0443\u0447\u0443     super.add(item)      return this   }    \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.   \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432   remove(item, compare) {     \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043a\u0443\u0447\u0438     super.remove(item, compare)     \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b     this.priorities.delete(item)      return this   }    \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442.   \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442   changePriority(item, priority) {     \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438     this.remove(item, new Comparator(this.compareValues))     \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441 \u043d\u043e\u0432\u044b\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c     this.add(item, priority)      return this   }    \/\/ \u0418\u0449\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.   \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432   findByValue(item) {     return this.find(item, new Comparator(this.compareValues))   }    \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430   hasValue(item) {     return this.findByValue(item).length &gt; 0   }    \/\/ \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b   comparePriorities(a, b) {     \/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439,     \/\/ \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0435\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b     return this.compareValues(this.priorities.get(a), this.priorities.get(b))   }    \/\/ \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f   compareValues(a, b) {     if (a === b) {       return 0     }     return a &lt; b ? -1 : 1   } }<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<p><strong>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong><\/p>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import PriorityQueue from '..\/priority-queue'  describe('PriorityQueue', () =&gt; {   it('\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c', () =&gt; {     const priorityQueue = new PriorityQueue()      expect(priorityQueue).toBeDefined()   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c', () =&gt; {     const priorityQueue = new PriorityQueue()      priorityQueue.add(10, 1)     expect(priorityQueue.peek()).toBe(10)      priorityQueue.add(5, 2)     expect(priorityQueue.peek()).toBe(10)      priorityQueue.add(100, 0)     expect(priorityQueue.peek()).toBe(100)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b', () =&gt; {     const priorityQueue = new PriorityQueue()      const user1 = { name: 'Mike' }     const user2 = { name: 'Bill' }     const user3 = { name: 'Jane' }      priorityQueue.add(user1, 1)     expect(priorityQueue.peek()).toBe(user1)      priorityQueue.add(user2, 2)     expect(priorityQueue.peek()).toBe(user1)      priorityQueue.add(user3, 0)     expect(priorityQueue.peek()).toBe(user3)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0443', () =&gt; {     const priorityQueue = new PriorityQueue()      priorityQueue.add(10, 1)     priorityQueue.add(5, 2)     priorityQueue.add(100, 0)     priorityQueue.add(200, 0)      expect(priorityQueue.poll()).toBe(100)     expect(priorityQueue.poll()).toBe(200)     expect(priorityQueue.poll()).toBe(10)     expect(priorityQueue.poll()).toBe(5)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b \u0433\u043e\u043b\u043e\u0432\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432', () =&gt; {     const priorityQueue = new PriorityQueue()      priorityQueue.add(10, 1)     priorityQueue.add(5, 2)     priorityQueue.add(100, 0)     priorityQueue.add(200, 0)      expect(priorityQueue.peek()).toBe(100)      priorityQueue.changePriority(100, 10)     priorityQueue.changePriority(10, 20)      expect(priorityQueue.poll()).toBe(200)     expect(priorityQueue.poll()).toBe(5)     expect(priorityQueue.poll()).toBe(100)     expect(priorityQueue.poll()).toBe(10)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0443\u0437\u043b\u043e\u0432', () =&gt; {     const priorityQueue = new PriorityQueue()      priorityQueue.add(10, 1)     priorityQueue.add(5, 2)     priorityQueue.add(100, 0)     priorityQueue.add(200, 0)      expect(priorityQueue.peek()).toBe(100)      priorityQueue.changePriority(200, 10)     priorityQueue.changePriority(10, 20)      expect(priorityQueue.poll()).toBe(100)     expect(priorityQueue.poll()).toBe(5)     expect(priorityQueue.poll()).toBe(200)     expect(priorityQueue.poll()).toBe(10)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442', () =&gt; {     const priorityQueue = new PriorityQueue()      priorityQueue.add(10, 1)     priorityQueue.add(5, 2)     priorityQueue.add(100, 0)     priorityQueue.add(200, 0)      priorityQueue.changePriority(200, 10)     priorityQueue.changePriority(10, 20)      priorityQueue.add(15, 15)      expect(priorityQueue.poll()).toBe(100)     expect(priorityQueue.poll()).toBe(5)     expect(priorityQueue.poll()).toBe(200)     expect(priorityQueue.poll()).toBe(15)     expect(priorityQueue.poll()).toBe(10)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432', () =&gt; {     const priorityQueue = new PriorityQueue()      priorityQueue.add(10, 1)     priorityQueue.add(5, 2)     priorityQueue.add(100, 0)     priorityQueue.add(200, 0)     priorityQueue.add(15, 15)      expect(priorityQueue.hasValue(70)).toBe(false)     expect(priorityQueue.hasValue(15)).toBe(true)   }) })<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u044b:<\/p>\n<p> <\/p>\n<pre><code class=\"bash\">npm run test .\/data-structures\/__tests__\/priority-queue<\/code><\/pre>\n<p> <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/op\/se\/xs\/opsexsj0spxpzlivn5dcba5ydp8.png\" data-src=\"https:\/\/habrastorage.org\/webt\/op\/se\/xs\/opsexsj0spxpzlivn5dcba5ydp8.png\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<h2 id=\"8-prefiksnoe-derevo\">8. \u041f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e<\/h2>\n<p> <\/p>\n<ul>\n<li><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9F%D1%80%D0%B5%D1%84%D0%B8%D0%BA%D1%81%D0%BD%D0%BE%D0%B5_%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE\">\u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u044f<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=fqfkeJ09G0c\">YouTube<\/a><\/li>\n<\/ul>\n<p> <\/p>\n<p>\u041f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e (\u0438\u043b\u0438 \u0431\u043e\u0440, \u0438\u043b\u0438 \u043b\u0443\u0447, \u0438\u043b\u0438 \u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e) (trie) \u2014 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 (\u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e), \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0438. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e, \u043a\u0430\u0436\u0434\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u043c \u0442\u0430\u043a, \u0447\u0442\u043e \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0432\u0441\u0435 \u0440\u0435\u0431\u0440\u0430, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0435 \u044d\u0442\u043e\u0442 \u0443\u0437\u0435\u043b \u0441 \u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c\u0438, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0437\u043b\u044b \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443-\u043a\u043b\u044e\u0447 \u0442\u043e\u0433\u0434\u0430 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 \u043f\u0443\u0442\u0438 \u0438\u0437 \u043a\u043e\u0440\u043d\u044f \u0434\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e (\u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438) \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430.<\/p>\n<p> <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u043f\u043e\u0438\u0441\u043a\u0430 (binary search tree), \u043a\u043b\u044e\u0447, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0443\u0437\u0435\u043b \u0434\u0435\u0440\u0435\u0432\u0430, \u043d\u0435 \u044f\u0432\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0443\u0437\u043b\u0435, \u0430 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435. \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043b\u044e\u0447 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043f\u043e\u043c\u0435\u0447\u0430\u044e\u0449\u0438\u0445 \u0440\u0435\u0431\u0440\u0430 \u043d\u0430 \u043f\u0443\u0442\u0438 \u043e\u0442 \u043a\u043e\u0440\u043d\u044f \u0434\u043e \u0443\u0437\u043b\u0430. \u041a\u043b\u044e\u0447 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u2014 \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430. \u0427\u0430\u0441\u0442\u043e \u0432 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0437\u043b\u0430\u0445 \u0445\u0440\u0430\u043d\u044f\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u0441 \u043a\u043b\u044e\u0447\u043e\u043c, \u0438 \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0441\u0442\u044c\u044f, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0443\u0437\u043b\u044b.<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/tk\/yc\/-w\/tkyc-wz6y5jcnie6zzpjpsk3_oi.png\" data-src=\"https:\/\/habrastorage.org\/webt\/tk\/yc\/-w\/tkyc-wz6y5jcnie6zzpjpsk3_oi.png\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p><strong>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c<\/strong><\/p>\n<p> <\/p>\n<p>\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 O(n) (\u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b).<\/p>\n<p> <\/p>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong><\/p>\n<p> <\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 (\u0441\u043c. \u0440\u0430\u0437\u0434\u0435\u043b 5).<\/p>\n<p> <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0443\u0437\u043b\u0430 \u0434\u0435\u0440\u0435\u0432\u0430:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ data-structures\/trie\/node.js \/\/ \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b import HashTable from '..\/hash-table'  \/\/ \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 (\u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0438\u0439) \u0441\u0438\u043c\u0432\u043e\u043b export const HEAD_CHARACTER = '*'  \/\/ \u0423\u0437\u0435\u043b \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 export default class Node {   constructor(char, isCompleteWord = false) {     \/\/ \u0421\u0438\u043c\u0432\u043e\u043b     this.char = char     \/\/ \u0418\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430     this.isCompleteWord = isCompleteWord     \/\/ \u0425\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432     this.children = new HashTable()   } }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0443\u0437\u043b\u043e\u0432-\u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u043e addChild(char, isCompleteWord = false) {   \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0443\u0437\u0435\u043b \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438   if (!this.hasChild(char)) {     this.children.set(char, new Node(char, isCompleteWord))   }    \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0443\u0437\u0435\u043b   const node = this.getChild(char)    \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0444\u043b\u0430\u0433 `isCompleteWord` \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438,   \/\/ \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0441\u043b\u043e\u0432\u0430 \"car\" \u043f\u043e\u0441\u043b\u0435 \u0441\u043b\u043e\u0432\u0430 \"carpet\",   \/\/ \u0431\u0443\u043a\u0432\u0443 \"r\" \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u043a\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0443\u044e   node.isCompleteWord = node.isCompleteWord || isCompleteWord    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0443\u0437\u0435\u043b   return node }  \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u0430 removeChild(char) {   \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0443\u0437\u0435\u043b   const node = this.getChild(char)    \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0443\u0437\u0435\u043b, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438:   \/\/ - \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432   \/\/ - node.isCompleteWord === false   if (node &amp;&amp; !node.isCompleteWord &amp;&amp; !node.hasChildren()) {     this.children.remove(char)   }    return this }<\/code><\/pre>\n<p> <\/p>\n<p>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c\u0438:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u0430 getChild(char) {   return this.children.get(char) }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u0442\u043e\u043c\u043a\u0430 hasChild(char) {   return this.children.has(char) }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 hasChildren() {   return this.children.getKeys().length &gt; 0 }  \/\/ \u0410\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 (\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432) suggestChildren() {   return [...this.children.getKeys()] }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \/\/ \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 toString() {   let childrenAsString = this.suggestChildren().toString()   childrenAsString = childrenAsString ? `:${childrenAsString}` : ''   const isCompleteString = this.isCompleteWord ? HEAD_CHARACTER : ''    return `${this.char}${isCompleteString}${childrenAsString}` }<\/code><\/pre>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0443\u0437\u043b\u0430 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/ \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b import HashTable from '..\/hash-table'  \/\/ \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 (\u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0438\u0439) \u0441\u0438\u043c\u0432\u043e\u043b export const HEAD_CHARACTER = '*'  \/\/ \u0423\u0437\u0435\u043b \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 export default class Node {   constructor(char, isCompleteWord = false) {     \/\/ \u0421\u0438\u043c\u0432\u043e\u043b     this.char = char     \/\/ \u0418\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430     this.isCompleteWord = isCompleteWord     \/\/ \u0425\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432     this.children = new HashTable()   }    \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u043e   addChild(char, isCompleteWord = false) {     \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0443\u0437\u0435\u043b \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438     if (!this.hasChild(char)) {       this.children.set(char, new Node(char, isCompleteWord))     }      \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0443\u0437\u0435\u043b     const node = this.getChild(char)      \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0444\u043b\u0430\u0433 `isCompleteWord` \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438,     \/\/ \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0441\u043b\u043e\u0432\u0430 \"car\" \u043f\u043e\u0441\u043b\u0435 \u0441\u043b\u043e\u0432\u0430 \"carpet\",     \/\/ \u0431\u0443\u043a\u0432\u0443 \"r\" \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u043a\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0443\u044e     node.isCompleteWord = node.isCompleteWord || isCompleteWord      \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0443\u0437\u0435\u043b     return node   }    \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u0430   removeChild(char) {     \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0443\u0437\u0435\u043b     const node = this.getChild(char)      \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0443\u0437\u0435\u043b, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438:     \/\/ - \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432     \/\/ - node.isCompleteWord === false     if (node &amp;&amp; !node.isCompleteWord &amp;&amp; !node.hasChildren()) {       this.children.remove(char)     }      return this   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u0430   getChild(char) {     return this.children.get(char)   }    \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u0442\u043e\u043c\u043a\u0430   hasChild(char) {     return this.children.has(char)   }    \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432   hasChildren() {     return this.children.getKeys().length &gt; 0   }    \/\/ \u0410\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 (\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432)   suggestChildren() {     return [...this.children.getKeys()]   }    \/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443   \/\/ \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430   toString() {     let childrenAsString = this.suggestChildren().toString()     childrenAsString = childrenAsString ? `:${childrenAsString}` : ''     const isCompleteString = this.isCompleteWord ? HEAD_CHARACTER : ''      return `${this.char}${isCompleteString}${childrenAsString}`   } }<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e! \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0430\u043c\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ data-structures\/trie\/index.js import TrieNode, { HEAD_CHARACTER } from '.\/node'  \/\/ \u041f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e export default class Trie {   constructor() {     \/\/ \u0413\u043e\u043b\u043e\u0432\u043d\u043e\u0439 (\u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439) \u0443\u0437\u0435\u043b     this.head = new TrieNode(HEAD_CHARACTER)   } }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430 (\u043a\u043b\u044e\u0447\u0430) \u0432\/\u0438\u0437 \u0434\u0435\u0440\u0435\u0432\u0430:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u043e (\u043a\u043b\u044e\u0447) \u0432 \u0434\u0435\u0440\u0435\u0432\u043e addWord(word) {   \/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 (\u0441\u043b\u043e\u0432\u043e) \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432   \/\/ (\u0432\u043e\u043f\u0440\u043e\u0441 \u043d\u0430 \u0437\u0430\u0441\u044b\u043f\u043a\u0443: \u043f\u043e\u0447\u0435\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c `split('')`?   \/\/ \u041f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0430: \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \"Hello, ?!\")   const chars = [...word]    \/\/ \u0422\u0435\u043a\u0443\u0449\u0438\u0439 \u0443\u0437\u0435\u043b (\u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0433\u043e\u043b\u043e\u0432\u043d\u043e\u0433\u043e)   let node = this.head    \/\/ \u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0432 \u0434\u0435\u0440\u0435\u0432\u043e   for (let i = 0; i &lt; chars.length; i++) {     \/\/ \u0418\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430     const isComplete = i === chars.length - 1     \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u0430     node = node.addChild(chars[i], isComplete)   }    return this }  \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u043e (\u043a\u043b\u044e\u0447) \u0438\u0437 \u0434\u0435\u0440\u0435\u0432\u0430 removeWord(word) {   \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e (\"\u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443\")   const depthFirstRemove = (node, i = 0) =&gt; {     \/\/ \u0415\u0441\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0441\u043b\u043e\u0432\u0430,     \/\/ \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u043c     if (i &gt;= word.length) return      \/\/ \u0421\u0438\u043c\u0432\u043e\u043b     const char = word[i]     \/\/ \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0443\u0437\u0435\u043b     const nextNode = node.getChild(char)      \/\/ \u0415\u0441\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0443\u0437\u0435\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442,     \/\/ \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u043c     if (!nextNode) return      \/\/ \u041f\u043e\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u0441\u044f \u0433\u043b\u0443\u0431\u0436\u0435     depthFirstRemove(nextNode, i + 1)      \/\/ \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u043b\u043e\u0432\u043e,     \/\/ \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0444\u043b\u0430\u0433 `isCompleteWord`     \/\/ \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430     if (i === word.length - 1) {       nextNode.isCompleteWord = false     }      \/\/ \u0423\u0437\u0435\u043b \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438:     \/\/ - \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432     \/\/ - nextNode.isCompleteWord === false     node.removeChild(char)   }    \/\/ \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0433\u043e\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430   depthFirstRemove(this.head)    return this }<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0430\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0410\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 (\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432) suggestNextCharacters(word) {   \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b   const lastChar = this.getLastCharNode(word)    \/\/ \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442   if (!lastChar) {     return null   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432   return lastChar.suggestChildren() }<\/code><\/pre>\n<p> <\/p>\n<p>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0441\u043b\u043e\u0432\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435 doesWordExist(word) {   \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b   const lastChar = this.getLastCharNode(word)    return Boolean(lastChar) &amp;&amp; lastChar.isCompleteWord }<\/code><\/pre>\n<p> <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b getLastCharNode(word) {   \/\/ \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u043e \u043d\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u044b   const chars = [...word]   \/\/ \u0422\u0435\u043a\u0443\u0449\u0438\u0439 \u0443\u0437\u0435\u043b (\u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0433\u043e\u043b\u043e\u0432\u043d\u043e\u0433\u043e)   let node = this.head    \/\/ \u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b   for (let i = 0; i &lt; chars.length; i++) {     \/\/ \u0415\u0441\u043b\u0438 \u0441\u0438\u043c\u0432\u043e\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442     if (!node.hasChild(chars[i])) {       return null     }      \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u0430     node = node.getChild(chars[i])   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0443\u0437\u0435\u043b   return node }<\/code><\/pre>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import TrieNode, { HEAD_CHARACTER } from '.\/node'  \/\/ \u041f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e export default class Trie {   constructor() {     \/\/ \u0413\u043e\u043b\u043e\u0432\u043d\u043e\u0439 (\u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439) \u0443\u0437\u0435\u043b     this.head = new TrieNode(HEAD_CHARACTER)   }    \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u043e (\u043a\u043b\u044e\u0447) \u0432 \u0434\u0435\u0440\u0435\u0432\u043e   addWord(word) {     \/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 (\u0441\u043b\u043e\u0432\u043e) \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432     \/\/ (\u0432\u043e\u043f\u0440\u043e\u0441 \u043d\u0430 \u0437\u0430\u0441\u044b\u043f\u043a\u0443: \u043f\u043e\u0447\u0435\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c `split()`?     \/\/ \u041f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0430: \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \"Hello, ?!\")     const chars = [...word]      \/\/ \u0422\u0435\u043a\u0443\u0449\u0438\u0439 \u0443\u0437\u0435\u043b (\u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0433\u043e\u043b\u043e\u0432\u043d\u043e\u0433\u043e)     let node = this.head      \/\/ \u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0432 \u0434\u0435\u0440\u0435\u0432\u043e     for (let i = 0; i &lt; chars.length; i++) {       \/\/ \u0418\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e (\u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0435\u0433\u043e) \u0441\u0438\u043c\u0432\u043e\u043b\u0430       const isComplete = i === chars.length - 1       \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u0430       node = node.addChild(chars[i], isComplete)     }      return this   }    \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u043e (\u043a\u043b\u044e\u0447) \u0438\u0437 \u0434\u0435\u0440\u0435\u0432\u0430   removeWord(word) {     \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e (\"\u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443\")     const depthFirstRemove = (node, i = 0) =&gt; {       \/\/ \u0415\u0441\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0441\u043b\u043e\u0432\u0430,       \/\/ \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u043c       if (i &gt;= word.length) return        \/\/ \u0421\u0438\u043c\u0432\u043e\u043b       const char = word[i]       \/\/ \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0443\u0437\u0435\u043b       const nextNode = node.getChild(char)        \/\/ \u0415\u0441\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0443\u0437\u0435\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442,       \/\/ \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u043c       if (!nextNode) return        \/\/ \u041f\u043e\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u0441\u044f \u0433\u043b\u0443\u0431\u0436\u0435       depthFirstRemove(nextNode, i + 1)        \/\/ \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u043b\u043e\u0432\u043e,       \/\/ \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0444\u043b\u0430\u0433 `isCompleteWord`       \/\/ \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430       if (i === word.length - 1) {         nextNode.isCompleteWord = false       }        \/\/ \u0423\u0437\u0435\u043b \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438:       \/\/ - \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432       \/\/ - nextNode.isCompleteWord === false       node.removeChild(char)     }      \/\/ \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0433\u043e\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430     depthFirstRemove(this.head)      return this   }    \/\/ \u0410\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 (\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432)   suggestNextCharacters(word) {     \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b     const lastChar = this.getLastCharNode(word)      \/\/ \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442     if (!lastChar) {       return null     }      \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432     return lastChar.suggestChildren()   }    \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435   doesWordExist(word) {     \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b     const lastChar = this.getLastCharNode(word)      return Boolean(lastChar) &amp;&amp; lastChar.isCompleteWord   }    \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b   getLastCharNode(word) {     \/\/ \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u043e \u043d\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u044b     const chars = [...word]     \/\/ \u0422\u0435\u043a\u0443\u0449\u0438\u0439 \u0443\u0437\u0435\u043b (\u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0433\u043e\u043b\u043e\u0432\u043d\u043e\u0433\u043e)     let node = this.head      \/\/ \u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b     for (let i = 0; i &lt; chars.length; i++) {       \/\/ \u0415\u0441\u043b\u0438 \u0441\u0438\u043c\u0432\u043e\u043b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442       if (!node.hasChild(chars[i])) {         return null       }        \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u0430       node = node.getChild(chars[i])     }      \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0443\u0437\u0435\u043b     return node   } }<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<p><strong>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong><\/p>\n<p> <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u0448\u0435 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0437\u043b\u0430:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/ data-structures\/trie\/__tests__\/node.test.js import TrieNode from '..\/node'  describe('TrieNode', () =&gt; {   it('\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0443\u0437\u0435\u043b \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430', () =&gt; {     const trieNode = new TrieNode('c', true)      expect(trieNode.char).toBe('c')     expect(trieNode.isCompleteWord).toBe(true)     expect(trieNode.toString()).toBe('c*')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432', () =&gt; {     const trieNode = new TrieNode('c')      trieNode.addChild('a', true)     trieNode.addChild('o')      expect(trieNode.toString()).toBe('c:a,o')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432', () =&gt; {     const trieNode = new TrieNode('c')      trieNode.addChild('a')     trieNode.addChild('o')      expect(trieNode.getChild('a').toString()).toBe('a')     expect(trieNode.getChild('a').char).toBe('a')     expect(trieNode.getChild('o').toString()).toBe('o')     expect(trieNode.getChild('b')).toBeNull()   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432', () =&gt; {     const trieNode = new TrieNode('c')      expect(trieNode.hasChildren()).toBe(false)      trieNode.addChild('a')      expect(trieNode.hasChildren()).toBe(true)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430', () =&gt; {     const trieNode = new TrieNode('c')      trieNode.addChild('a')     trieNode.addChild('o')      expect(trieNode.hasChild('a')).toBe(true)     expect(trieNode.hasChild('o')).toBe(true)     expect(trieNode.hasChild('b')).toBe(false)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b', () =&gt; {     const trieNode = new TrieNode('c')      trieNode.addChild('a')     trieNode.addChild('o')      expect(trieNode.suggestChildren()).toEqual(['a', 'o'])   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043c\u043a\u0430, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0435\u0433\u043e \u041d\u0415\u0422 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432', () =&gt; {     const trieNode = new TrieNode('c')     trieNode.addChild('a')     expect(trieNode.hasChild('a')).toBe(true)      trieNode.removeChild('a')     expect(trieNode.hasChild('a')).toBe(false)   })    it('\u041d\u0415 \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u043f\u043e\u0442\u043e\u043c\u043a\u0438', () =&gt; {     const trieNode = new TrieNode('c')     trieNode.addChild('a')     const childNode = trieNode.getChild('a')     childNode.addChild('r')      trieNode.removeChild('a')     expect(trieNode.hasChild('a')).toEqual(true)   })    it('\u041d\u0415 \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0438\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438', () =&gt; {     const trieNode = new TrieNode('c')     const IS_COMPLETE_WORD = true     trieNode.addChild('a', IS_COMPLETE_WORD)      trieNode.removeChild('a')     expect(trieNode.hasChild('a')).toEqual(true)   }) })<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u0430:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/ data-structures\/trie\/__tests__\/trie.test.js import Trie from '..'  describe('Trie', () =&gt; {   it('\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e', () =&gt; {     const trie = new Trie()      expect(trie).toBeDefined()     expect(trie.head.toString()).toBe('*')   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043b\u043e\u0432\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u043e', () =&gt; {     const trie = new Trie()      trie.addWord('cat')      expect(trie.head.toString()).toBe('*:c')     expect(trie.head.getChild('c').toString()).toBe('c:a')      trie.addWord('car')     expect(trie.head.toString()).toBe('*:c')     expect(trie.head.getChild('c').toString()).toBe('c:a')     expect(trie.head.getChild('c').getChild('a').toString()).toBe('a:t,r')     expect(trie.head.getChild('c').getChild('a').getChild('t').toString()).toBe(       't*',     )   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0441\u043b\u043e\u0432\u0430 \u0438\u0437 \u0434\u0435\u0440\u0435\u0432\u0430', () =&gt; {     const trie = new Trie()      trie.addWord('carpet')     trie.addWord('car')     trie.addWord('cat')     trie.addWord('cart')     expect(trie.doesWordExist('carpet')).toBe(true)     expect(trie.doesWordExist('car')).toBe(true)     expect(trie.doesWordExist('cart')).toBe(true)     expect(trie.doesWordExist('cat')).toBe(true)      \/\/ \u041f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0441\u043b\u043e\u0432\u043e     trie.removeWord('carpool')     expect(trie.doesWordExist('carpet')).toBe(true)     expect(trie.doesWordExist('car')).toBe(true)     expect(trie.doesWordExist('cart')).toBe(true)     expect(trie.doesWordExist('cat')).toBe(true)      trie.removeWord('carpet')     expect(trie.doesWordExist('carpet')).toEqual(false)     expect(trie.doesWordExist('car')).toEqual(true)     expect(trie.doesWordExist('cart')).toBe(true)     expect(trie.doesWordExist('cat')).toBe(true)      trie.removeWord('cat')     expect(trie.doesWordExist('car')).toEqual(true)     expect(trie.doesWordExist('cart')).toBe(true)     expect(trie.doesWordExist('cat')).toBe(false)      trie.removeWord('car')     expect(trie.doesWordExist('car')).toEqual(false)     expect(trie.doesWordExist('cart')).toBe(true)      trie.removeWord('cart')     expect(trie.doesWordExist('car')).toEqual(false)     expect(trie.doesWordExist('cart')).toBe(false)   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b', () =&gt; {     const trie = new Trie()      trie.addWord('cat')     trie.addWord('cats')     trie.addWord('car')     trie.addWord('caption')      expect(trie.suggestNextCharacters('ca')).toEqual(['t', 'r', 'p'])     expect(trie.suggestNextCharacters('cat')).toEqual(['s'])     expect(trie.suggestNextCharacters('cab')).toBeNull()   })    it('\u0434\u043e\u043b\u0436\u0435\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0441\u043b\u043e\u0432', () =&gt; {     const trie = new Trie()      trie.addWord('cat')     trie.addWord('cats')     trie.addWord('carpet')     trie.addWord('car')     trie.addWord('caption')      expect(trie.doesWordExist('cat')).toBe(true)     expect(trie.doesWordExist('cats')).toBe(true)     expect(trie.doesWordExist('carpet')).toBe(true)     expect(trie.doesWordExist('car')).toBe(true)     expect(trie.doesWordExist('cap')).toBe(false)     expect(trie.doesWordExist('call')).toBe(false)   }) })<\/code><\/pre>\n<\/div><\/div>\n<p> <\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u044b:<\/p>\n<p> <\/p>\n<pre><code class=\"bash\">npm run test .\/data-structures\/trie<\/code><\/pre>\n<p> <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ts\/gq\/ga\/tsgqgakqf8qoyy5vgj7qbluxk3m.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ts\/gq\/ga\/tsgqgakqf8qoyy5vgj7qbluxk3m.png\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p>\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044d\u0442\u043e \u0432\u0441\u0435, \u0434\u0440\u0443\u0437\u044c\u044f. \u0423\u0432\u0438\u0434\u0438\u043c\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<p> <\/p>\n<hr\/>\n<p> <\/p>\n<blockquote><p><a href=\"https:\/\/t.me\/timewebru\"><b>\u041d\u043e\u0432\u043e\u0441\u0442\u0438, \u043e\u0431\u0437\u043e\u0440\u044b \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0441\u044b \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b Timeweb.Cloud \u2014 \u0432 \u043d\u0430\u0448\u0435\u043c Telegram-\u043a\u0430\u043d\u0430\u043b\u0435<\/b><\/a> <b>\u21a9<\/b><\/p><\/blockquote>\n<p><a href=\"https:\/\/timeweb.cloud\/?i=106909\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/u9\/vg\/io\/u9vgio3hxj12h5u7j3un0wx_zpk.png\" data-src=\"https:\/\/habrastorage.org\/webt\/u9\/vg\/io\/u9vgio3hxj12h5u7j3un0wx_zpk.png\"\/><\/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\/828068\/\"> https:\/\/habr.com\/ru\/articles\/828068\/<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg\" data-blurred=\"true\"\/> <\/p>\n<p> \u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f!<\/p>\n<p> <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 <a href=\"https:\/\/github.com\/trekhleb\/javascript-algorithms\">\u044d\u0442\u043e\u043c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>. \u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0435\u0440\u0438\u0438.<\/p>\n<p> <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/826424\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a><\/li>\n<\/ul>\n<p> <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0442\u0430\u043a\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u0430\u043a \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u043a\u0443\u0447\u0430, \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u0438 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e.<\/p>\n<p> <\/p>\n<p>\u041a\u043e\u0434, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 \u044d\u0442\u043e\u0439 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u0441\u0435\u0440\u0438\u0438, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/github.com\/harryheman\/algorithms-data-structures\">\u044d\u0442\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>.<\/p>\n<p> <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e? \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\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-427344","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/427344","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=427344"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/427344\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=427344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=427344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=427344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}