{"id":475921,"date":"2023-08-09T07:24:43","date_gmt":"2023-08-09T07:24:43","guid":{"rendered":""},"modified":"2023-09-05T11:11:35","modified_gmt":"2023-09-05T11:11:35","slug":"associative-array","status":"publish","type":"wiki","link":"https:\/\/oneproxy.pro\/cn\/wiki\/associative-array\/","title":{"rendered":"\u5173\u8054\u6570\u7ec4"},"content":{"rendered":"<p>\u5173\u4e8e\u5173\u8054\u6570\u7ec4\u7684\u7b80\u8981\u4fe1\u606f<\/p>\n<p>\u5173\u8054\u6570\u7ec4\uff0c\u4e5f\u79f0\u4e3a\u6620\u5c04\u6216\u5b57\u5178\uff0c\u662f\u8ba1\u7b97\u673a\u79d1\u5b66\u548c\u8f6f\u4ef6\u5f00\u53d1\u4e2d\u7684\u5173\u952e\u6570\u636e\u7ed3\u6784\u3002\u4e0e\u4f7f\u7528\u6574\u6570\u7d22\u5f15\u8bbf\u95ee\u5143\u7d20\u7684\u4f20\u7edf\u6570\u7ec4\u4e0d\u540c\uff0c\u5173\u8054\u6570\u7ec4\u4f7f\u7528\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u7684\u552f\u4e00\u952e\u6765\u6620\u5c04\u5230\u5176\u5bf9\u5e94\u7684\u503c\u3002\u8fd9\u79cd\u62bd\u8c61\u4f7f\u5f97\u66f4\u590d\u6742\u3001\u9002\u5e94\u6027\u66f4\u5f3a\u7684\u6570\u636e\u6a21\u578b\u7684\u5b9e\u73b0\u6210\u4e3a\u53ef\u80fd\uff0c\u4ece\u800c\u53d7\u76ca\u4e8e\u9ad8\u6548\u7684\u67e5\u627e\u3001\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u3002<\/p>\n<h2>\u5173\u8054\u6570\u7ec4\u7684\u8d77\u6e90\u548c\u5386\u53f2<\/h2>\n<p>\u81ea\u8ba1\u7b97\u673a\u79d1\u5b66\u8bde\u751f\u4ee5\u6765\uff0c\u5173\u8054\u6570\u7ec4\u4e00\u76f4\u662f\u8ba1\u7b97\u673a\u79d1\u5b66\u7684\u57fa\u7840\u3002\u5b83\u4eec\u7684\u7406\u8bba\u57fa\u7840\u53ef\u4ee5\u8ffd\u6eaf\u5230\u6570\u5b66\u4e2d\u7684\u51fd\u6570\u601d\u60f3\uff0c\u5176\u4e2d\u552f\u4e00\u7684\u8f93\u5165\uff08\u952e\uff09\u88ab\u6620\u5c04\u5230\u552f\u4e00\u7684\u8f93\u51fa\uff08\u503c\uff09\u3002\u7136\u800c\uff0c\u968f\u7740\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\u7684\u5174\u8d77\uff0c\u5b83\u4eec\u4f5c\u4e3a\u4e00\u79cd\u6570\u636e\u7ed3\u6784\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\u7684\u5b9e\u73b0\u624d\u53d8\u5f97\u7a81\u51fa\u3002<\/p>\n<p>\u5173\u8054\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5177\u4f53\u5b9e\u73b0\u662f\u5728 SNOBOL \u4e2d\uff0c\u8fd9\u662f 20 \u4e16\u7eaa 60 \u5e74\u4ee3\u65e9\u671f\u5f00\u53d1\u7684\u4e00\u79cd\u5b57\u7b26\u4e32\u5904\u7406\u8bed\u8a00\u3002\u540e\u6765\uff0c\u5b83\u4eec\u88ab\u6574\u5408\u5230\u5176\u4ed6\u6d41\u884c\u7684\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u4f8b\u5982 Perl\u3001Python\u3001PHP\u3001JavaScript \u7b49\uff0c\u5728\u8fd9\u4e9b\u8bed\u8a00\u4e2d\u5b83\u4eec\u901a\u5e38\u88ab\u79f0\u4e3a\u201c\u54c8\u5e0c\u201d\u3001\u201c\u5b57\u5178\u201d\u6216\u201c\u5bf9\u8c61\u201d\u3002<\/p>\n<h2>\u6df1\u5165\u63a2\u7d22\u5173\u8054\u6570\u7ec4<\/h2>\n<p>\u5173\u8054\u6570\u7ec4\u662f\u952e\u503c\u5bf9\u7684\u96c6\u5408\uff0c\u5176\u4e2d\u6bcf\u4e2a\u552f\u4e00\u952e\u90fd\u6620\u5c04\u5230\u4e00\u4e2a\u503c\u3002\u952e\u53ef\u4ee5\u662f\u4efb\u4f55\u6570\u636e\u7c7b\u578b\uff08\u4e0d\u4ec5\u4ec5\u662f\u6574\u6570\uff09\uff0c\u5e76\u7528\u4e8e\u68c0\u7d22\u76f8\u5e94\u7684\u503c\u3002\u8fd9\u4e0e\u4ec5\u5141\u8bb8\u6574\u6570\u7d22\u5f15\u7684\u4f20\u7edf\u6570\u7ec4\u5f62\u6210\u5bf9\u6bd4\u3002\u5728\u5173\u8054\u6570\u7ec4\u4e2d\uff0c\u952e\u4e0d\u5fc5\u662f\u8fde\u7eed\u7684\u6216\u6309\u4efb\u4f55\u7279\u5b9a\u987a\u5e8f\u6392\u5217\u3002<\/p>\n<p>\u5173\u8054\u6570\u7ec4\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u5305\u542b\u4e24\u5217\u7684\u8868\u3002\u7b2c\u4e00\u5217\u8868\u793a\u952e\uff0c\u7b2c\u4e8c\u5217\u8868\u793a\u503c\u3002\u952e\u503c\u5bf9\u7684\u5b58\u50a8\u987a\u5e8f\u4e0d\u56fa\u5b9a\uff0c\u53ef\u4ee5\u91cd\u65b0\u6392\u5217\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002<\/p>\n<h2>\u5173\u8054\u6570\u7ec4\u7684\u5185\u90e8\u7ed3\u6784\u53ca\u5176\u5de5\u4f5c\u539f\u7406<\/h2>\n<p>\u5728\u5185\u90e8\uff0c\u5173\u8054\u6570\u7ec4\u901a\u5e38\u4f7f\u7528\u54c8\u5e0c\u8868\u6216\u641c\u7d22\u6811\u6765\u5b9e\u73b0\u3002\u54c8\u5e0c\u8868\u4f7f\u7528\u54c8\u5e0c\u51fd\u6570\u5c06\u952e\u8f6c\u6362\u4e3a\u5e95\u5c42\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15\uff0c\u4e3a\u641c\u7d22\u3001\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u63d0\u4f9b\u6052\u5b9a\u65f6\u95f4\u5e73\u5747\u590d\u6742\u5ea6\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u641c\u7d22\u6811\uff08\u4f8b\u5982 AVL \u6811\u6216\u7ea2\u9ed1\u6811\uff09\u4ee5\u6392\u5e8f\u65b9\u5f0f\u4fdd\u5b58\u952e\uff0c\u4e3a\u8fd9\u4e9b\u64cd\u4f5c\u63d0\u4f9b log(n) \u65f6\u95f4\u590d\u6742\u5ea6\u3002<\/p>\n<h2>\u5173\u8054\u6570\u7ec4\u7684\u4e3b\u8981\u7279\u6027<\/h2>\n<ol>\n<li><strong>\u7075\u6d3b\u7684\u6309\u952e\uff1a<\/strong> \u4e0e\u5e38\u89c4\u6570\u7ec4\u4e0d\u540c\uff0c\u5173\u8054\u6570\u7ec4\u5141\u8bb8\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u7684\u952e\uff0c\u800c\u4e0d\u4ec5\u4ec5\u662f\u6574\u6570\u3002<\/li>\n<li><strong>\u4e0d\u8fde\u7eed\u7684\u952e\uff1a<\/strong> \u5173\u8054\u6570\u7ec4\u4e2d\u7684\u952e\u4e0d\u9700\u8981\u8fde\u7eed\u6216\u6309\u4efb\u4f55\u7279\u5b9a\u987a\u5e8f\u6392\u5217\u3002<\/li>\n<li><strong>\u52a8\u6001\u5c3a\u5bf8\uff1a<\/strong> \u5173\u8054\u6570\u7ec4\u7684\u5927\u5c0f\u53ef\u4ee5\u968f\u7740\u5143\u7d20\u7684\u6dfb\u52a0\u6216\u5220\u9664\u800c\u52a8\u6001\u5730\u589e\u5927\u6216\u7f29\u5c0f\u3002<\/li>\n<li><strong>\u9ad8\u6548\u8fd0\u8425\uff1a<\/strong> \u5982\u679c\u6b63\u786e\u5b9e\u73b0\uff0c\u5173\u8054\u6570\u7ec4\u53ef\u4ee5\u63d0\u4f9b\u9ad8\u6548\u7684\u641c\u7d22\u3001\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u3002<\/li>\n<\/ol>\n<h2>\u5173\u8054\u6570\u7ec4\u7684\u7c7b\u578b<\/h2>\n<p>\u5173\u8054\u6570\u7ec4\u53ef\u4ee5\u6839\u636e\u5176\u5b9e\u73b0\u65b9\u5f0f\u5927\u81f4\u5206\u4e3a\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u54c8\u5e0c\u8868<\/td>\n<td>\u4f7f\u7528\u54c8\u5e0c\u51fd\u6570\u5c06\u952e\u6620\u5c04\u5230\u5e95\u5c42\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u641c\u7d22\u6811<\/td>\n<td>\u4f7f\u7528\u6811\u7ed3\u6784\u4ee5\u6392\u5e8f\u7684\u65b9\u5f0f\u5b58\u50a8\u952e\u503c\u5bf9\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u5173\u8054\u6570\u7ec4\u7684\u5e94\u7528\u3001\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6848<\/h2>\n<p>\u5173\u8054\u6570\u7ec4\u901a\u5e38\u7528\u4e8e\u5b58\u50a8\u548c\u68c0\u7d22\u6570\u636e\uff0c\u5176\u4e2d\u8bbf\u95ee\u952e\u4e0d\u4e00\u5b9a\u662f\u6574\u6570\u6216\u5728\u4efb\u4f55\u7279\u5b9a\u8303\u56f4\u5185\u3002\u5b83\u4eec\u5728\u6570\u636e\u5e93\u7d22\u5f15\u3001\u7f13\u5b58\u548c\u6570\u636e\u5e8f\u5217\u5316\u7b49\u9886\u57df\u5f88\u5e38\u89c1\u3002\u4f46\u662f\uff0c\u54c8\u5e0c\u51b2\u7a81\uff08\u5728\u54c8\u5e0c\u8868\u5b9e\u73b0\u4e2d\uff09\u6216\u4e0d\u5e73\u8861\u6811\uff08\u5728\u641c\u7d22\u6811\u5b9e\u73b0\u4e2d\uff09\u7b49\u95ee\u9898\u53ef\u80fd\u4f1a\u5f71\u54cd\u6027\u80fd\u3002\u8fd9\u4e9b\u95ee\u9898\u901a\u5e38\u5206\u522b\u4f7f\u7528\u51b2\u7a81\u89e3\u51b3\u6280\u672f\u6216\u81ea\u5e73\u8861\u6811\u6765\u7f13\u89e3\u3002<\/p>\n<h2>\u4e0e\u7c7b\u4f3c\u6570\u636e\u7ed3\u6784\u7684\u6bd4\u8f83<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u6570\u636e\u7ed3\u6784<\/th>\n<th>\u6307\u6570\u7c7b\u578b<\/th>\n<th>\u547d\u4ee4<\/th>\n<th>\u641c\u7d22\u901f\u5ea6<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u5e38\u89c4\u6570\u7ec4<\/td>\n<td>\u6574\u6570<\/td>\n<td>\u5df2\u8ba2\u8d2d<\/td>\n<td>\u5728\uff09<\/td>\n<\/tr>\n<tr>\n<td>\u5173\u8054\u6570\u7ec4\uff08\u54c8\u5e0c\u8868\uff09<\/td>\n<td>\u4efb\u4f55<\/td>\n<td>\u65e0\u5e8f<\/td>\n<td>O(1) \u5e73\u5747\u503c<\/td>\n<\/tr>\n<tr>\n<td>\u5173\u8054\u6570\u7ec4\uff08\u641c\u7d22\u6811\uff09<\/td>\n<td>\u4efb\u4f55<\/td>\n<td>\u5df2\u8ba2\u8d2d<\/td>\n<td>O(logn)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4e0e\u5173\u8054\u6570\u7ec4\u76f8\u5173\u7684\u524d\u666f\u548c\u672a\u6765\u6280\u672f<\/h2>\n<p>\u5173\u8054\u6570\u7ec4\u7684\u6982\u5ff5\u4ecd\u7136\u662f\u73b0\u4ee3\u8ba1\u7b97\u7684\u57fa\u7840\uff0c\u5e76\u968f\u7740\u8ba1\u7b97\u673a\u79d1\u5b66\u7684\u8fdb\u6b65\u800c\u4e0d\u65ad\u53d1\u5c55\u3002\u5206\u5e03\u5f0f\u8ba1\u7b97\u548c\u6570\u636e\u5e93\u7684\u51fa\u73b0\u5bfc\u81f4\u4e86\u5206\u5e03\u5f0f\u54c8\u5e0c\u8868\u7684\u51fa\u73b0\uff0c\u8fd9\u662f\u5173\u8054\u6570\u7ec4\u7684\u4e00\u79cd\u5f62\u5f0f\u3002\u6b64\u5916\uff0cRedis \u7b49\u5185\u5b58\u6570\u636e\u5b58\u50a8\u7cfb\u7edf\u5229\u7528\u8be5\u6570\u636e\u7ed3\u6784\u6765\u63d0\u4f9b\u9ad8\u6027\u80fd\u548c\u7075\u6d3b\u6027\u3002<\/p>\n<h2>\u5173\u8054\u6570\u7ec4\u4e0e\u4ee3\u7406\u670d\u52a1\u5668\u7684\u4f7f\u7528<\/h2>\n<p>\u5728 OneProxy \u7b49\u4ee3\u7406\u670d\u52a1\u5668\u73af\u5883\u4e2d\uff0c\u5173\u8054\u6570\u7ec4\u5bf9\u4e8e\u7ef4\u62a4\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u8fde\u63a5\u7684\u6620\u5c04\u3001\u7f13\u5b58\u6570\u636e\u6216\u7ba1\u7406\u914d\u7f6e\u8bbe\u7f6e\u975e\u5e38\u6709\u7528\u3002\u5b83\u4eec\u63d0\u4f9b\u9ad8\u6548\u7684\u67e5\u627e\u548c\u4fee\u6539\u529f\u80fd\uff0c\u8fd9\u5bf9\u4e8e\u9ad8\u6027\u80fd\u7f51\u7edc\u670d\u52a1\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<h2>\u76f8\u5173\u94fe\u63a5<\/h2>\n<ol>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Associative_array\" target=\"_new\" rel=\"noopener nofollow\">\u8ba1\u7b97\u673a\u7f16\u7a0b\u4e2d\u7684\u5173\u8054\u6570\u7ec4<\/a><\/li>\n<li><a href=\"https:\/\/www.hackerearth.com\/practice\/data-structures\/hash-tables\/basics-of-hash-tables\/tutorial\/\" target=\"_new\" rel=\"noopener nofollow\">\u7406\u89e3\u54c8\u5e0c\u8868<\/a><\/li>\n<li><a href=\"https:\/\/www.tutorialspoint.com\/data_structures_algorithms\/tree_data_structure.htm\" target=\"_new\" rel=\"noopener nofollow\">\u6811\u6728\u7b80\u4ecb<\/a><\/li>\n<li><a href=\"https:\/\/redis.io\/\" target=\"_new\" rel=\"noopener nofollow\">Redis\uff1a\u5185\u5b58\u6570\u636e\u7ed3\u6784\u5b58\u50a8<\/a><\/li>\n<\/ol>","protected":false},"featured_media":467650,"menu_order":0,"template":"","meta":{"_acf_changed":false,"content-type":"","inline_featured_image":false,"footnotes":""},"class_list":["post-475921","wiki","type-wiki","status-publish","has-post-thumbnail","hentry"],"acf":{"faq_title":"Frequently Asked Questions about <mark>Associative Arrays: Understanding, Implementing, and Using Them<\/mark>","faq_items":[{"question":"What is an Associative Array?","answer":"<p>An associative array is a data structure that consists of a collection of key-value pairs where each unique key maps to a value. Unlike traditional arrays that use integer indices to access elements, associative arrays use keys of any data type.<\/p>"},{"question":"When were Associative Arrays first used?","answer":"<p>The first implementation of associative arrays was in the early 1960s with the string manipulation language SNOBOL. However, the concept of mapping unique inputs to outputs has roots in the idea of functions in mathematics.<\/p>"},{"question":"How are Associative Arrays internally structured?","answer":"<p>Associative arrays are commonly implemented using hash tables or search trees. Hash tables use a hash function to convert keys into an index in an underlying array. Search trees, on the other hand, use a tree structure to store key-value pairs in a sorted manner.<\/p>"},{"question":"What are the key features of Associative Arrays?","answer":"<p>The key features of associative arrays include the use of flexible keys (of any data type), the non-contiguous and unordered nature of keys, their dynamic size, and efficient search, insertion, and deletion operations.<\/p>"},{"question":"What types of Associative Arrays exist?","answer":"<p>Associative arrays can be broadly classified into two types based on their implementation: hash tables and search trees.<\/p>"},{"question":"How are Associative Arrays used, and what problems can occur?","answer":"<p>Associative arrays are commonly used in areas such as database indexing, caching, and data serialization. Issues like hash collisions (in hash table implementations) or unbalanced trees (in search tree implementations) can affect performance. These issues are generally solved using collision resolution techniques or self-balancing trees, respectively.<\/p>"},{"question":"How do Associative Arrays compare to similar data structures?","answer":"<p>Compared to regular arrays, associative arrays offer more flexibility in terms of key data types and order, as well as typically faster search speed. Depending on their specific implementation, associative arrays may maintain an ordered or unordered collection of key-value pairs.<\/p>"},{"question":"What future developments are expected for Associative Arrays?","answer":"<p>Future technologies related to associative arrays include their use in distributed computing and databases, leading to structures like distributed hash tables. In-memory data store systems like Redis also use associative arrays for high performance and flexibility.<\/p>"},{"question":"How can Associative Arrays be used with proxy servers?","answer":"<p>In the context of proxy servers, associative arrays can be used for maintaining a mapping of clients to server connections, caching data, or managing configuration settings. Their efficient lookup and modification capabilities make them highly valuable for high-performance network services.<\/p>"}]},"_links":{"self":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki\/475921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki"}],"about":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/types\/wiki"}],"version-history":[{"count":0,"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki\/475921\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/media\/467650"}],"wp:attachment":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/media?parent=475921"}],"curies":[{"name":"\u53ef\u6e7f\u6027\u7c89\u5242","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}