{"id":443158,"date":"2024-12-26T05:45:13","date_gmt":"2024-12-26T05:45:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=443158"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=443158","title":{"rendered":"<span>\u041c\u0438\u0444 \u043e RAM<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a1d\/03e\/f27\/a1d03ef272f5d96f3c4e08ab1d1a16dc.png\" width=\"780\" height=\"488\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a1d\/03e\/f27\/a1d03ef272f5d96f3c4e08ab1d1a16dc.png\"\/><\/figure>\n<p>\u041c\u0438\u0444 \u043e RAM \u2014 \u044d\u0442\u043e \u0432\u0435\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0430\u043c\u044f\u0442\u044c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c. \u041a\u044d\u0448 \u043b\u044e\u0434\u0438 \u0441\u0447\u0438\u0442\u0430\u044e\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0434\u043b\u044f \u043c\u0430\u043b\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0443\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 L2, \u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0435; \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u0442\u0443\u0442 \u0443\u0436 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u0434\u0435\u043b\u0430\u0435\u0448\u044c.<\/p>\n<p>\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0447\u0442\u043e \u0441\u0430\u043c\u044b\u043c \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 (\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434\u0430 Python; \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u044f \u043f\u0438\u0448\u0443 \u044d\u0442\u043e \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043b\u044e\u0431\u0438\u043c\u043e\u043c \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u043c \u044f\u0437\u044b\u043a\u0435):<\/p>\n<pre><code class=\"python\">groups = [[] for _ in range(n_groups)] for element in elements:     groups[element.group].append(element)<\/code><\/pre>\n<p>\u041e\u043d \u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043b\u0438\u043d\u0435\u0435\u043d (\u0442\u043e \u0435\u0441\u0442\u044c \u0430\u0441\u0438\u043c\u043f\u0442\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u0435\u043d), \u0438 \u043c\u044b \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c, \u0442\u0430\u043a \u0447\u0442\u043e \u043a\u044d\u0448 \u0437\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043d\u0438 \u0432 \u0447\u0451\u043c \u0431\u044b \u043d\u0435 \u043f\u043e\u043c\u043e\u0433.<\/p>\n<p>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0440\u0443\u043f\u043f \u0432\u044b\u0441\u043e\u043a\u043e, \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043d\u0435 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 <em>\u0430\u0441\u0438\u043c\u043f\u0442\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435<\/em> \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043e\u043d\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0434\u0438\u0441\u043a\u0435, \u043d\u043e, \u043a\u0430\u043a \u043d\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u043e, \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0434\u0430\u0436\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 RAM.<\/p>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0447\u0442\u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0430\u0445 \u043a\u044d\u0448\u0430 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u043c\u0430\u0445\u043e\u0432 \u2014 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u043e\u043b\u0435\u0435 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u043c\u0438. \u0415\u0441\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0431\u044b\u043b\u0438 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u044b \u043f\u043e <code>group<\/code>, \u0442\u043e \u044d\u0442\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u0442, \u0442\u043e \u0432\u044b \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0434\u043e \u0446\u0438\u043a\u043b\u0430 <code>for<\/code>:<\/p>\n<pre><code class=\"python\">elements.sort(key = lambda element: element.group)<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0442\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043d\u043e \u0437\u0430\u0442\u043e \u0432\u044b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0432\u044b \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0435\u0441\u044c \u043e\u0442 \u043f\u0440\u043e\u043c\u0430\u0445\u043e\u0432 \u043a\u044d\u0448\u0430 \u0432 \u0446\u0438\u043a\u043b\u0435 <code>for<\/code>. \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u043a \u0432\u0435\u043b\u0438\u043a\u0438, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u044d\u0448, \u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u044d\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u0432\u044b\u0438\u0433\u0440\u044b\u0448. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u043e\u043d\u0443\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0435\u0439 <code>groupby<\/code>:<\/p>\n<pre><code class=\"python\">elements.sort(key = lambda element: element.group) groups = [     group_elements     for _, group_elements     in itertools.groupby(elements, key = lambda element: element.group) ]<\/code><\/pre>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043a\u044d\u0448, \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u0437\u0434\u0435\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u043f\u043e\u0440\u0430\u0437\u0440\u044f\u0434\u043d\u0430\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 (radix sort). \u0421\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u043c\u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u0434\u043e\u0448\u043b\u0430 \u0432 Rust <a href=\"https:\/\/docs.rs\/radsort\/latest\/radsort\/\" rel=\"noopener noreferrer nofollow\">radsort<\/a>.<\/p>\n<h3>\u0423\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043e\u0431\u044a\u0451\u043c\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0443\u0436\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043d\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0451 \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u0440\u044e\u043a\u043e\u0432 \u0434\u043b\u044f \u0435\u0433\u043e \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f.<\/p>\n<h4>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/h4>\n<p>API \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430 \u043c\u0435\u0441\u0442\u0435, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u044f\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435. \u041d\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f, \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 32-\u0431\u0438\u0442\u043d\u044b\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 def radix_sort(elements, bits = 32):     # \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 -- \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0447\u0435\u0433\u043e \u0438\u043b\u0438 \u0432\u0441\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b     if len(elements) &lt;= 1 or bits &lt;= 0:         yield from elements         return      # \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u043f\u043e \u0441\u0442\u0430\u0440\u0448\u0435\u043c\u0443 \u0431\u0430\u0439\u0442\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0435\u0441\u043b\u0438 \u0435\u0449\u0451 \u0435\u0433\u043e \u043d\u0435 \u0432\u0438\u0434\u0435\u043b\u0438     buckets = [[] for _ in range(256)]     for element in elements:         buckets[(element.index &gt;&gt; max(0, bits - 8)) &amp; 0xff].append(element)      # \u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0431\u0430\u043a\u0435\u0442\u044b     for bucket in buckets:         yield from radix_sort(bucket, bits - 8)<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u044d\u0442\u0430\u043f\u0430 <code>groupby<\/code>\u00a0\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c yield \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0433\u0440\u0443\u043f\u043f:<\/p>\n<pre><code class=\"python\"># \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 -- \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0447\u0435\u0433\u043e \u0438\u043b\u0438 \u0432\u0441\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b if bits &lt;= 0:     if elements:         # \u0413\u0440\u0443\u043f\u043f\u0430!         yield elements     return<\/code><\/pre>\n<h4>\u041f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f<\/h4>\n<p>\u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 <code>bucket<\/code>\u00a0\u043f\u0440\u0438 <code>append<\/code>. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e <code>memcpy<\/code>\u00a0\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0430\u0449\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e, \u0438 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e \u0434\u043b\u044f \u043a\u044d\u0448\u0430. \u0427\u0430\u0441\u0442\u043e \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442 \u0437\u0430\u0440\u0430\u043d\u0435\u0435:<\/p>\n<pre><code class=\"python\">def get_bucket(element):     return (element.index &gt;&gt; max(0, bits - 8)) &amp; 0xff  sizes = Counter(map(get_bucket, elements))  # \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, Python \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u0441\u043f\u0438\u0441\u043a\u043e\u0432, \u043d\u043e \u043f\u0440\u0438\u0442\u0432\u043e\u0440\u0438\u043c\u0441\u044f, \u0447\u0442\u043e `reserve` \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442. # \u0412 C++ \u044d\u0442\u043e `std::vector::reserve`. \u0412 Rust \u044d\u0442\u043e `Vec::with_capacity`. buckets = [reserve(sizes[i]) for i in range(256)] for element in elements:     buckets[get_bucket(element)].append(element)<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u0432\u0443\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439, \u0430 \u043d\u0430\u043c \u0431\u044b \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f \u0437\u0430 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0445\u043e\u0434. \u0415\u0441\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u043b\u0443\u0447\u0430\u0435\u043d, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0438\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u0441\u0442\u0440\u0435\u043b\u043e\u043c \u0434\u0432\u0443\u0445 \u0437\u0430\u0439\u0446\u0435\u0432:\u00a0<em>\u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c <\/em>\u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u0430\u043a\u0435\u0442\u0430 \u043a\u0430\u043a <code>len(elements) \/ 256<\/code>\u00a0\u0438 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043f\u043e\u0434 \u043d\u0438\u0445. \u0415\u0441\u043b\u0438 \u043d\u0430\u0448\u0430 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u0436\u0435\u043d\u043d\u043e\u0439, \u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u043e\u0441\u0442\u0430\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435:<\/p>\n<pre><code class=\"python\">class Bucket:     reserved: list     leftovers: list      def __init__(self, capacity):         self.reserved = reserve(capacity) # \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434         self.leftovers = []      def append(self, element):         if len(self.reserved) &lt; self.reserved.capacity(): # \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434             self.reserved.append(element)         else:             self.leftovers.append(element)      def __len__(self):         return len(self.reserved) + len(self.leftovers)      def __iter__(self):         yield from self.reserved         yield from self.leftovers<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u0435\u0434\u0451\u0442 \u0441\u0435\u0431\u044f \u0447\u0435\u0441\u0442\u043d\u043e: \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043b\u0438\u0448\u044c \u043a\u0440\u043e\u0448\u0435\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 <code>leftovers<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0438\u0448\u043d\u0438\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0430\u043b\u044b, \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0432 <code>leftovers<\/code>\u00a0\u0431\u044b\u0441\u0442\u0440\u044b, \u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u043a\u0430 \u043d\u0430 \u0431\u0430\u043a\u0435\u0442\u044b (\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u0431\u0430\u043a\u0435\u0442\u0430\u043c) \u0443\u0434\u043e\u0431\u043d\u0430 \u0434\u043b\u044f \u043a\u044d\u0448\u0430.<\/p>\n<h4>\u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435<\/h4>\n<p>\u041f\u0440\u043e\u0441\u0442\u0430\u044f \u043c\u0438\u043a\u0440\u043e\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u043d\u0430 \u0431\u043b\u043e\u043a\u0438, \u0430 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e <code>malloc<\/code>\u00a0(\u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u044b). \u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e, \u0438 \u044d\u0442\u043e \u043c\u0430\u043b\u043e\u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u0438\u0445 \u0432\u043b\u0438\u044f\u043d\u0438\u044f.<\/p>\n<h4>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439<\/h4>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434 \u043a \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u043c\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 \u043f\u0440\u0438 \u043c\u0430\u043b\u043e\u043c \u043e\u0431\u044a\u0451\u043c\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043e\u043b\u0435\u0435 \u044f\u0432\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 O(n log n). \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>radix_sort<\/code>\u00a0\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043e\u0431\u044a\u0451\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\"># \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 -- \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0430\u043b, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c if len(elements) &lt;= CUTOFF or bits &lt;= 8:     counts = [0] * 256     for element in elements:         counts[element.index &amp; 0xff] += 1      groups = [[] for _ in range(256)]     for element in elements:         groups[get_bucket(element)].append(element)      for group in groups:         if group:             yield group     return<\/code><\/pre>\n<p>\u041e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>CUTOFF<\/code>\u00a0\u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u0430\u0448\u0438\u043d\u044b. \u041e\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u043a\u044d\u0448\u0430 \u0438 RAM, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u043a\u044d\u0448\u0430 \u0438 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 64-\u0431\u0438\u0442\u043d\u044b\u0445 integer \u044f \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0430 \u043c\u0430\u0448\u0438\u043d\u044b, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0431\u044b\u043b\u043e <code>50k<\/code>,\u00a0<code>200k<\/code> \u0438 <code>1M<\/code>. \u041d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u2014 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u0432 \u0441\u0440\u0435\u0434\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f; \u044d\u0442\u043e \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u041f\u041e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h3>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a<\/h3>\n<h4>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430<\/h4>\n<p>\u0412\u043e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a.<\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u2014 \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 64-\u0431\u0438\u0442\u043d\u044b\u0445 integer. \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u0445\u044d\u0448\u0443, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043d\u0430 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0438, \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0431\u0430\u043a\u0435\u0442\u043e\u0432, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u0441\u0443\u043c\u043c\u0443 \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u043e\u0432 \u0441\u0440\u0435\u0434\u0438 \u0431\u0430\u043a\u0435\u0442\u043e\u0432. (\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u0430\u043a\u0435\u0442\u044b \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0438\u0436\u0435 \u043f\u043e \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0443 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u0434\u0440\u0443\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043a \u043a\u044d\u0448\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c.)<\/p>\n<p>\u041c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0434\u0432\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e\u0440\u0430\u0437\u0440\u044f\u0434\u043d\u043e\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0448\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0442\u0441\u0435\u0447\u043a\u043e\u0439 (cutoff).<\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u0440\u0435\u0434\u043d\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0433\u0440\u0443\u043f\u043f\u044b \u0440\u0430\u0432\u0435\u043d 10.<\/p>\n<p>\u041a\u043e\u0434 \u0432\u044b\u043b\u043e\u0436\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/purplesyringa\/site\/blob\/master\/blog\/the-ram-myth\/benchmark.rs\" rel=\"noopener noreferrer nofollow\">GitHub<\/a>.<\/p>\n<h4>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/h4>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0440\u0430\u0441\u0442\u0451\u0442 \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0451\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439, \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u0430\u0448\u0438\u043d\u044b, \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0442 2,5 \u0434\u043e 9 \u0440\u0430\u0437.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b (<code>A<\/code>,\u00a0<code>Y<\/code>,\u00a0<code>M<\/code>\u00a0\u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u043d\u044b\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430):<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/614\/23d\/b22\/61423db225c4fb1b755995455e280cce.png\" width=\"852\" height=\"464\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/614\/23d\/b22\/61423db225c4fb1b755995455e280cce.png\"\/><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/553\/9ea\/98a\/5539ea98a19e776a421255974e577760.png\" width=\"852\" height=\"464\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/553\/9ea\/98a\/5539ea98a19e776a421255974e577760.png\"\/><\/figure>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u0442\u043e\u0438\u043b\u043e \u043b\u0438 \u043e\u043d\u043e \u0442\u043e\u0433\u043e? \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u0432\u0430\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430, \u0442\u043e \u043b\u044e\u0431\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044d\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0445\u044d\u0448\u0430 \u0431\u0435\u0437 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0439 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e \u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043b\u044e\u0431\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u0440\u0430\u0441\u043f\u043b\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0437\u0430 \u043d\u0435\u0451 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<p>\u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441 big data, \u0442\u043e \u043f\u0440\u043e \u044d\u0442\u043e\u0442 \u0442\u0440\u044e\u043a \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0438 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0432\u044b\u0432\u043e\u0434: \u0432\u0441\u0435 \u0437\u043d\u0430\u044e\u0442, \u0447\u0442\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0438\u0445 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e. \u042d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u043b\u043e\u0445\u043e\u0439. \u0423\u0440\u043e\u043a \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e \u0442\u0430\u043a\u0436\u0435 \u043a RAM \u0438 \u043a\u044d\u0448\u0443: \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0431\u043e\u043b\u044c\u0448\u0435, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, 32 \u041c\u0438\u0411 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0434 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u043d\u0430\u0434 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c \u043a \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u044c\u044e.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/868452\/\"> https:\/\/habr.com\/ru\/articles\/868452\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p>\u041c\u0438\u0444 \u043e RAM \u2014 \u044d\u0442\u043e \u0432\u0435\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0430\u043c\u044f\u0442\u044c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c. \u041a\u044d\u0448 \u043b\u044e\u0434\u0438 \u0441\u0447\u0438\u0442\u0430\u044e\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0434\u043b\u044f \u043c\u0430\u043b\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0443\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 L2, \u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0435; \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u0442\u0443\u0442 \u0443\u0436 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u0434\u0435\u043b\u0430\u0435\u0448\u044c.<\/p>\n<p>\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0447\u0442\u043e \u0441\u0430\u043c\u044b\u043c \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 (\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434\u0430 Python; \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u044f \u043f\u0438\u0448\u0443 \u044d\u0442\u043e \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043b\u044e\u0431\u0438\u043c\u043e\u043c \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u043c \u044f\u0437\u044b\u043a\u0435):<\/p>\n<pre><code class=\"python\">groups = [[] for _ in range(n_groups)] for element in elements:     groups[element.group].append(element)<\/code><\/pre>\n<p>\u041e\u043d \u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043b\u0438\u043d\u0435\u0435\u043d (\u0442\u043e \u0435\u0441\u0442\u044c \u0430\u0441\u0438\u043c\u043f\u0442\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u0435\u043d), \u0438 \u043c\u044b \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c, \u0442\u0430\u043a \u0447\u0442\u043e \u043a\u044d\u0448 \u0437\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043d\u0438 \u0432 \u0447\u0451\u043c \u0431\u044b \u043d\u0435 \u043f\u043e\u043c\u043e\u0433.<\/p>\n<p>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0440\u0443\u043f\u043f \u0432\u044b\u0441\u043e\u043a\u043e, \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043d\u0435 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 <em>\u0430\u0441\u0438\u043c\u043f\u0442\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435<\/em> \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043e\u043d\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0434\u0438\u0441\u043a\u0435, \u043d\u043e, \u043a\u0430\u043a \u043d\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u043e, \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0434\u0430\u0436\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 RAM.<\/p>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0447\u0442\u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0430\u0445 \u043a\u044d\u0448\u0430 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u043c\u0430\u0445\u043e\u0432 \u2014 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u043e\u043b\u0435\u0435 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u043c\u0438. \u0415\u0441\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0431\u044b\u043b\u0438 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u044b \u043f\u043e <code>group<\/code>, \u0442\u043e \u044d\u0442\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u0442, \u0442\u043e \u0432\u044b \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0434\u043e \u0446\u0438\u043a\u043b\u0430 <code>for<\/code>:<\/p>\n<pre><code class=\"python\">elements.sort(key = lambda element: element.group)<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0442\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043d\u043e \u0437\u0430\u0442\u043e \u0432\u044b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0432\u044b \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0435\u0441\u044c \u043e\u0442 \u043f\u0440\u043e\u043c\u0430\u0445\u043e\u0432 \u043a\u044d\u0448\u0430 \u0432 \u0446\u0438\u043a\u043b\u0435 <code>for<\/code>. \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u043a \u0432\u0435\u043b\u0438\u043a\u0438, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u044d\u0448, \u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u044d\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u0432\u044b\u0438\u0433\u0440\u044b\u0448. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u043e\u043d\u0443\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0435\u0439 <code>groupby<\/code>:<\/p>\n<pre><code class=\"python\">elements.sort(key = lambda element: element.group) groups = [     group_elements     for _, group_elements     in itertools.groupby(elements, key = lambda element: element.group) ]<\/code><\/pre>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043a\u044d\u0448, \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u0437\u0434\u0435\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u043f\u043e\u0440\u0430\u0437\u0440\u044f\u0434\u043d\u0430\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 (radix sort). \u0421\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u043c\u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u0434\u043e\u0448\u043b\u0430 \u0432 Rust <a href=\"https:\/\/docs.rs\/radsort\/latest\/radsort\/\" rel=\"noopener noreferrer nofollow\">radsort<\/a>.<\/p>\n<h3>\u0423\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043e\u0431\u044a\u0451\u043c\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0443\u0436\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043d\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0451 \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u0440\u044e\u043a\u043e\u0432 \u0434\u043b\u044f \u0435\u0433\u043e \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f.<\/p>\n<h4>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/h4>\n<p>API \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430 \u043c\u0435\u0441\u0442\u0435, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u044f\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435. \u041d\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f, \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 32-\u0431\u0438\u0442\u043d\u044b\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 def radix_sort(elements, bits = 32):     # \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 -- \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0447\u0435\u0433\u043e \u0438\u043b\u0438 \u0432\u0441\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b     if len(elements) &lt;= 1 or bits &lt;= 0:         yield from elements         return      # \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u043f\u043e \u0441\u0442\u0430\u0440\u0448\u0435\u043c\u0443 \u0431\u0430\u0439\u0442\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0435\u0441\u043b\u0438 \u0435\u0449\u0451 \u0435\u0433\u043e \u043d\u0435 \u0432\u0438\u0434\u0435\u043b\u0438     buckets = [[] for _ in range(256)]     for element in elements:         buckets[(element.index &gt;&gt; max(0, bits - 8)) &amp; 0xff].append(element)      # \u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0431\u0430\u043a\u0435\u0442\u044b     for bucket in buckets:         yield from radix_sort(bucket, bits - 8)<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u044d\u0442\u0430\u043f\u0430 <code>groupby<\/code>\u00a0\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c yield \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0433\u0440\u0443\u043f\u043f:<\/p>\n<pre><code class=\"python\"># \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 -- \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0447\u0435\u0433\u043e \u0438\u043b\u0438 \u0432\u0441\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b if bits &lt;= 0:     if elements:         # \u0413\u0440\u0443\u043f\u043f\u0430!         yield elements     return<\/code><\/pre>\n<h4>\u041f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f<\/h4>\n<p>\u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 <code>bucket<\/code>\u00a0\u043f\u0440\u0438 <code>append<\/code>. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e <code>memcpy<\/code>\u00a0\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0430\u0449\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e, \u0438 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e \u0434\u043b\u044f \u043a\u044d\u0448\u0430. \u0427\u0430\u0441\u0442\u043e \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442 \u0437\u0430\u0440\u0430\u043d\u0435\u0435:<\/p>\n<pre><code class=\"python\">def get_bucket(element):     return (element.index &gt;&gt; max(0, bits - 8)) &amp; 0xff  sizes = Counter(map(get_bucket, elements))  # \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, Python \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u0441\u043f\u0438\u0441\u043a\u043e\u0432, \u043d\u043e \u043f\u0440\u0438\u0442\u0432\u043e\u0440\u0438\u043c\u0441\u044f, \u0447\u0442\u043e `reserve` \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442. # \u0412 C++ \u044d\u0442\u043e `std::vector::reserve`. \u0412 Rust \u044d\u0442\u043e `Vec::with_capacity`. buckets = [reserve(sizes[i]) for i in range(256)] for element in elements:     buckets[get_bucket(element)].append(element)<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u0432\u0443\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439, \u0430 \u043d\u0430\u043c \u0431\u044b \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f \u0437\u0430 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0445\u043e\u0434. \u0415\u0441\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u043b\u0443\u0447\u0430\u0435\u043d, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0438\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u0441\u0442\u0440\u0435\u043b\u043e\u043c \u0434\u0432\u0443\u0445 \u0437\u0430\u0439\u0446\u0435\u0432:\u00a0<em>\u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c <\/em>\u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u0430\u043a\u0435\u0442\u0430 \u043a\u0430\u043a <code>len(elements) \/ 256<\/code>\u00a0\u0438 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043f\u043e\u0434 \u043d\u0438\u0445. \u0415\u0441\u043b\u0438 \u043d\u0430\u0448\u0430 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u0436\u0435\u043d\u043d\u043e\u0439, \u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u043e\u0441\u0442\u0430\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435:<\/p>\n<pre><code class=\"python\">class Bucket:     reserved: list     leftovers: list      def __init__(self, capacity):         self.reserved = reserve(capacity) # \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434         self.leftovers = []      def append(self, element):         if len(self.reserved) &lt; self.reserved.capacity(): # \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434             self.reserved.append(element)         else:             self.leftovers.append(element)      def __len__(self):         return len(self.reserved) + len(self.leftovers)      def __iter__(self):         yield from self.reserved         yield from self.leftovers<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u0435\u0434\u0451\u0442 \u0441\u0435\u0431\u044f \u0447\u0435\u0441\u0442\u043d\u043e: \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043b\u0438\u0448\u044c \u043a\u0440\u043e\u0448\u0435\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 <code>leftovers<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0438\u0448\u043d\u0438\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0430\u043b\u044b, \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0432 <code>leftovers<\/code>\u00a0\u0431\u044b\u0441\u0442\u0440\u044b, \u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u043a\u0430 \u043d\u0430 \u0431\u0430\u043a\u0435\u0442\u044b (\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u0431\u0430\u043a\u0435\u0442\u0430\u043c) \u0443\u0434\u043e\u0431\u043d\u0430 \u0434\u043b\u044f \u043a\u044d\u0448\u0430.<\/p>\n<h4>\u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435<\/h4>\n<p>\u041f\u0440\u043e\u0441\u0442\u0430\u044f \u043c\u0438\u043a\u0440\u043e\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u043d\u0430 \u0431\u043b\u043e\u043a\u0438, \u0430 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e <code>malloc<\/code>\u00a0(\u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u044b). \u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e, \u0438 \u044d\u0442\u043e \u043c\u0430\u043b\u043e\u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u0438\u0445 \u0432\u043b\u0438\u044f\u043d\u0438\u044f.<\/p>\n<h4>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439<\/h4>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434 \u043a \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u043c\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 \u043f\u0440\u0438 \u043c\u0430\u043b\u043e\u043c \u043e\u0431\u044a\u0451\u043c\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043e\u043b\u0435\u0435 \u044f\u0432\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 O(n log n). \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>radix_sort<\/code>\u00a0\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043e\u0431\u044a\u0451\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\"># \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 -- \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0430\u043b, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c if len(elements) &lt;= CUTOFF or bits &lt;= 8:     counts = [0] * 256     for element in elements:         counts[element.index &amp; 0xff] += 1      groups = [[] for _ in range(256)]     for element in elements:         groups[get_bucket(element)].append(element)      for group in groups:         if group:             yield group     return<\/code><\/pre>\n<p>\u041e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>CUTOFF<\/code>\u00a0\u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u0430\u0448\u0438\u043d\u044b. \u041e\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u043a\u044d\u0448\u0430 \u0438 RAM, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u043a\u044d\u0448\u0430 \u0438 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 64-\u0431\u0438\u0442\u043d\u044b\u0445 integer \u044f \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0430 \u043c\u0430\u0448\u0438\u043d\u044b, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0431\u044b\u043b\u043e <code>50k<\/code>,\u00a0<code>200k<\/code> \u0438 <code>1M<\/code>. \u041d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u2014 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u0432 \u0441\u0440\u0435\u0434\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f; \u044d\u0442\u043e \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u041f\u041e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h3>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a<\/h3>\n<h4>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430<\/h4>\n<p>\u0412\u043e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a.<\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u2014 \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 64-\u0431\u0438\u0442\u043d\u044b\u0445 integer. \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u0445\u044d\u0448\u0443, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043d\u0430 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0438, \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0431\u0430\u043a\u0435\u0442\u043e\u0432, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u0441\u0443\u043c\u043c\u0443 \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u043e\u0432 \u0441\u0440\u0435\u0434\u0438 \u0431\u0430\u043a\u0435\u0442\u043e\u0432. (\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u0430\u043a\u0435\u0442\u044b \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0438\u0436\u0435 \u043f\u043e \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0443 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u0434\u0440\u0443\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043a \u043a\u044d\u0448\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c.)<\/p>\n<p>\u041c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0434\u0432\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e\u0440\u0430\u0437\u0440\u044f\u0434\u043d\u043e\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0448\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0442\u0441\u0435\u0447\u043a\u043e\u0439 (cutoff).<\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u0440\u0435\u0434\u043d\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0433\u0440\u0443\u043f\u043f\u044b \u0440\u0430\u0432\u0435\u043d 10.<\/p>\n<p>\u041a\u043e\u0434 \u0432\u044b\u043b\u043e\u0436\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/purplesyringa\/site\/blob\/master\/blog\/the-ram-myth\/benchmark.rs\" rel=\"noopener noreferrer nofollow\">GitHub<\/a>.<\/p>\n<h4>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/h4>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0440\u0430\u0441\u0442\u0451\u0442 \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0451\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439, \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u0430\u0448\u0438\u043d\u044b, \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0442 2,5 \u0434\u043e 9 \u0440\u0430\u0437.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b (<code>A<\/code>,\u00a0<code>Y<\/code>,\u00a0<code>M<\/code>\u00a0\u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u043d\u044b\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430):<\/p>\n<figure class=\"full-width\"><\/figure>\n<figure class=\"full-width\"><\/figure>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u0442\u043e\u0438\u043b\u043e \u043b\u0438 \u043e\u043d\u043e \u0442\u043e\u0433\u043e? \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u0432\u0430\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430, \u0442\u043e \u043b\u044e\u0431\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044d\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0445\u044d\u0448\u0430 \u0431\u0435\u0437 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0439 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e \u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043b\u044e\u0431\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u0440\u0430\u0441\u043f\u043b\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0437\u0430 \u043d\u0435\u0451 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<p>\u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441 big data, \u0442\u043e \u043f\u0440\u043e \u044d\u0442\u043e\u0442 \u0442\u0440\u044e\u043a \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0438 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0432\u044b\u0432\u043e\u0434: \u0432\u0441\u0435 \u0437\u043d\u0430\u044e\u0442, \u0447\u0442\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0438\u0445 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e. \u042d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u043b\u043e\u0445\u043e\u0439. \u0423\u0440\u043e\u043a \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e \u0442\u0430\u043a\u0436\u0435 \u043a RAM \u0438 \u043a\u044d\u0448\u0443: \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0431\u043e\u043b\u044c\u0448\u0435, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, 32 \u041c\u0438\u0411 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0434 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u043d\u0430\u0434 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c \u043a \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u044c\u044e.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/868452\/\"> https:\/\/habr.com\/ru\/articles\/868452\/<\/a><br \/><\/br><\/br><\/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-443158","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/443158","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=443158"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/443158\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=443158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=443158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=443158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}