{"id":201537,"date":"2025-05-10T11:04:46","date_gmt":"2025-05-10T03:04:46","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201537\/"},"modified":"2025-05-10T11:04:46","modified_gmt":"2025-05-10T03:04:46","slug":"%e4%b8%80%e6%96%87%e5%bd%bb%e5%ba%95%e6%90%9e%e6%b8%85%e8%b7%b3%e8%b7%83%e8%a1%a8%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e4%b8%8e%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201537\/","title":{"rendered":"\u4e00\u6587\u5f7b\u5e95\u641e\u6e05\u8df3\u8dc3\u8868\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u4e00\u6587\u5f7b\u5e95\u641e\u6e05\u8df3\u8dc3\u8868\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p><span style=\"color: #FF6600;font-family:\">\u6570\u636e\u5e93<\/span>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;font-family:\">\u300a\u4e00\u6587\u5f7b\u5e95\u641e\u6e05\u8df3\u8dc3\u8868\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;font-family:\">\u6570\u636e\u3001\u7ed3\u6784\u3001\u8df3\u8dc3\u8868<\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p>\u4f5c\u8005\uff1a\u4eac\u4e1c\u7269\u6d41 \u7eaa\u5353\u5fd7<\/p>\n<p>\u76ee\u524d\u5e02\u9762\u4e0a\u5145\u65a5\u7740\u5927\u91cf\u5173\u4e8e\u8df3\u8dc3\u8868\u7ed3\u6784\u4e0eRedis\u7684\u6e90\u7801\u89e3\u6790\uff0c\u4f46\u662f\u7ecf\u8fc7\u957f\u671f\u89c2\u5bdf\u540e\u53d1\u73b0\u5927\u90fd\u53ea\u662f\u5728\u505c\u7559\u5728\u4ee3\u7801\u7684\u8868\u9762\uff0c\u800c\u6ca1\u6709\u7cfb\u7edf\u6027\u5730\u4ecb\u7ecd\u8df3\u8dc3\u8868\u7684\u7531\u6765\u4ee5\u53ca\u5404\u79cd\u5e38\u91cf\u7684\u7531\u6765\u3002\u4f5c\u4e3a\u4e00\u79cd\u6982\u7387\u6570\u636e\u7ed3\u6784\uff0c\u7406\u89e3\u5404\u79cd\u5e38\u91cf\u7684\u7531\u6765\u53ef\u4ee5\u66f4\u597d\u5730\u8fdb\u884c\u53d8\u5316\u5e76\u5e94\u7528\u5230\u9ad8\u6027\u80fd\u529f\u80fd\u5f00\u53d1\u4e2d\u3002\u672c\u6587\u6ca1\u6709\u91cd\u590d\u5730\u4ee5\u5bf9\u73b0\u6709\u4f18\u79c0\u5b9e\u73b0\u8fdb\u884c\u4ee3\u7801\u5206\u6790\uff0c\u800c\u662f\u901a\u8fc7\u5bf9\u8df3\u8dc3\u8868\u8fdb\u884c\u4e86\u7cfb\u7edf\u6027\u5730\u4ecb\u7ecd\u4e0e\u5f62\u5f0f\u5316\u5206\u6790\uff0c\u5e76\u7ed9\u51fa\u4e86\u5728\u7279\u5b9a\u573a\u666f\u4e0b\u7684\u8df3\u8dc3\u8868\u6269\u5c55\u65b9\u5f0f\uff0c\u65b9\u4fbf\u8bfb\u8005\u66f4\u597d\u5730\u7406\u89e3\u8df3\u8dc3\u8868\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<p><span style=\"color: #606c71\">\u8df3\u8dc3\u8868[1,2,3]\u662f\u4e00\u79cd\u7528\u4e8e\u5728\u5927\u591a\u6570\u5e94\u7528\u7a0b\u5e8f\u4e2d\u53d6\u4ee3\u5e73\u8861\u6811\u7684\u6982\u7387\u6570\u636e\u7ed3\u6784\u3002\u8df3\u8dc3\u8868\u62e5\u6709\u4e0e\u5e73\u8861\u6811\u76f8\u540c\u7684\u671f\u671b\u65f6\u95f4\u4e0a\u754c\uff0c\u5e76\u4e14\u66f4\u7b80\u5355\u3001\u66f4\u5feb\u3001\u662f\u7528\u66f4\u5c11\u7684\u7a7a\u95f4\u3002\u5728\u67e5\u627e\u4e0e\u5217\u8868\u7684\u7ebf\u6027\u64cd\u4f5c\u4e0a\uff0c\u6bd4\u5e73\u8861\u6811\u66f4\u5feb\uff0c\u5e76\u4e14\u66f4\u7b80\u5355\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u6982\u7387\u5e73\u8861\u4e5f\u53ef\u4ee5\u88ab\u7528\u5728\u57fa\u4e8e\u6811\u7684\u6570\u636e\u7ed3\u6784[4]\u4e0a\uff0c\u4f8b\u5982\u6811\u5806\uff08Treap\uff09\u3002\u4e0e\u5e73\u8861\u4e8c\u53c9\u6811\u76f8\u540c\uff0c\u8df3\u8dc3\u8868\u4e5f\u5b9e\u73b0\u4e86\u4ee5\u4e0b\u4e24\u79cd\u64cd\u4f5c<\/span><\/p>\n<ol>\n<li>\n<p><span style=\"color: #606c71\">\u901a\u8fc7\u641c\u7d22\u5f15\u7528[5]\uff0c\u53ef\u4ee5\u4fdd\u8bc1\u4ece\u4efb\u610f\u5143\u7d20\u5f00\u59cb\uff0c\u641c\u7d22\u5230\u5728\u5217\u8868\u4e2d\u95f4\u9694\u4e3ak\u7684\u5143\u7d20\u7684\u4efb\u610f\u671f\u671b\u65f6\u95f4\u662fO(logk)<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">\u5b9e\u73b0\u7ebf\u6027\u8868\u7684\u5e38\u89c4\u64cd\u4f5c\uff08\u4f8b\u5982<em>\u5c06\u5143\u7d20\u63d2\u5165\u5230\u5217\u8868\u7b2ck\u4e2a\u5143\u7d20\u540e\u9762<\/em>\uff09<\/span><\/p>\n<\/li>\n<\/ol>\n<p><span style=\"color: #606c71\">\u8fd9\u51e0\u79cd\u64cd\u4f5c\u5728\u5e73\u8861\u6811\u4e2d\u4e5f\u53ef\u4ee5\u5b9e\u73b0\uff0c\u4f46\u662f\u5728\u8df3\u8dc3\u8868\u4e2d\u5b9e\u73b0\u8d77\u6765\u66f4\u7b80\u5355\u800c\u4e14\u975e\u5e38\u7684\u5feb\uff0c\u5e76\u4e14\u901a\u5e38\u60c5\u51b5\u4e0b\u5f88\u96be\u5728\u5e73\u8861\u6811\u4e2d\u76f4\u63a5\u5b9e\u73b0\uff08\u6811\u7684\u7ebf\u7d22\u5316\u53ef\u4ee5\u5b9e\u73b0\u4e0e\u94fe\u8868\u76f8\u540c\u7684\u6548\u679c\uff0c\u4f46\u662f\u8fd9\u4f7f\u5f97\u5b9e\u73b0\u53d8\u5f97\u66f4\u52a0\u590d\u6742[6]\uff09<\/span><\/p>\n<h2>\u9884\u89c8<\/h2>\n<p><span style=\"color: #606c71\">\u6700\u7b80\u5355\u7684\u652f\u6301\u67e5\u627e\u7684\u6570\u636e\u7ed3\u6784\u53ef\u80fd\u5c31\u662f\u94fe\u8868\u3002Figure.1\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u94fe\u8868\u3002\u5728\u94fe\u8868\u4e2d\u6267\u884c\u4e00\u6b21\u67e5\u627e\u7684\u65f6\u95f4\u6b63\u6bd4\u4e8e\u5fc5\u987b\u8003\u67e5\u7684\u8282\u70b9\u4e2a\u6570\uff0c\u8fd9\u4e2a\u4e2a\u6570\u6700\u591a\u662fN\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791163e341d7890be.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.1 Linked List<\/span><\/p>\n<p><span style=\"color: #606c71\">Figure.2\u8868\u793a\u4e00\u4e2a\u94fe\u8868\uff0c\u5728\u8be5\u94fe\u8868\u4e2d\uff0c\u6bcf\u4e2a\u4e00\u4e2a\u8282\u70b9\u5c31\u6709\u4e00\u4e2a\u9644\u52a0\u7684\u6307\u9488\u6307\u5411\u5b83\u5728\u8868\u4e2d\u7684\u524d\u4e24\u4e2a\u4f4d\u7f6e\u4e0a\u7684\u8282\u70b9\u3002\u6b63\u56e0\u4e3a\u8fd9\u4e2a\u524d\u5411\u6307\u9488\uff0c\u5728\u6700\u574f\u60c5\u51b5\u4e0b\u6700\u591a\u8003\u67e5\u2308N\/2\u2309+1\u4e2a\u8282\u70b9\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791163e341d7c83dc.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.2 Linked List with fingers to the 2nd forward elements<\/span><\/p>\n<p><span style=\"color: #606c71\">Figure.3\u5c06\u8fd9\u79cd\u60f3\u6cd5\u6269\u5c55\uff0c\u6bcf\u4e2a\u5e8f\u6570\u662f4\u7684\u500d\u6570\u7684\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u6307\u9488\u6307\u5411\u4e0b\u4e00\u4e2a\u5e8f\u6570\u4e3a4\u7684\u500d\u6570\u7684\u8282\u70b9\u3002\u53ea\u6709\u2308N\/4\u2309+2\u4e2a\u8282\u70b9\u88ab\u8003\u67e5\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791263e341d80e65f.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.3 Linked List with fingers to the 4th forward elements<\/span><\/p>\n<p><span style=\"color: #606c71\">\u8fd9\u79cd\u8df3\u8dc3\u5e45\u5ea6\u7684\u4e00\u822c\u60c5\u51b5\u5982Figure.4\u6240\u793a\u3002\u6bcf\u4e2a2i\u8282\u70b9\u5c31\u6709\u4e00\u4e2a\u6307\u9488\u6307\u5411\u4e0b\u4e00\u4e2a2i\u8282\u70b9\uff0c\u524d\u5411\u6307\u9488\u7684\u95f4\u9694\u6700\u5927\u4e3aN\/2\u3002\u53ef\u4ee5\u8bc1\u660e\u603b\u7684\u6307\u9488\u6700\u5927\u4e0d\u4f1a\u8d85\u8fc72N\uff08\u89c1\u7a7a\u95f4\u590d\u6742\u5ea6\u5206\u6790\uff09\uff0c\u4f46\u73b0\u5728\u5728\u4e00\u6b21\u67e5\u627e\u4e2d\u6700\u591a\u8003\u67e5\u2308logN\u2309\u4e2a\u8282\u70b9\u3002\u8fd9\u610f\u5473\u7740\u4e00\u6b21\u67e5\u627e\u4e2d\u603b\u7684\u65f6\u95f4\u6d88\u8017\u4e3aO(logN)\uff0c\u4e5f\u5c31\u662f\u8bf4\u5728\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u67e5\u627e\u57fa\u672c\u7b49\u540c\u4e8e\u4e8c\u5206\u67e5\u627e\uff08binary search\uff09\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791263e341d84e0c1.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.4 Linked List with fingers to the 2ith forward elements<\/span><\/p>\n<p><span style=\"color: #606c71\">\u5728\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u7531\u4e00\u4e2a\u8282\u70b9\u8868\u793a\u3002\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u9ad8\u5ea6\uff08height\uff09\u6216\u7ea7\u522b\uff08level\uff09\uff0c\u8868\u793a\u8282\u70b9\u6240\u62e5\u6709\u7684\u524d\u5411\u6307\u9488\u6570\u91cf\u3002\u6bcf\u4e2a\u8282\u70b9\u7684\u7b2ci\u4e2a\u524d\u5411\u6307\u9488\u6307\u5411\u4e0b\u4e00\u4e2a\u7ea7\u522b\u4e3ai\u6216\u66f4\u9ad8\u7684\u8282\u70b9\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u5728\u524d\u9762\u63cf\u8ff0\u7684\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\u90fd\u662f\u4e0e\u5143\u7d20\u6570\u91cf\u6709\u5173\u7684\uff0c\u5f53\u63d2\u5165\u6216\u5220\u9664\u65f6\u9700\u8981\u5bf9\u6570\u636e\u7ed3\u6784\u8fdb\u884c\u8c03\u6574\u6765\u6ee1\u8db3\u8fd9\u6837\u7684\u7ea6\u675f\uff0c\u8fd9\u662f\u5f88\u5446\u677f\u4e14\u4f4e\u6548\u7684\u3002\u4e3a\u6b64\uff0c\u53ef\u4ee5<em>\u5c06\u6bcf\u4e2a2i\u8282\u70b9\u5c31\u6709\u4e00\u4e2a\u6307\u9488\u6307\u5411\u4e0b\u4e00\u4e2a2i\u8282\u70b9<\/em>\u7684\u9650\u5236\u53bb\u6389\uff0c\u5f53\u65b0\u5143\u7d20\u63d2\u5165\u65f6\u4e3a\u6bcf\u4e2a\u65b0\u8282\u70b9\u5206\u914d\u4e00\u4e2a\u968f\u673a\u7684\u7ea7\u522b\u800c\u4e0d\u7528\u8003\u8651\u6570\u636e\u7ed3\u6784\u7684\u5143\u7d20\u6570\u91cf\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u867d\u7136\u65e0\u6cd5\u901a\u8fc7\u5143\u7d20\u6570\u91cf\u6765\u786e\u5b9a\u6bcf\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\uff0c\u4f46\u662f\u901a\u8fc7\u8003\u67e5Figure.1\u5230Figure.4\u4e2d\u7684\u8282\u70b9\u5206\u5e03\u89c4\u5f8b\u4e0d\u96be\u53d1\u73b0\uff0c<em>\u968f\u7740\u7ea7\u522b\u7684\u589e\u52a0\uff0c\u5f53\u524d\u7ea7\u522b\u7684\u8282\u70b9\u6570\u91cf\u6210\u6bd4\u4f8b\u51cf\u5c11<\/em>\u3002\u5728Figure.1\u5230Figure.4\u4e2d\uff0c\u8fd9\u4e2a\u6bd4\u4f8b\u662f12\uff0c\u4e5f\u5c31\u662f\u8bf4\u53ea\u670912i\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\u662fi\uff0c\u968f\u673a\u9009\u62e9\u8282\u70b9\u7684\u7ea7\u522b\u7684\u6982\u7387\u5206\u5e03\u9075\u5faaP(X)=(12)X\u3002\u6240\u4ee5Figure.5\u4e5f\u53ef\u4ee5\u8ba4\u4e3a\u662f\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u7684\u4e00\u4e2a\u5b9e\u4f8b\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791263e341d88d479.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.5 Skip List<\/span><\/p>\n<h2>\u6570\u636e\u7ed3\u6784<\/h2>\n<p><span style=\"color: #606c71\">\u5230\u6b64\u4e3a\u6b62\uff0c\u5df2\u7ecf\u5f97\u5230\u4e86\u6240\u6709\u8ba9\u94fe\u8868\u652f\u6301\u5feb\u901f\u67e5\u627e\u7684\u5145\u8981\u6761\u4ef6\uff0c\u800c\u8fd9\u79cd\u5f62\u5f0f\u7684\u6570\u636e\u7ed3\u6784\u5c31\u662f\u8df3\u8dc3\u8868\u3002\u63a5\u4e0b\u6765\u5c06\u4f1a\u4f7f\u7528\u66f4\u6b63\u89c4\u7684\u65b9\u5f0f\u6765\u5b9a\u4e49\u8df3\u8dc3\u8868<\/span><\/p>\n<ol>\n<li>\n<p><span style=\"color: #606c71\">\u6240\u6709\u5143\u7d20\u5728\u8df3\u8dc3\u8868\u4e2d\u90fd\u662f\u7531\u4e00\u4e2a\u8282\u70b9\u8868\u793a\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u9ad8\u5ea6\u6216\u7ea7\u522b\uff0c\u6709\u65f6\u5019\u4e5f\u53ef\u4ee5\u79f0\u4e4b\u4e3a\u9636\uff08step\uff09\uff0c\u8282\u70b9\u7684\u7ea7\u522b\u662f\u4e00\u4e2a\u4e0e\u5143\u7d20\u603b\u6570\u65e0\u5173\u7684\u968f\u673a\u6570\u3002\u89c4\u5b9a<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">NULL<\/span><\/span>\u7684\u7ea7\u522b\u662f\u221e\u3002<\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">\u6bcf\u4e2a\u7ea7\u522b\u4e3ak\u7684\u8282\u70b9\u90fd\u6709k\u4e2a\u524d\u5411\u6307\u9488\uff0c\u4e14\u7b2ci\u4e2a\u524d\u5411\u6307\u9488\u6307\u5411\u4e0b\u4e00\u4e2a\u7ea7\u522b\u4e3ai\u6216\u66f4\u9ad8\u7684\u8282\u70b9\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">\u6bcf\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\u90fd\u4e0d\u4f1a\u8d85\u8fc7\u4e00\u4e2a\u660e\u786e\u7684\u5e38\u91cf<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">MaxLevel<\/span><\/span>\u3002\u6574\u4e2a\u8df3\u8dc3\u8868\u7684\u7ea7\u522b\u662f\u6240\u6709\u8282\u70b9\u7684\u7ea7\u522b\u7684\u6700\u9ad8\u503c\u3002\u5982\u679c\u8df3\u8dc3\u8868\u662f\u7a7a\u7684\uff0c\u90a3\u4e48\u8df3\u8dc3\u8868\u7684\u7ea7\u522b\u5c31\u662f1\u3002<\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">\u5b58\u5728\u4e00\u4e2a\u5934\u8282\u70b9<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">head<\/span><\/span>\uff0c\u5b83\u7684\u7ea7\u522b\u662f<span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">MaxLevel<\/span><\/span>\uff0c\u6240\u6709\u9ad8\u4e8e\u8df3\u8dc3\u8868\u7684\u7ea7\u522b\u7684\u524d\u5411\u6307\u9488\u90fd\u6307\u5411<span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">NULL<\/span><\/span>\u3002<\/p>\n<\/li>\n<\/ol>\n<p><span style=\"color: #606c71\">\u7a0d\u540e\u5c06\u4f1a\u63d0\u5230\uff0c\u8282\u70b9\u7684\u67e5\u627e\u8fc7\u7a0b\u662f\u5728\u5934\u8282\u70b9\u4ece\u6700\u9ad8\u7ea7\u522b\u7684\u6307\u9488\u5f00\u59cb\uff0c\u6cbf\u7740\u8fd9\u4e2a\u7ea7\u522b\u4e00\u76f4\u8d70\uff0c\u76f4\u5230\u627e\u5230\u5927\u4e8e\u6b63\u5728\u5bfb\u627e\u7684\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\uff08\u6216\u8005\u662f<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">NULL<\/span><\/span>\uff09\uff0c\u5728\u6b64\u8fc7\u7a0b\u4e2d\u9664\u4e86\u5934\u8282\u70b9\u5916\u5e76\u6ca1\u6709\u4f7f\u7528\u5230\u6bcf\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\uff0c\u56e0\u6b64<strong>\u6bcf\u4e2a\u8282\u70b9\u65e0\u9700\u5b58\u50a8\u8282\u70b9\u7684\u7ea7\u522b<\/strong>\u3002<\/p>\n<p><span style=\"color: #606c71\">\u5728\u8df3\u8dc3\u8868\u4e2d\uff0c\u7ea7\u522b\u4e3a1\u7684\u524d\u5411\u6307\u9488\u4e0e\u539f\u59cb\u7684\u94fe\u8868\u7ed3\u6784\u4e2d<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">next<\/span><\/span>\u6307\u9488\u7684\u4f5c\u7528\u5b8c\u5168\u76f8\u540c\uff0c\u56e0\u6b64\u8df3\u8dc3\u8868\u652f\u6301\u6240\u6709\u94fe\u8868\u652f\u6301\u7684\u7b97\u6cd5\u3002<\/p>\n<p><span style=\"color: #606c71\">\u5bf9\u5e94\u5230\u9ad8\u7ea7\u8bed\u8a00\u4e2d\u7684\u7ed3\u6784\u5b9a\u4e49\u5982\u4e0b\u6240\u793a\uff08\u540e\u7eed\u6240\u6709\u4ee3\u7801\u793a\u4f8b\u90fd\u5c06\u4f7f\u7528C\u8bed\u8a00\u63cf\u8ff0\uff09<\/span><\/p>\n<p>#define SKIP_LIST_KEY_TYPE &nbsp; &nbsp; <span style=\"color: #22863a\">int<\/span><br \/>#define SKIP_LIST_VALUE_TYPE &nbsp; <span style=\"color: #22863a\">int<\/span><br \/>#define SKIP_LIST_MAX_LEVEL &nbsp; &nbsp;<span style=\"color: #005cc5\">32<\/span><br \/>#define SKIP_LIST_P &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #005cc5\">0.5<\/span><\/p>\n<p>struct Node <span style=\"color: #997\">{<\/span><br \/> &nbsp;SKIP_LIST_KEY_TYPE &nbsp; &nbsp;key;<br \/> &nbsp;SKIP_LIST_VALUE_TYPE &nbsp;value;<br \/> &nbsp;struct Node &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #d73a49\">*<\/span>forwards<span style=\"color: #997\">[<\/span><span style=\"color: #997\">]<\/span>; <span style=\"color: #d73a49\">\/\/<\/span> flexible array member<br \/><span style=\"color: #997\">}<\/span>;<\/p>\n<p>struct SkipList <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span>head;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;level;<br \/><span style=\"color: #997\">}<\/span>;<\/p>\n<p>struct Node <span style=\"color: #d73a49\">*<\/span>CreateNode<span style=\"color: #997\">(<\/span><span style=\"color: #22863a\">int<\/span> level<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span>node;<br \/> &nbsp;assert<span style=\"color: #997\">(<\/span>level <span style=\"color: #d73a49\">&gt;<\/span> <span style=\"color: #005cc5\">0<\/span><span style=\"color: #997\">)<\/span>;<br \/> &nbsp;node <span style=\"color: #d73a49\">=<\/span> malloc<span style=\"color: #997\">(<\/span>sizeof<span style=\"color: #997\">(<\/span>struct Node<span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\">+<\/span> sizeof<span style=\"color: #997\">(<\/span>struct Node <span style=\"color: #d73a49\">*<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\">*<\/span> level<span style=\"color: #997\">)<\/span>;<br \/> &nbsp;return node;<br \/><span style=\"color: #997\">}<\/span><\/p>\n<p>struct SkipList <span style=\"color: #d73a49\">*<\/span>CreateSkipList<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct SkipList <span style=\"color: #d73a49\">*<\/span>list;<br \/> &nbsp;struct Node &nbsp; &nbsp; <span style=\"color: #d73a49\">*<\/span>head;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i;<\/p>\n<p> &nbsp;list <span style=\"color: #d73a49\">=<\/span> malloc<span style=\"color: #997\">(<\/span>sizeof<span style=\"color: #997\">(<\/span>struct SkipList<span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span>;<br \/> &nbsp;head <span style=\"color: #d73a49\">=<\/span> CreateNode<span style=\"color: #997\">(<\/span>SKIP_LIST_MAX_LEVEL<span style=\"color: #997\">)<\/span>;<br \/> &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">0<\/span>; i <span style=\"color: #d73a49\"> SKIP_LIST_MAX_LEVEL; i<span style=\"color: #d73a49\">++<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;head<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #905\">NULL<\/span>;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp;list<span style=\"color: #d73a49\">-&gt;<\/span>head <span style=\"color: #d73a49\">=<\/span> head;<br \/> &nbsp;list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">1<\/span>;<\/p>\n<p> &nbsp;return list;<br \/><span style=\"color: #997\">}<\/span><\/span><\/p>\n<p><span style=\"color: #606c71\">\u4ece\u524d\u9762\u7684\u9884\u89c8\u7ae0\u8282\u4e2d\uff0c\u4e0d\u96be\u770b\u51fa<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">MaxLevel<\/span><\/span>\u7684\u9009\u503c\u5f71\u54cd\u7740\u8df3\u8dc3\u8868\u7684\u67e5\u8be2\u6027\u80fd\uff0c\u5173\u4e8e<span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">MaxLevel<\/span><\/span>\u7684\u9009\u503c\u5c06\u4f1a\u5728\u540e\u7eed\u7ae0\u8282\u4e2d\u8fdb\u884c\u4ecb\u7ecd\u3002\u5728\u6b64\u5148\u5c06<span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">MaxLevel<\/span><\/span>\u5b9a\u4e49\u4e3a32\uff0c\u8fd9\u5bf9\u4e8e232\u4e2a\u5143\u7d20\u7684\u8df3\u8dc3\u8868\u662f\u8db3\u591f\u7684\u3002\u5ef6\u7eed\u9884\u89c8\u7ae0\u8282\u4e2d\u7684\u63cf\u8ff0\uff0c\u8df3\u8dc3\u8868\u7684\u6982\u7387\u88ab\u5b9a\u4e49\u4e3a0.5\uff0c\u5173\u4e8e\u8fd9\u4e2a\u503c\u7684\u9009\u53d6\u95ee\u9898\u5c06\u4f1a\u5728\u540e\u7eed\u7ae0\u8282\u4e2d\u8fdb\u884c\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<h2>\u7b97\u6cd5<\/h2>\n<h2>\u641c\u7d22<\/h2>\n<p><span style=\"color: #606c71\">\u5728\u8df3\u8dc3\u8868\u4e2d\u8fdb\u884c\u641c\u7d22\u7684\u8fc7\u7a0b\uff0c\u662f\u901a\u8fc7Z\u5b57\u5f62\u904d\u5386\u6240\u6709\u6ca1\u6709\u8d85\u8fc7\u8981\u5bfb\u627e\u7684\u76ee\u6807\u5143\u7d20\u7684\u524d\u5411\u6307\u9488\u6765\u5b8c\u6210\u7684\u3002\u5728\u5f53\u524d\u7ea7\u522b\u6ca1\u6709\u53ef\u4ee5\u79fb\u52a8\u7684\u524d\u5411\u6307\u9488\u65f6\uff0c\u5c06\u4f1a\u79fb\u52a8\u5230\u4e0b\u4e00\u7ea7\u522b\u8fdb\u884c\u641c\u7d22\u3002\u76f4\u5230\u5728\u7ea7\u522b\u4e3a1\u7684\u65f6\u5019\u4e14\u6ca1\u6709\u53ef\u4ee5\u79fb\u52a8\u7684\u524d\u5411\u6307\u9488\u65f6\u505c\u6b62\u641c\u7d22\uff0c\u6b64\u65f6\u76f4\u63a5\u6307\u5411\u7684\u8282\u70b9\uff08\u7ea7\u522b\u4e3a1\u7684\u524d\u5411\u6307\u9488\uff09\u5c31\u662f\u5305\u542b\u76ee\u6807\u5143\u7d20\u7684\u8282\u70b9\uff08\u5982\u679c\u76ee\u6807\u5143\u7d20\u5728\u5217\u8868\u4e2d\u7684\u8bdd\uff09\u3002\u5728Figure.6\u4e2d\u5c55\u793a\u4e86\u5728\u8df3\u8dc3\u8868\u4e2d\u641c\u7d22\u5143\u7d2017\u7684\u8fc7\u7a0b\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791263e341d8c7c49.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.6 A search path to find element 17 in Skip List<\/span><\/p>\n<p><span style=\"color: #606c71\">\u6574\u4e2a\u8fc7\u7a0b\u7684\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff0c\u56e0\u4e3a\u9ad8\u7ea7\u8bed\u8a00\u4e2d\u7684\u6570\u7ec4\u4e0b\u6807\u4ece<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">0<\/span><\/span>\u5f00\u59cb\uff0c\u56e0\u6b64<span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">forwards[0]<\/span><\/span>\u8868\u793a\u8282\u70b9\u7684\u7ea7\u522b\u4e3a1\u7684\u524d\u5411\u6307\u9488\uff0c\u4f9d\u6b64\u7c7b\u63a8<\/p>\n<p>struct Node <span style=\"color: #d73a49\">*<\/span>SkipListSearch<span style=\"color: #997\">(<\/span>struct SkipList <span style=\"color: #d73a49\">*<\/span>list, SKIP_LIST_KEY_TYPE target<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span>current;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i;<\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>head;<br \/> &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">&#8211;<\/span> <span style=\"color: #005cc5\">1<\/span>; i <span style=\"color: #d73a49\">&gt;=<\/span> <span style=\"color: #005cc5\">0<\/span>; i<span style=\"color: #6a737d\">&#8211;) {<\/span><br \/> &nbsp; &nbsp;while <span style=\"color: #997\">(<\/span>current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">&amp;&amp;<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\"> target<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;current <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span>;<br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span><span style=\"color: #005cc5\">0<\/span><span style=\"color: #997\">]<\/span>;<br \/> &nbsp;if <span style=\"color: #997\">(<\/span>current<span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\">==<\/span> target<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;return current;<br \/> &nbsp;<span style=\"color: #997\">}<\/span> else <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;return <span style=\"color: #905\">NULL<\/span>;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><br \/><span style=\"color: #997\">}<\/span><\/span><\/p>\n<h2>\u63d2\u5165\u548c\u5220\u9664<\/h2>\n<\/p>\n<p><span style=\"color: #606c71\">\u5728\u63d2\u5165\u548c\u5220\u9664\u8282\u70b9\u7684\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u6267\u884c\u548c\u641c\u7d22\u76f8\u540c\u7684\u903b\u8f91\u3002\u5728\u641c\u7d22\u7684\u57fa\u7840\u4e0a\uff0c\u9700\u8981\u7ef4\u62a4\u4e00\u4e2a\u540d\u4e3a<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">update<\/span><\/span>\u7684\u5411\u91cf\uff0c\u5b83\u7ef4\u62a4\u7684\u662f\u641c\u7d22\u8fc7\u7a0b\u4e2d\u8df3\u8dc3\u8868\u6bcf\u4e2a\u7ea7\u522b\u4e0a\u904d\u5386\u5230\u7684\u6700\u53f3\u4fa7\u7684\u503c\uff0c\u8868\u793a\u63d2\u5165\u6216\u5220\u9664\u7684\u8282\u70b9\u7684\u5de6\u4fa7\u76f4\u63a5\u76f4\u63a5\u6307\u5411\u5b83\u7684\u8282\u70b9\uff0c\u7528\u4e8e\u5728\u63d2\u5165\u6216\u5220\u9664\u540e\u8c03\u6574\u8282\u70b9\u6240\u5728\u6240\u6709\u7ea7\u522b\u7684\u524d\u5411\u6307\u9488\uff08\u4e0e\u6734\u7d20\u7684\u94fe\u8868\u8282\u70b9\u63d2\u5165\u6216\u5220\u9664\u7684\u8fc7\u7a0b\u76f8\u540c\uff09\u3002<\/p>\n<p><span style=\"color: #606c71\">\u5f53\u65b0\u63d2\u5165\u8282\u70b9\u7684\u7ea7\u522b\u8d85\u8fc7\u5f53\u524d\u8df3\u8dc3\u8868\u7684\u7ea7\u522b\u65f6\uff0c\u9700\u8981\u589e\u52a0\u8df3\u8dc3\u8868\u7684\u7ea7\u522b\u5e76\u5c06<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">update<\/span><\/span>\u5411\u91cf\u4e2d\u5bf9\u5e94\u7ea7\u522b\u7684\u8282\u70b9\u4fee\u6539\u4e3a<span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">head<\/span><\/span>\u8282\u70b9\u3002<\/p>\n<p><span style=\"color: #606c71\">Figure.7\u548cFigure.8\u5c55\u793a\u4e86\u5728\u8df3\u8dc3\u8868\u4e2d\u63d2\u5165\u5143\u7d2016\u7684\u8fc7\u7a0b\u3002\u9996\u5148\uff0c\u5728Figure.7\u4e2d\u6267\u884c\u4e0e\u641c\u7d22\u76f8\u540c\u7684\u67e5\u8be2\u8fc7\u7a0b\uff0c\u5728\u6bcf\u4e2a\u7ea7\u522b\u904d\u5386\u5230\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5728\u5bf9\u5e94\u5c42\u7ea7\u7684\u524d\u5411\u6307\u9488\u88ab\u6807\u8bb0\u4e3a\u7070\u8272\uff0c\u8868\u793a\u7a0d\u540e\u5c06\u4f1a\u5bf9\u9f50\u8fdb\u884c\u8c03\u6574\u3002\u63a5\u4e0b\u6765\u5728Figure.8\u4e2d\uff0c\u5728\u5143\u7d20\u4e3a13\u7684\u8282\u70b9\u540e\u63d2\u5165\u5143\u7d2016\uff0c\u5143\u7d2016\u5bf9\u5e94\u7684\u8282\u70b9\u7684\u7ea7\u522b\u662f5\uff0c\u8fd9\u6bd4\u8df3\u8dc3\u8868\u5f53\u524d\u7ea7\u522b\u8981\u9ad8\uff0c\u56e0\u6b64\u9700\u8981\u589e\u52a0\u8df3\u8dc3\u8868\u7684\u7ea7\u522b\u52305\uff0c\u5e76\u5c06<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">head<\/span><\/span>\u8282\u70b9\u5bf9\u5e94\u7ea7\u522b\u7684\u524d\u5411\u6307\u9488\u6807\u8bb0\u4e3a\u7070\u8272\u3002Figure.8\u4e2d\u6240\u6709\u865a\u7ebf\u90e8\u5206\u90fd\u8868\u793a\u8c03\u6574\u540e\u7684\u6548\u679c\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791363e341d912d03.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.7 Search path for inserting element 16<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791363e341d955da7.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.8 Insert element 16 and adjust forward pointers<\/span><\/p>\n<p>struct Node <span style=\"color: #d73a49\">*<\/span>SkipListInsert<span style=\"color: #997\">(<\/span>struct SkipList <span style=\"color: #d73a49\">*<\/span>list, SKIP_LIST_KEY_TYPE key, SKIP_LIST_VALUE_TYPE value<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span><span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>SKIP_LIST_MAX_LEVEL<span style=\"color: #997\">]<\/span>;<br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span>current;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;level;<\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>head;<br \/> &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">&#8211;<\/span> <span style=\"color: #005cc5\">1<\/span>; i <span style=\"color: #d73a49\">&gt;=<\/span> <span style=\"color: #005cc5\">0<\/span>; i<span style=\"color: #6a737d\">&#8211;) {<\/span><br \/> &nbsp; &nbsp;while <span style=\"color: #997\">(<\/span>current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">&amp;&amp;<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\"> target<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;current <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span>;<br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> current;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span><span style=\"color: #005cc5\">0<\/span><span style=\"color: #997\">]<\/span>;<br \/> &nbsp;if <span style=\"color: #997\">(<\/span>current<span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\">==<\/span> target<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;current<span style=\"color: #d73a49\">-&gt;<\/span>value <span style=\"color: #d73a49\">=<\/span> value;<br \/> &nbsp; &nbsp;return current;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;level <span style=\"color: #d73a49\">=<\/span> SkipListRandomLevel<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span>;<br \/> &nbsp;if <span style=\"color: #997\">(<\/span>level <span style=\"color: #d73a49\">&gt;<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>level<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>level; i <span style=\"color: #d73a49\"> level; i<span style=\"color: #d73a49\">++<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>header;<br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> CreateNode<span style=\"color: #997\">(<\/span>level<span style=\"color: #997\">)<\/span>;<br \/> &nbsp;current<span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\">=<\/span> key;<br \/> &nbsp;current<span style=\"color: #d73a49\">-&gt;<\/span>value <span style=\"color: #d73a49\">=<\/span> value;<\/p>\n<p> &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">0<\/span>; i <span style=\"color: #d73a49\"> level; i<span style=\"color: #d73a49\">++<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span>;<br \/> &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> current;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;return current;<br \/><span style=\"color: #997\">}<\/span><\/span><\/span><\/span><\/p>\n<p><span style=\"color: #606c71\">\u5728\u5220\u9664\u8282\u70b9\u540e\uff0c\u5982\u679c\u5220\u9664\u7684\u8282\u70b9\u662f\u8df3\u8dc3\u8868\u4e2d\u7ea7\u522b\u6700\u5927\u7684\u8282\u70b9\uff0c\u90a3\u4e48\u9700\u8981\u964d\u4f4e\u8df3\u8dc3\u8868\u7684\u7ea7\u522b\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">Figure.9\u548cFigure.10\u5c55\u793a\u4e86\u5728\u8df3\u8dc3\u8868\u4e2d\u5220\u9664\u5143\u7d2019\u7684\u8fc7\u7a0b\u3002\u9996\u5148\uff0c\u5728Figure.9\u4e2d\u6267\u884c\u4e0e\u641c\u7d22\u76f8\u540c\u7684\u67e5\u8be2\u8fc7\u7a0b\uff0c\u5728\u6bcf\u4e2a\u7ea7\u522b\u904d\u5386\u5230\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5728\u5bf9\u5e94\u5c42\u7ea7\u7684\u524d\u5411\u6307\u9488\u88ab\u6807\u8bb0\u4e3a\u7070\u8272\uff0c\u8868\u793a\u7a0d\u540e\u5c06\u4f1a\u5bf9\u9f50\u8fdb\u884c\u8c03\u6574\u3002\u63a5\u4e0b\u6765\u5728Figure.10\u4e2d\uff0c\u9996\u5148\u901a\u8fc7\u8c03\u6574\u524d\u5411\u6307\u9488\u5c06\u5143\u7d2019\u5bf9\u5e94\u7684\u8282\u70b9\u4ece\u8df3\u8dc3\u8868\u4e2d\u5378\u8f7d\uff0c\u56e0\u4e3a\u5143\u7d2019\u5bf9\u5e94\u7684\u8282\u70b9\u662f\u7ea7\u522b\u6700\u9ad8\u7684\u8282\u70b9\uff0c\u56e0\u6b64\u5c06\u5176\u4ece\u8df3\u8dc3\u8868\u4e2d\u79fb\u9664\u540e\u9700\u8981\u8c03\u6574\u8df3\u8dc3\u8868\u7684\u7ea7\u522b\u3002Figure.10\u4e2d\u6240\u6709\u865a\u7ebf\u90e8\u5206\u90fd\u8868\u793a\u8c03\u6574\u540e\u7684\u6548\u679c\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791363e341d993622.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.9 Search path for deleting element 19<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791363e341d9ce2d2.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.10 Delete element 19 and adjust forward pointers<\/span><\/p>\n<p>struct Node <span style=\"color: #d73a49\">*<\/span>SkipListDelete<span style=\"color: #997\">(<\/span>struct SkipList <span style=\"color: #d73a49\">*<\/span>list, SKIP_LIST_KEY_TYPE key<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span><span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>SKIP_LIST_MAX_LEVEL<span style=\"color: #997\">]<\/span>;<br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span>current;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i;<\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>head;<br \/> &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">&#8211;<\/span> <span style=\"color: #005cc5\">1<\/span>; i <span style=\"color: #d73a49\">&gt;=<\/span> <span style=\"color: #005cc5\">0<\/span>; i<span style=\"color: #6a737d\">&#8211;) {<\/span><br \/> &nbsp; &nbsp;while <span style=\"color: #997\">(<\/span>current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">&amp;&amp;<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\"> key<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;current <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span>;<br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> current;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span><span style=\"color: #005cc5\">0<\/span><span style=\"color: #997\">]<\/span>;<br \/> &nbsp;if <span style=\"color: #997\">(<\/span>current <span style=\"color: #d73a49\">&amp;&amp;<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\">==<\/span> key<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">0<\/span>; i <span style=\"color: #d73a49\"> list<span style=\"color: #d73a49\">-&gt;<\/span>level; i<span style=\"color: #d73a49\">++<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;if <span style=\"color: #997\">(<\/span><span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">==<\/span> current<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span>;<br \/> &nbsp; &nbsp; &nbsp;<span style=\"color: #997\">}<\/span> else <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp; &nbsp;break;<br \/> &nbsp; &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp; &nbsp;while <span style=\"color: #997\">(<\/span>list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">&gt;<\/span> <span style=\"color: #005cc5\">1<\/span> <span style=\"color: #d73a49\">&amp;&amp;<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>head<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">&#8211;<\/span> <span style=\"color: #005cc5\">1<\/span><span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">==<\/span> <span style=\"color: #905\">NULL<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;list<span style=\"color: #d73a49\">-&gt;<\/span>level<span style=\"color: #6a737d\">&#8211;;<\/span><br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;return current;<br \/><span style=\"color: #997\">}<\/span><\/span><\/span><\/p>\n<h2>\u751f\u6210\u968f\u673a\u7ea7\u522b<\/h2>\n<\/p>\n<p><span style=\"color: #606c71\">\u5728\u524d\u9762\u63d0\u5230\u8fc7\uff0c<em>\u968f\u673a\u9009\u62e9\u8282\u70b9\u7684\u7ea7\u522b\u7684\u6982\u7387\u5206\u5e03\u9075\u5faa\u6982\u7387\u4e3a12\u7684\u6307\u6570\u5206\u5e03<\/em>\uff0c\u4e5f\u5c31\u662f\u8bf4\u7b2ci+1\u5c42\u7684\u8282\u70b9\u6570\u91cf\u662f\u7b2ci\u5c42\u7684\u4e00\u534a\u3002\u4e3a\u4e86\u907f\u514d\u4f7f\u7528\u9b54\u6cd5\u503c\uff0c\u5b9a\u4e49\u4e00\u4e2a\u5206\u6570p\u4ee3\u8868\u8282\u70b9\u540c\u65f6\u5e26\u6709\u7b2ci\u5c42\u524d\u5411\u6307\u9488\u548c\u7b2ci+1\u5c42\u524d\u5411\u6307\u9488\u7684\u6982\u7387\uff08\u5728\u4e4b\u524d\u7684\u8ba8\u8bba\u4e2d\uff0cp=12\uff09\u3002\u8282\u70b9\u7684\u7ea7\u522b\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u65b9\u6cd5\u968f\u673a\u751f\u6210\uff0c\u5728\u8fd9\u4e2a\u7b97\u6cd5\u4e2d\u8282\u70b9\u7684\u7ea7\u522b\u53ef\u4ee5\u5728\u4e0d\u4f9d\u8d56\u8df3\u8dc3\u8868\u5143\u7d20\u6570\u91cf\u7684\u524d\u63d0\u4e0b\u751f\u6210<\/span><\/p>\n<p><span style=\"color: #22863a\">int<\/span> SkipListRandomLevel<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> level;<br \/> &nbsp;level <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">1<\/span>;<br \/> &nbsp;while <span style=\"color: #997\">(<\/span>random<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\"> RAND_MAX <span style=\"color: #d73a49\">*<\/span> SKIP_LIST_P <span style=\"color: #d73a49\">&amp;&amp;<\/span> level <span style=\"color: #d73a49\"> SKIP_LIST_MAX_LEVEL<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;level<span style=\"color: #d73a49\">++<\/span>;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp;return level;<br \/><span style=\"color: #997\">}<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #606c71\">\u4ee5\u4e0b\u8868\u683c\u4e3a\u6309\u4e0a\u9762\u7b97\u6cd5\u6267\u884c232\u6b21\u540e\uff0c\u6240\u751f\u6210\u7684\u968f\u673a\u7ea7\u522b\u7684\u5206\u5e03\u60c5\u51b5\u3002<\/span><\/p>\n<table style=\"width: 100%;border-collapse: collapse\">\n<tbody>\n<tr>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>1<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>2<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>3<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>4<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>5<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>6<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>7<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>8<\/strong><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">2147540777<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">1073690199<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">536842769<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">268443025<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">134218607<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">67116853<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">33563644<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">16774262<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>9<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>10<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>11<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>12<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>13<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>14<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>15<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>16<\/strong><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">8387857<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">4193114<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">2098160<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">1049903<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">523316<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">262056<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">131455<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">65943<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>17<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>18<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>19<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>20<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>21<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>22<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>23<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>24<\/strong><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">32611<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">16396<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">8227<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">4053<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">2046<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">1036<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">492<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">249<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>25<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>26<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>27<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>28<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>29<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>30<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>31<\/strong><\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\"><strong>32<\/strong><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">121<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">55<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">34<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">16<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">7<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">9<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">2<\/span><\/p>\n<\/td>\n<td style=\"vertical-align: top;line-height: 2;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p><span style=\"color: #606c71\">1<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>MaxLevel\u7684\u9009\u62e9<\/h2>\n<p><span style=\"color: #606c71\">\u5728Figure.4\u4e2d\u66fe\u7ed9\u51fa\u8fc7\u5bf9\u4e8e10\u4e2a\u5143\u7d20\u7684\u8df3\u8dc3\u8868\u6700\u7406\u60f3\u7684\u5206\u5e03\u60c5\u51b5\uff0c\u5176\u4e2d5\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\u662f1\uff0c3\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\u662f2\uff0c1\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\u662f3\uff0c1\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\u662f4\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u8fd9\u5f15\u7533\u51fa\u4e00\u4e2a\u95ee\u9898\uff1a<em>\u65e2\u7136\u76f8\u540c\u5143\u7d20\u6570\u91cf\u4e0b\uff0c\u8df3\u8dc3\u8868\u7684\u7ea7\u522b\u4e0d\u540c\u4f1a\u6709\u4e0d\u540c\u7684\u6027\u80fd\uff0c\u90a3\u4e48\u8df3\u8dc3\u8868\u7684\u7ea7\u522b\u4e3a\u591a\u5c11\u624d\u5408\u9002\uff1f<\/em><\/span><\/p>\n<p><span style=\"color: #606c71\">\u7ecf\u8fc7\u5206\u6790\u5f97\u51fa\uff0c\u8df3\u8dc3\u8868\u5728\u7ea7\u522bL\u4e0a\u671f\u671b\u7684\u8282\u70b9\u6570\u91cf\u662f1p\uff0c\u5f53L=log1pn\u65f6\u8fd9\u662f\u6210\u7acb\u7684[1]\u3002\u5728\u6b64\u53ef\u4ee5\u5b9a\u4e49L(n)\u6765\u4ee3\u8868log1pn\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u7531\u4e8e\u7ea7\u522b\u53ef\u4ee5\u5b89\u5168\u5730\u9650\u5b9a\u5728L(n)\uff0c\u53ef\u4ee5\u9009\u62e9MaxLevel=L(N)\uff08N\u662f\u8df3\u8dc3\u8868\u4e2d\u5143\u7d20\u6570\u91cf\u7684\u4e0a\u9650\uff09\u3002\u5982\u679cp=12\uff0c\u90a3\u4e48MaxLevel=32\u5c31\u53ef\u4ee5\u5b89\u5168\u5730\u5305\u542b\u6700\u591a232\u4e2a\u5143\u7d20\u3002<\/span><\/p>\n<h2>\u5206\u6790<\/h2>\n<h2>\u7a7a\u95f4\u590d\u6742\u5ea6\u5206\u6790<\/h2>\n<p><span style=\"color: #606c71\">\u524d\u9762\u63d0\u5230\u8fc7\uff0c<em>\u5206\u6570p\u4ee3\u8868\u8282\u70b9\u540c\u65f6\u5e26\u6709\u7b2ci\u5c42\u524d\u5411\u6307\u9488\u548c\u7b2ci+1\u5c42\u524d\u5411\u6307\u9488\u7684\u6982\u7387<\/em>\uff0c\u800c\u6bcf\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\u6700\u5c11\u662f1\uff0c\u56e0\u6b64\u7ea7\u522b\u4e3ai\u7684\u524d\u5411\u6307\u9488\u6570\u4e3anpi\u22121\u3002\u5b9a\u4e49S(n)\u8868\u793a\u6240\u6709\u524d\u5411\u6307\u9488\u7684\u603b\u91cf\uff0c\u7531\u7b49\u6bd4\u6570\u5217\u6c42\u548c\u516c\u5f0f\u53ef\u5f97<\/span><\/p>\n<p><span style=\"color: #606c71\">S(n)=n\u2217(1+p+p2+&#8230;+pL(n)\u22121)=n\u22171\u2212pL(n)\u221211\u2212p=n\u22171\u2212plog1pn\u221211\u2212p<\/span><\/p>\n<p><span style=\"color: #606c71\">\u5bf9S(n)\u6c42\u6781\u9650\uff0c\u6709<\/span><\/p>\n<p><span style=\"color: #606c71\">limn\u2192+\u221eS(n)=n\u221711\u2212p=n1\u2212p<\/span><\/p>\n<p><span style=\"color: #606c71\">\u6613\u8bc1\uff0c\u8fd9\u662f\u4e00\u4e2a\u5173\u4e8ep\u7684\u5355\u8c03\u9012\u589e\u51fd\u6570\uff0c\u56e0\u6b64p\u7684\u503c\u8d8a\u5927\uff0c\u8df3\u8dc3\u8868\u4e2d\u524d\u5411\u6307\u9488\u7684\u603b\u6570\u8d8a\u591a\u3002\u56e0\u4e3a1\u2212p\u662f\u5df2\u77e5\u7684\u5e38\u6570\uff0c\u6240\u4ee5\u8bf4\u8df3\u8dc3\u8868\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u662fO(n)\u3002<\/span><\/p>\n<h2>\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790<\/h2>\n<h2>\u975e\u5f62\u5f0f\u5316\u5206\u6790<\/h2>\n<p><span style=\"color: #606c71\">\u5ef6\u7eed\u524d\u9762\u7684\u5b9a\u4e49\uff0c<em>\u5206\u6570p\u4ee3\u8868\u8282\u70b9\u540c\u65f6\u5e26\u6709\u7b2ci\u5c42\u524d\u5411\u6307\u9488\u548c\u7b2ci+1\u5c42\u524d\u5411\u6307\u9488\u7684\u6982\u7387<\/em>\uff0c\u4e5f\u5c31\u662f\u8bf4\u76f8\u90bb\u4e24\u4e2a\u7ea7\u522b\u4e3ai+k(k&gt;0)\u7684\u8282\u70b9\u4e2d\u95f4\u671f\u671b\u67091p\u22121\u4e2a\u7ea7\u522b\u4e3ai\u7684\u8282\u70b9\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u800c\u901a\u8fc7\u8003\u67e5Figure.6\u641c\u7d22\u8def\u5f84\uff0c\u4e0d\u96be\u53d1\u73b0\uff0c\u5728\u7ea7\u522bi\u7684\u641c\u7d22\u6c38\u8fdc\u4e0d\u4f1a\u89e6\u8fbe\u7ea7\u522b\u5927\u4e8ei\u7684\u8282\u70b9\uff08\u56e0\u4e3a\u7ea7\u522b\u5927\u4e8ei\u7684\u8282\u70b9\u5df2\u7ecf\u5728\u7ea7\u522bi+k(k&gt;0)\u7684\u641c\u7d22\u4e2d\u88ab\u5426\u51b3\uff09\uff0c\u56e0\u6b64\u53ef\u4ee5\u8ba4\u4e3a\u5728\u7406\u60f3\u60c5\u51b5\u4e0b\u6bcf\u4e00\u5c42\u6700\u591a\u53ea\u9700\u8981\u8bbf\u95ee1p\u4e2a\u8282\u70b9\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u7531\u641c\u7d22\u662f\u901a\u8fc7Z\u5b57\u5f62\u904d\u5386\u6240\u6709\u6ca1\u6709\u8d85\u8fc7\u8981\u5bfb\u627e\u7684\u76ee\u6807\u5143\u7d20\u7684\u524d\u5411\u6307\u9488\u6765\u5b8c\u6210\u7684\uff0c\u56e0\u6b64\u641c\u7d22\u603b\u662f\u9700\u8981\u7ecf\u8fc7L(n)\u5c42\u3002\u6240\u4ee5\u671f\u671b\u7684\u8bbf\u95ee\u6b21\u6570\u662f1pL(n)\uff0c\u56e0\u4e3aL(n)=log1pn\uff0c\u6240\u4ee5\u671f\u671b\u7684\u8bbf\u95ee\u6b21\u6570\u662f1plog1pn\uff0c\u56e0\u4e3a1\/p\u662f\u53ef\u4ee5\u786e\u5b9a\u7684\u5e38\u6570\uff0c\u56e0\u6b64\u8df3\u8dc3\u8868\u7684\u641c\u7d22\u3001\u63d2\u5165\u548c\u5220\u9664\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u662fO(logn)<\/span><\/p>\n<h2>\u5f62\u5f0f\u5316\u5206\u6790<\/h2>\n<p><span style=\"color: #606c71\">\u5b9a\u4e491. $=<em>{prob} and le<\/em>{prob}<em>\uff1a<\/em>\u5b9a\u4e49\uff1a\u5b9a\u4e49X\u548c\u548cY\u662f\u4e24\u4e2a\u975e\u8d1f\u7684\u65e0\u5173\u7684\u968f\u673a\u53d8\u91cf<em>\uff08<\/em>\u901a\u5e38\u6765\u8bf4<em>\uff0c<\/em>\u662f\u4e24\u4e2a\u975e\u8d1f\u7684\u65e0\u5173\u7684\u968f\u673a\u53d8\u91cf\uff08\u901a\u5e38\u6765\u8bf4\uff0cX\u548c\u548cY\u8868\u793a\u7b97\u6cd5\u8868\u793a\u7b97\u6cd5A_X\u548c\u548cA_Y\u7684\u6267\u884c\u65f6\u95f4<em>\uff09<\/em>\u3002\u5b9a\u4e49\u7684\u6267\u884c\u65f6\u95f4\uff09\u3002\u5b9a\u4e49Xle_{prob}Y\u5f53\u4e14\u4ec5\u5f53\u5bf9\u4e8e\u4efb\u610f\u5f53\u4e14\u4ec5\u5f53\u5bf9\u4e8e\u4efb\u610ft<em>\uff0c<\/em>\uff0ct\u5728\u5728X\u4e2d\u51fa\u73b0\u7684\u6982\u7387\u603b\u662f\u5c0f\u4e8e\u4e2d\u51fa\u73b0\u7684\u6982\u7387\u603b\u662f\u5c0f\u4e8et\u5728\u5728Y$\u4e2d\u51fa\u73b0\u7684\u6982\u7387\u65f6\u4e3a\u771f\u3002\u66f4\u52a0\u5f62\u5f0f\u5316\u7684\u5b9a\u4e49<\/span><\/p>\n<p><span style=\"color: #606c71\">X=probY if \u2200t,Prob{X&gt;t}=Prob{Y&gt;t}<\/span><\/p>\n<p><span style=\"color: #606c71\">X\u2264probYif\u2200t,Prob{X&gt;t}\u2264Prob{Y&gt;t}<\/span><\/p>\n<p><span style=\"color: #606c71\">\u5b9a\u4e492. \u8d1f\u4e8c\u9879\u5206\u5e03\uff08NB(s,p)\uff09[7]\uff09\uff1a\u5b9a\u4e49s\u4e3a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u5e76\u4e14p\u662f\u6982\u7387\u3002NB(s,p)\u8868\u793a\u4e00\u4e2a\u5728\u6210\u529f\u6982\u7387\u4e3ap\u7684\u60c5\u51b5\u4e0b\uff0c\u91cd\u590d\u6267\u884c\u968f\u673a\u72ec\u7acb\u8bd5\u9a8c\u5728\u7b2cs\u6b21\u6210\u529f\u524d\u7684\u5931\u8d25\u6b21\u6570\u7684\u968f\u673a\u53d8\u91cf\u3002NB(s,p)\u7684\u6570\u5b66\u671f\u671b\u662fs(1\u2212p)\/p\uff0c\u800c\u65b9\u5dee\u662fs(1\u2212p)\/p2\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u5ef6\u7eed<em>\u5206\u6570p\u4ee3\u8868\u8282\u70b9\u540c\u65f6\u5e26\u6709\u7b2ci\u5c42\u524d\u5411\u6307\u9488\u548c\u7b2ci+1\u5c42\u524d\u5411\u6307\u9488\u7684\u6982\u7387<\/em>\u7684\u5b9a\u4e49\uff0c\u8003\u8651\u53cd\u65b9\u5411\u5206\u6790\u641c\u7d22\u8def\u5f84\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u641c\u7d22\u7684\u8def\u5f84\u603b\u662f\u5c0f\u4e8e\u5fc5\u987b\u6267\u884c\u7684\u6bd4\u8f83\u7684\u6b21\u6570\u7684\u3002\u9996\u5148\u9700\u8981\u8003\u67e5\u4ece\u7ea7\u522b1\uff08\u5728\u641c\u7d22\u5230\u5143\u7d20\u524d\u904d\u5386\u7684\u6700\u540e\u4e00\u4e2a\u8282\u70b9\uff09\u722c\u5347\u5230\u7ea7\u522bL(n)\u6240\u9700\u8981\u53cd\u5411\u8ddf\u8e2a\u7684\u6307\u9488\u6570\u91cf\u3002\u867d\u7136\u5728\u641c\u7d22\u65f6\u53ef\u4ee5\u786e\u5b9a\u6bcf\u4e2a\u8282\u70b9\u7684\u7ea7\u522b\u90fd\u662f\u5df2\u77e5\u4e14\u786e\u5b9a\u7684\uff0c\u5728\u8fd9\u91cc\u4ecd\u8ba4\u4e3a\u53ea\u6709\u5f53\u6574\u4e2a\u641c\u7d22\u8def\u5f84\u90fd\u88ab\u53cd\u5411\u8ffd\u8e2a\u540e\u624d\u80fd\u88ab\u786e\u5b9a\uff0c\u5e76\u4e14\u5728\u722c\u5347\u5230\u7ea7\u522bL(n)\u4e4b\u524d\u90fd\u4e0d\u4f1a\u63a5\u89e6\u5230<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">head<\/span><\/span>\u8282\u70b9\u3002<\/p>\n<p><span style=\"color: #606c71\">\u5728\u722c\u5347\u8fc7\u7a0b\u4e2d\u4efb\u4f55\u7279\u5b9a\u7684\u70b9\uff0c\u90fd\u8ba4\u4e3a\u662f\u5728\u5143\u7d20x\u7684\u7b2ci\u4e2a\u524d\u5411\u6307\u9488\uff0c\u5e76\u4e14\u4e0d\u77e5\u9053\u5143\u7d20x\u5de6\u4fa7\u6240\u6709\u5143\u7d20\u7684\u7ea7\u522b\u6216\u5143\u7d20x\u7684\u7ea7\u522b\uff0c\u4f46\u662f\u53ef\u4ee5\u77e5\u9053\u5143\u7d20x\u7684\u7ea7\u522b\u81f3\u5c11\u662fi\u3002\u5143\u7d20x\u7684\u7ea7\u522b\u5927\u4e8ei\u7684\u6982\u7387\u662fp\uff0c\u53ef\u4ee5\u901a\u8fc7\u8003\u8651\u89c6\u8ba4\u4e3a\u8fd9\u4e2a\u53cd\u5411\u722c\u5347\u7684\u8fc7\u7a0b\u662f\u4e00\u7cfb\u5217\u7531\u6210\u529f\u7684\u722c\u5347\u5230\u66f4\u9ad8\u7ea7\u522b\u6216\u5931\u8d25\u5730\u5411\u5de6\u79fb\u52a8\u7684\u968f\u673a\u72ec\u7acb\u5b9e\u9a8c\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u5728\u722c\u5347\u5230\u7ea7\u522bL(n)\u8fc7\u7a0b\u4e2d\uff0c\u5411\u5de6\u79fb\u52a8\u7684\u6b21\u6570\u7b49\u4e8e\u5728\u8fde\u7eed\u968f\u673a\u8bd5\u9a8c\u4e2d\u7b2cL(n)\u22121\u6b21\u6210\u529f\u524d\u7684\u5931\u8d25\u7684\u6b21\u6570\uff0c\u8fd9\u7b26\u5408\u8d1f\u4e8c\u9879\u5206\u5e03\u3002\u671f\u671b\u7684\u5411\u4e0a\u79fb\u52a8\u6b21\u6570\u4e00\u5b9a\u662fL(n)\u22121\u3002\u56e0\u6b64\u53ef\u4ee5\u5f97\u5230\u65e0\u9650\u5217\u8868\u4e2d\u722c\u5347\u5230L(n)\u7684\u4ee3\u4ef7C C=prob(L(n)\u22121)+NB(L(n)\u22121,p) \u5217\u8868\u957f\u5ea6\u65e0\u9650\u5927\u662f\u4e00\u4e2a\u60b2\u89c2\u7684\u5047\u8bbe\u3002\u5f53\u53cd\u5411\u722c\u5347\u7684\u8fc7\u7a0b\u4e2d\u63a5\u89e6\u5230<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">head<\/span><\/span>\u8282\u70b9\u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u5411\u4e0a\u722c\u5347\u800c\u4e0d\u9700\u8981\u4efb\u4f55\u5411\u5de6\u79fb\u52a8\u3002\u56e0\u6b64\u53ef\u4ee5\u5f97\u5230n\u4e2a\u5143\u7d20\u5217\u8868\u4e2d\u722c\u5347\u5230L(n)\u7684\u4ee3\u4ef7C(n)<\/p>\n<p>C(n)\u2264probC=prob(L(n)\u22121)+NB(L(n)\u22121,p)<\/p>\n<p>\u56e0\u6b64n\u4e2a\u5143\u7d20\u5217\u8868\u4e2d\u722c\u5347\u5230L(n)\u7684\u4ee3\u4ef7C(n)\u7684\u6570\u5b66\u671f\u671b\u548c\u65b9\u5dee\u4e3a<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791463e341da15646.png\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">\u56e0\u4e3a1\/p\u662f\u5df2\u77e5\u5e38\u6570\uff0c\u56e0\u6b64\u8df3\u8dc3\u8868\u7684\u641c\u7d22\u3001\u63d2\u5165\u548c\u5220\u9664\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u662fO(logn)\u3002<\/span><\/p>\n<h2>P\u7684\u9009\u62e9<\/h2>\n<p><span style=\"color: #606c71\">\u5f97\u5230\u641c\u7d22\u4ee3\u4ef7\u4e3aE(C(n))<\/span><\/p>\n<p><span style=\"color: #606c71\">E(C(n))<\/span><\/p>\n<p><span style=\"color: #606c71\">\u4e0d\u96be\u770b\u51fa\uff0c\u5bf9\u4e8e\u4efb\u610f\u786e\u5b9a\u7684n\uff0cln(n)\u90fd\u662f\u786e\u5b9a\u7684\uff0c\u56e0\u6b64\u53ea\u9700\u8981\u5206\u67901pln(1p)\u7684\u53d8\u5316\u8d8b\u52bf\u5c31\u53ef\u4ee5\u3002\u4e3a\u4e86\u66f4\u597d\u7684\u8fdb\u884c\u5bf9\u6bd4\uff0c\u4ee5p=12\u4e3a\u57fa\u7840\u503c\u8fdb\u884c\u6807\u51c6\u5316\uff0cFigure.11\u5c31\u662f\u968f\u7740p\u7684\u53d8\u5316\uff0c\u641c\u7d22\u65f6\u95f4\u7684\u53d8\u5316\u8d8b\u52bf\uff0c\u5176\u4e2dp=1e\u7684\u70b9\u662f\u641c\u7d22\u65f6\u95f4\u6700\u597d\u7684\u70b9\uff0c\u4f46\u662f\u4e8c\u7684\u6574\u6570\u6b21\u5e42\u53ef\u4ee5\u66f4\u597d\u5730\u8fdb\u884c\u968f\u673a\u7ea7\u522b\u7684\u751f\u6210\u3002<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230208\/167583791463e341da5438f.jpg\" style=\"max-width:100%\" class=\"aligncenter\"> <\/p>\n<p><span style=\"color: #606c71\">Figure.11 Normalized search times<\/span><\/p>\n<p><span style=\"color: #606c71\">\u800c\u524d\u9762\u5206\u6790\u7a7a\u95f4\u590d\u6742\u5ea6\u65f6\u4e5f\u786e\u5b9a\u4e86n1\u2212p\uff0c\u7a7a\u95f4\u7528\u91cf\u968f\u7740p\u51cf\u5c0f\u800c\u964d\u4f4e\uff0c\u56e0\u6b64p=14\u662f\u4f18\u4e8ep=12\u7684\uff0c\u8fd9\u4e5f\u662fRedis\u4e2d\u4f7f\u7528p=0.25\u800c\u4e0d\u662fp=0.5\u7684\u4e00\u4e2a\u539f\u56e0\u3002<\/span><\/p>\n<h2>\u6269\u5c55<\/h2>\n<h2>\u5feb\u901f\u968f\u673a\u8bbf\u95ee<\/h2>\n<p><span style=\"color: #606c71\">\u5728\u8df3\u8dc3\u8868\u4e2d\u901a\u8fc7\u524d\u5411\u5f15\u7528\u5b9e\u73b0\u4e86O(log1pn)\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u641c\u7d22\u3001\u63d2\u5165\u4e0e\u5220\u9664\u7b97\u6cd5\uff0c\u4f46\u662f\u5bf9\u4e8e\u968f\u673a\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7b2ci\u4e2a\u5143\u7d20\u64cd\u4f5c\u4ecd\u9700\u8981O(i)\u65f6\u95f4\u3002\u901a\u8fc7\u89c2\u5bdfFigure.7\u4e2d\u7684Z\u5b57\u5f62\u641c\u7d22\u8def\u5f84\uff0c\u4e0d\u96be\u53d1\u73b0\uff0c\u4ece\u5934\u8282\u70b9\u5230\u67d0\u4e2a\u8282\u70b9\u7684\u8def\u5f84\u4e2d\u6240\u6709\u524d\u5411\u6307\u9488\u7684\u8de8\u5ea6\u7684\u548c\uff0c\u5c31\u662f\u8fd9\u4e2a\u8282\u70b9\u5728\u8df3\u8dc3\u8868\u4e2d\u7684\u4f4d\u7f6e\u3002\u90a3\u4e48\u901a\u8fc7\u5728\u524d\u5411\u6307\u9488\u4e2d\u7ef4\u62a4\u5f53\u524d\u8282\u70b9\u5230\u76ee\u6807\u8282\u70b9\u7684\u8de8\u5ea6\uff0c\u5c31\u53ef\u4ee5\u4fdd\u8bc1\u968f\u673a\u8bbf\u95ee\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u662fO(log1pn)\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u9996\u5148\uff0c\u9700\u8981\u5bf9\u6570\u636e\u7ed3\u6784\u91cd\u65b0\u8fdb\u884c\u5b9a\u4e49\uff0c\u5728\u524d\u5411\u6307\u9488\u4e2d\u589e\u52a0\u8de8\u5ea6\u76f8\u5173\u7684\u8bb0\u5f55\uff0c\u5e76\u5c06\u5176\u521d\u59cb\u8bbe\u7f6e\u4e3a0\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u8ba4\u4e3a<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">NULL<\/span><\/span>\u5728\u8df3\u8dc3\u8868\u4e2d\u7684\u4f4d\u7f6e\u6c38\u8fdc\u662f\u8df3\u8dc3\u8868\u7684\u957f\u5ea6\uff08\u4ece<span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">0<\/span><\/span>\u5f00\u59cb\uff09\uff0c\u56e0\u6b64\u9700\u8981\u5728\u8df3\u8dc3\u8868\u4e2d\u8bb0\u5f55\u603b\u957f\u5ea6\u3002<\/p>\n<p><span style=\"color: #606c71\">\u672c\u8282\u4e2d\u7684\u4ee3\u7801\u53c2\u8003\u81eaRedis\u7684\u8df3\u8dc3\u8868\u5b9e\u73b0[8], \u4e3a\u4e86\u4e0e\u524d\u9762\u7684\u4ee3\u7801\u98ce\u683c\u4fdd\u6301\u4e00\u81f4\uff0c\u8fdb\u884c\u4e86\u9002\u5f53\u7684\u4fee\u6539<\/span><\/p>\n<p>#define SKIP_LIST_KEY_TYPE &nbsp; &nbsp; <span style=\"color: #22863a\">int<\/span><br \/>#define SKIP_LIST_VALUE_TYPE &nbsp; <span style=\"color: #22863a\">int<\/span><br \/>#define SKIP_LIST_MAX_LEVEL &nbsp; &nbsp;<span style=\"color: #005cc5\">32<\/span><br \/>#define SKIP_LIST_P &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #005cc5\">0.5<\/span><\/p>\n<p>struct Node; <span style=\"color: #d73a49\">\/\/<\/span> forward definition<\/p>\n<p>struct Forward <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span>forward;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;span;<br \/><span style=\"color: #997\">}<\/span><\/p>\n<p>struct Node <span style=\"color: #997\">{<\/span><br \/> &nbsp;SKIP_LIST_KEY_TYPE &nbsp; &nbsp;key;<br \/> &nbsp;SKIP_LIST_VALUE_TYPE &nbsp;value;<br \/> &nbsp;struct Forward &nbsp; &nbsp; &nbsp; &nbsp;forwards<span style=\"color: #997\">[<\/span><span style=\"color: #997\">]<\/span>; <span style=\"color: #d73a49\">\/\/<\/span> flexible array member<br \/><span style=\"color: #997\">}<\/span>;<\/p>\n<p>struct SkipList <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span>head;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;level;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;length;<br \/><span style=\"color: #997\">}<\/span>;<\/p>\n<p>struct Node <span style=\"color: #d73a49\">*<\/span>CreateNode<span style=\"color: #997\">(<\/span><span style=\"color: #22863a\">int<\/span> level<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span>node;<br \/> &nbsp;assert<span style=\"color: #997\">(<\/span>level <span style=\"color: #d73a49\">&gt;<\/span> <span style=\"color: #005cc5\">0<\/span><span style=\"color: #997\">)<\/span>;<br \/> &nbsp;node <span style=\"color: #d73a49\">=<\/span> malloc<span style=\"color: #997\">(<\/span>sizeof<span style=\"color: #997\">(<\/span>struct Node<span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\">+<\/span> sizeof<span style=\"color: #997\">(<\/span>struct Forward<span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\">*<\/span> level<span style=\"color: #997\">)<\/span>;<br \/> &nbsp;return node;<br \/><span style=\"color: #997\">}<\/span><\/p>\n<p>struct SkipList <span style=\"color: #d73a49\">*<\/span>CreateSkipList<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct SkipList <span style=\"color: #d73a49\">*<\/span>list;<br \/> &nbsp;struct Node &nbsp; &nbsp; <span style=\"color: #d73a49\">*<\/span>head;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i;<\/p>\n<p> &nbsp;list <span style=\"color: #d73a49\">=<\/span> malloc<span style=\"color: #997\">(<\/span>sizeof<span style=\"color: #997\">(<\/span>struct SkipList<span style=\"color: #997\">)<\/span><span style=\"color: #997\">)<\/span>;<br \/> &nbsp;head <span style=\"color: #d73a49\">=<\/span> CreateNode<span style=\"color: #997\">(<\/span>SKIP_LIST_MAX_LEVEL<span style=\"color: #997\">)<\/span>;<br \/> &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">0<\/span>; i <span style=\"color: #d73a49\"> SKIP_LIST_MAX_LEVEL; i<span style=\"color: #d73a49\">++<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;head<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #905\">NULL<\/span>;<br \/> &nbsp; &nbsp;head<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.span<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">0<\/span>;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;list<span style=\"color: #d73a49\">-&gt;<\/span>head <span style=\"color: #d73a49\">=<\/span> head;<br \/> &nbsp;list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">1<\/span>;<\/p>\n<p> &nbsp;return list;<br \/><span style=\"color: #997\">}<\/span><\/span><\/p>\n<p><span style=\"color: #606c71\">\u63a5\u4e0b\u6765\u9700\u8981\u4fee\u6539\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\uff0c\u6765\u4fdd\u8bc1\u5728\u8df3\u8dc3\u8868\u4fee\u6539\u540e\u8de8\u5ea6\u7684\u6570\u636e\u5b8c\u6574\u6027\u3002<\/span><\/p>\n<p><span style=\"color: #606c71\">\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u63d2\u5165\u8fc7\u7a0b\u4e2d\u9700\u8981\u4f7f\u7528<\/span><span style=\"color: #567482\"><span style=\"background-color: #f3f6fa\">indices<\/span><\/span>\u8bb0\u5f55\u5728\u6bcf\u4e2a\u5c42\u7ea7\u904d\u5386\u5230\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4f4d\u7f6e\uff0c\u8fd9\u6837\u901a\u8fc7\u505a\u7b80\u5355\u7684\u51cf\u6cd5\u64cd\u4f5c\u5c31\u53ef\u4ee5\u77e5\u9053\u6bcf\u4e2a\u5c42\u7ea7\u904d\u5386\u5230\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5230\u65b0\u63d2\u5165\u8282\u70b9\u7684\u8de8\u5ea6\u3002<\/p>\n<p>struct Node <span style=\"color: #d73a49\">*<\/span>SkipListInsert<span style=\"color: #997\">(<\/span>struct SkipList <span style=\"color: #d73a49\">*<\/span>list, SKIP_LIST_KEY_TYPE key, SKIP_LIST_VALUE_TYPE value<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span><span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>SKIP_LIST_MAX_LEVEL<span style=\"color: #997\">]<\/span>;<br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span>current;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;indices<span style=\"color: #997\">[<\/span>SKIP_LIST_MAX_LEVEL<span style=\"color: #997\">]<\/span>;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;level;<\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>head;<br \/> &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">&#8211;<\/span> <span style=\"color: #005cc5\">1<\/span>; i <span style=\"color: #d73a49\">&gt;=<\/span> <span style=\"color: #005cc5\">0<\/span>; i<span style=\"color: #6a737d\">&#8211;) {<\/span><br \/> &nbsp; &nbsp;if <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">==<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">&#8211;<\/span> <span style=\"color: #005cc5\">1<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;indices<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">0<\/span>;<br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span> else <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;indices<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> indices<span style=\"color: #997\">[<\/span>i <span style=\"color: #d73a49\">+<\/span> <span style=\"color: #005cc5\">1<\/span><span style=\"color: #997\">]<\/span>;<br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp; &nbsp;<br \/> &nbsp; &nbsp;while <span style=\"color: #997\">(<\/span>current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span> <span style=\"color: #d73a49\">&amp;&amp;<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span><span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\"> target<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;indices<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">+=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.span<\/span>;<br \/> &nbsp; &nbsp; &nbsp;current <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span>;<br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> current;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span><span style=\"color: #005cc5\">0<\/span><span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span>;<br \/> &nbsp;if <span style=\"color: #997\">(<\/span>current<span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\">==<\/span> target<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;current<span style=\"color: #d73a49\">-&gt;<\/span>value <span style=\"color: #d73a49\">=<\/span> value;<br \/> &nbsp; &nbsp;return current;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;level <span style=\"color: #d73a49\">=<\/span> SkipListRandomLevel<span style=\"color: #997\">(<\/span><span style=\"color: #997\">)<\/span>;<br \/> &nbsp;if <span style=\"color: #997\">(<\/span>level <span style=\"color: #d73a49\">&gt;<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>level<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>level; i <span style=\"color: #d73a49\"> level; i<span style=\"color: #d73a49\">++<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;indices<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">0<\/span>;<br \/> &nbsp; &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>header;<br \/> &nbsp; &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.span<\/span> <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>length;<br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> CreateNode<span style=\"color: #997\">(<\/span>level<span style=\"color: #997\">)<\/span>;<br \/> &nbsp;current<span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\">=<\/span> key;<br \/> &nbsp;current<span style=\"color: #d73a49\">-&gt;<\/span>value <span style=\"color: #d73a49\">=<\/span> value;<\/p>\n<p> &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">0<\/span>; i <span style=\"color: #d73a49\"> level; i<span style=\"color: #d73a49\">++<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span>;<br \/> &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span> <span style=\"color: #d73a49\">=<\/span> current;<br \/> &nbsp; &nbsp;current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.span<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.span<\/span> <span style=\"color: #d73a49\">&#8211;<\/span> <span style=\"color: #997\">(<\/span>indices<span style=\"color: #997\">[<\/span><span style=\"color: #005cc5\">0<\/span><span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">&#8211;<\/span> indices<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #997\">)<\/span>;<br \/> &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.span<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #997\">(<\/span>indices<span style=\"color: #997\">[<\/span><span style=\"color: #005cc5\">0<\/span><span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">&#8211;<\/span> indices<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #d73a49\">+<\/span> <span style=\"color: #005cc5\">1<\/span>;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;list<span style=\"color: #005cc5\">.length<\/span><span style=\"color: #d73a49\">++<\/span>;<\/p>\n<p> &nbsp;return current;<br \/><span style=\"color: #997\">}<\/span><\/span><\/span><\/span><\/p>\n<p>struct Node <span style=\"color: #d73a49\">*<\/span>SkipListDelete<span style=\"color: #997\">(<\/span>struct SkipList <span style=\"color: #d73a49\">*<\/span>list, SKIP_LIST_KEY_TYPE key<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span><span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>SKIP_LIST_MAX_LEVEL<span style=\"color: #997\">]<\/span>;<br \/> &nbsp;struct Node <span style=\"color: #d73a49\">*<\/span>current;<br \/> &nbsp;<span style=\"color: #22863a\">int<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i;<\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>head;<br \/> &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">&#8211;<\/span> <span style=\"color: #005cc5\">1<\/span>; i <span style=\"color: #d73a49\">&gt;=<\/span> <span style=\"color: #005cc5\">0<\/span>; i<span style=\"color: #6a737d\">&#8211;) {<\/span><br \/> &nbsp; &nbsp;while <span style=\"color: #997\">(<\/span>current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span> <span style=\"color: #d73a49\">&amp;&amp;<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span><span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\"> key<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;current <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span>;<br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">=<\/span> current;<br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;current <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span><span style=\"color: #005cc5\">0<\/span><span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span>;<br \/> &nbsp;if <span style=\"color: #997\">(<\/span>current <span style=\"color: #d73a49\">&amp;&amp;<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>key <span style=\"color: #d73a49\">==<\/span> key<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp;for <span style=\"color: #997\">(<\/span>i <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">0<\/span>; i <span style=\"color: #d73a49\"> list<span style=\"color: #d73a49\">-&gt;<\/span>level; i<span style=\"color: #d73a49\">++<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;if <span style=\"color: #997\">(<\/span><span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span> <span style=\"color: #d73a49\">==<\/span> current<span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.forward<\/span> <span style=\"color: #d73a49\">=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span>;<br \/> &nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #d73a49\">update<\/span><span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.span<\/span> <span style=\"color: #d73a49\">+=<\/span> current<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>i<span style=\"color: #997\">]<\/span><span style=\"color: #005cc5\">.span<\/span> <span style=\"color: #d73a49\">&#8211;<\/span> <span style=\"color: #005cc5\">1<\/span>;<br \/> &nbsp; &nbsp; &nbsp;<span style=\"color: #997\">}<\/span> else <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp; &nbsp;break;<br \/> &nbsp; &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp; &nbsp;while <span style=\"color: #997\">(<\/span>list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">&gt;<\/span> <span style=\"color: #005cc5\">1<\/span> <span style=\"color: #d73a49\">&amp;&amp;<\/span> list<span style=\"color: #d73a49\">-&gt;<\/span>head<span style=\"color: #d73a49\">-&gt;<\/span>forwards<span style=\"color: #997\">[<\/span>list<span style=\"color: #d73a49\">-&gt;<\/span>level <span style=\"color: #d73a49\">&#8211;<\/span> <span style=\"color: #005cc5\">1<\/span><span style=\"color: #997\">]<\/span> <span style=\"color: #d73a49\">==<\/span> <span style=\"color: #905\">NULL<\/span><span style=\"color: #997\">)<\/span> <span style=\"color: #997\">{<\/span><br \/> &nbsp; &nbsp; &nbsp;list<span style=\"color: #d73a49\">-&gt;<\/span>level<span style=\"color: #6a737d\">&#8211;;<\/span><br \/> &nbsp; &nbsp;<span style=\"color: #997\">}<\/span><br \/> &nbsp;<span style=\"color: #997\">}<\/span><\/p>\n<p> &nbsp;return current;<br \/><span style=\"color: #997\">}<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #606c71\">\u5f53\u5b9e\u73b0\u4e86\u5feb\u901f\u968f\u673a\u8bbf\u95ee\u4e4b\u540e\uff0c\u901a\u8fc7\u7b80\u5355\u7684\u6307\u9488\u64cd\u4f5c\u5373\u53ef\u5b9e\u73b0\u533a\u95f4\u67e5\u8be2\u529f\u80fd\u3002<\/span><\/p>\n<h2>\u53c2\u8003\u6587\u732e<\/h2>\n<ol>\n<li>\n<p><span style=\"color: #606c71\">Pugh, W. (1989). A skip list cookbook. Tech. Rep. CS-TR-2286.1, Dept. of Computer Science, Univ. of Maryland, College Park, MD [July 1989]<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">Pugh, W. (1989). Skip lists: A probabilistic alternative to balanced trees. Lecture Notes in Computer Science, 437\u2013449. https:\/\/doi.org\/10.1007\/3-540-51542-9_36<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">Weiss, M. A. (1996).&nbsp;<em>Data Structures and Algorithm Analysis in C (2nd Edition)<\/em>&nbsp;(2nd ed.). Pearson.<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">Aragon, Cecilia &amp; Seidel, Raimund. (1989). Randomized Search Trees. 540-545. 10.1109\/SFCS.1989.63531.<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">Wikipedia contributors. (2022b, November 22).&nbsp;<em>Finger search<\/em>. Wikipedia. https:\/\/en.wikipedia.org\/wiki\/Finger_search<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">Wikipedia contributors. (2022a, October 24).&nbsp;<em>Threaded binary tree<\/em>. Wikipedia. https:\/\/en.wikipedia.org\/wiki\/Threaded_binary_tree<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">Wikipedia contributors. (2023, January 4).&nbsp;<em>Negative binomial distribution<\/em>. Wikipedia. https:\/\/en.wikipedia.org\/wiki\/Negative_binomial_distribution<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color: #606c71\">Redis contributors.&nbsp;<em>Redis ordered set implementation<\/em>. GitHub. https:\/\/github.com\/redis\/redis<\/span><\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u6587\u5f7b\u5e95\u641e\u6e05\u8df3\u8dc3\u8868\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201537","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201537"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201537\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}