{"id":55448,"date":"2025-08-13T22:34:53","date_gmt":"2025-08-13T14:34:53","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/55448.html"},"modified":"2025-08-13T22:34:53","modified_gmt":"2025-08-13T14:34:53","slug":"%e4%b8%80%e4%b8%aa%e5%8f%8c%e5%90%91%e9%93%be%e8%a1%a8%e5%ae%9e%e4%be%8b%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/55448.html","title":{"rendered":"\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u5b9e\u4f8b\u89e3\u6790"},"content":{"rendered":"<p>                    <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">util_timer<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">client_data<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    sockaddr_in address<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> sockfd<span class=\"token punctuation\">;<\/span><br \/>\n    util_timer <span class=\"token operator\">*<\/span>timer<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">util_timer<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token function\">util_timer<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">:<\/span> <span class=\"token function\">prev<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">next<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n    time_t expire<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">void<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span> cb_func<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">(<\/span>client_data <span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    client_data <span class=\"token operator\">*<\/span>user_data<span class=\"token punctuation\">;<\/span><br \/>\n    util_timer <span class=\"token operator\">*<\/span>prev<span class=\"token punctuation\">;<\/span><br \/>\n    util_timer <span class=\"token operator\">*<\/span>next<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">sort_timer_lst<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token function\">sort_timer_lst<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token operator\">~<\/span><span class=\"token function\">sort_timer_lst<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">void<\/span> <span class=\"token function\">add_timer<\/span><span class=\"token punctuation\">(<\/span>util_timer <span class=\"token operator\">*<\/span>timer<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">adjust_timer<\/span><span class=\"token punctuation\">(<\/span>util_timer <span class=\"token operator\">*<\/span>timer<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">del_timer<\/span><span class=\"token punctuation\">(<\/span>util_timer <span class=\"token operator\">*<\/span>timer<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">tick<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">add_timer<\/span><span class=\"token punctuation\">(<\/span>util_timer <span class=\"token operator\">*<\/span>timer<span class=\"token punctuation\">,<\/span> util_timer <span class=\"token operator\">*<\/span>lst_head<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    util_timer <span class=\"token operator\">*<\/span>head<span class=\"token punctuation\">;<\/span><br \/>\n    util_timer <span class=\"token operator\">*<\/span>tail<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4ece\u6570\u636e\u7ed3\u6784\u89d2\u5ea6\u5bf9\u8fd9\u6bb5\u4ee3\u7801\u8fdb\u884c\u66f4\u7ec6\u81f4\u7684\u62c6\u89e3&#xff0c;\u7ed3\u5408\u5176\u5728\u7f51\u7edc\u7f16\u7a0b\u4e2d\u7684\u5178\u578b\u5e94\u7528\u573a\u666f&#xff08;\u5982TCP\u670d\u52a1\u5668\u7684\u8d85\u65f6\u8fde\u63a5\u7ba1\u7406&#xff09;&#xff0c;\u5206\u6790\u6bcf\u4e2a\u7ed3\u6784\u7684\u8bbe\u8ba1\u76ee\u7684\u3001\u4ea4\u4e92\u903b\u8f91\u53ca\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u7279\u6027\u3002<\/p>\n<h4>\u4e00\u3001client_data\u7ed3\u6784\u4f53&#xff1a;\u4e1a\u52a1\u6570\u636e\u4e0e\u5b9a\u65f6\u5668\u7684\u201c\u7ed1\u5b9a\u5668\u201d<\/h4>\n<p>client_data\u662f\u7f51\u7edc\u8fde\u63a5\u4fe1\u606f\u4e0e\u5b9a\u65f6\u5668\u7684\u4e2d\u95f4\u8f7d\u4f53&#xff0c;\u5176\u6838\u5fc3\u4f5c\u7528\u662f\u5efa\u7acb\u201c\u5ba2\u6237\u7aef\u8fde\u63a5\u201d\u4e0e\u201c\u5b9a\u65f6\u5668\u201d\u7684\u53cc\u5411\u6620\u5c04&#xff0c;\u8fd9\u662f\u6570\u636e\u7ed3\u6784\u670d\u52a1\u4e8e\u4e1a\u52a1\u903b\u8f91\u7684\u5173\u952e\u8bbe\u8ba1\u3002<\/p>\n<h5>\u6210\u5458\u89e3\u6790&#xff1a;<\/h5>\n<ul>\n<li>sockaddr_in address&#xff1a;\u5b58\u50a8\u5ba2\u6237\u7aef\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7&#xff08;\u7f51\u7edc\u7f16\u7a0b\u4e2d\u6807\u51c6\u7684\u5730\u5740\u7ed3\u6784&#xff09;&#xff0c;\u7528\u4e8e\u6807\u8bc6\u5ba2\u6237\u7aef\u7684\u7f51\u7edc\u8eab\u4efd\u3002<\/li>\n<li>int sockfd&#xff1a;\u5ba2\u6237\u7aef\u7684\u5957\u63a5\u5b57\u63cf\u8ff0\u7b26&#xff08;\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff09;&#xff0c;\u662f\u64cd\u4f5c\u7cfb\u7edf\u6807\u8bc6\u4e00\u4e2a\u7f51\u7edc\u8fde\u63a5\u7684\u552f\u4e00\u201c\u53e5\u67c4\u201d&#xff0c;\u901a\u8fc7\u5b83\u53ef\u4ee5\u6267\u884c\u8bfb\u5199\u3001\u5173\u95ed\u7b49\u64cd\u4f5c\u3002<\/li>\n<li>util_timer* timer&#xff1a;\u6307\u5411\u8be5\u5ba2\u6237\u7aef\u5bf9\u5e94\u7684\u5b9a\u65f6\u5668\u3002\u5f53\u5ba2\u6237\u7aef\u6d3b\u52a8&#xff08;\u5982\u53d1\u9001\u6570\u636e&#xff09;\u65f6&#xff0c;\u9700\u8981\u901a\u8fc7\u8fd9\u4e2a\u6307\u9488\u627e\u5230\u5bf9\u5e94\u7684\u5b9a\u65f6\u5668\u5e76\u66f4\u65b0\u5176\u8fc7\u671f\u65f6\u95f4&#xff1b;\u5f53\u5b9a\u65f6\u5668\u8fc7\u671f\u65f6&#xff0c;\u4e5f\u80fd\u901a\u8fc7\u5b83\u53cd\u5411\u5173\u8054\u5230\u5ba2\u6237\u7aef\u6570\u636e\u3002<\/li>\n<\/ul>\n<h5>\u8bbe\u8ba1\u610f\u4e49&#xff1a;<\/h5>\n<p>\u5728\u7f51\u7edc\u670d\u52a1\u5668\u4e2d&#xff0c;\u6bcf\u4e2a\u5ba2\u6237\u7aef\u8fde\u63a5\u90fd\u9700\u8981\u4e00\u4e2a\u5b9a\u65f6\u5668&#xff08;\u7528\u4e8e\u68c0\u6d4b\u201c\u957f\u65f6\u95f4\u65e0\u6d3b\u52a8\u201d\u7684\u8d85\u65f6\u8fde\u63a5\u5e76\u5173\u95ed&#xff09;\u3002client_data\u901a\u8fc7timer\u6307\u9488\u5c06\u201c\u8fde\u63a5\u201d\u4e0e\u201c\u5b9a\u65f6\u5668\u201d\u7ed1\u5b9a&#xff0c;\u4f7f\u5f97\u4e24\u8005\u7684\u72b6\u6001\u53ef\u4ee5\u76f8\u4e92\u5f71\u54cd&#xff0c;\u5b9e\u73b0\u201c\u6d3b\u52a8\u91cd\u7f6e\u5b9a\u65f6\u5668&#xff0c;\u8d85\u65f6\u5173\u95ed\u8fde\u63a5\u201d\u7684\u6838\u5fc3\u903b\u8f91\u3002<\/p>\n<h4>\u4e8c\u3001util_timer\u7c7b&#xff1a;\u53cc\u5411\u94fe\u8868\u8282\u70b9\u7684\u201c\u591a\u529f\u80fd\u8f7d\u4f53\u201d<\/h4>\n<p>util_timer\u662f\u5b9a\u65f6\u5668\u94fe\u8868\u7684\u8282\u70b9\u7ed3\u6784&#xff0c;\u5b83\u4e0d\u4ec5\u662f\u53cc\u5411\u94fe\u8868\u7684\u7ec4\u6210\u5355\u5143&#xff0c;\u8fd8\u5c01\u88c5\u4e86\u5b9a\u65f6\u5668\u7684\u6838\u5fc3\u4e1a\u52a1\u4fe1\u606f&#xff08;\u8fc7\u671f\u65f6\u95f4\u3001\u56de\u8c03\u51fd\u6570\u3001\u5173\u8054\u7684\u5ba2\u6237\u7aef\u6570\u636e&#xff09;\u3002<\/p>\n<h5>\u6210\u5458\u89e3\u6790&#xff1a;<\/h5>\n<ul>\n<li>\u53cc\u5411\u94fe\u8868\u6307\u9488&#xff1a;prev&#xff08;\u524d\u9a71\u8282\u70b9&#xff09;\u548cnext&#xff08;\u540e\u7ee7\u8282\u70b9&#xff09;\u3002\u8fd9\u4e24\u4e2a\u6307\u9488\u662f\u53cc\u5411\u94fe\u8868\u7684\u6807\u5fd7\u6027\u7279\u5f81&#xff0c;\u7528\u4e8e\u7ef4\u62a4\u8282\u70b9\u4e4b\u95f4\u7684\u903b\u8f91\u5173\u7cfb&#xff1a;\n<ul>\n<li>\u76f8\u6bd4\u5355\u5411\u94fe\u8868&#xff08;\u53ea\u6709next\u6307\u9488&#xff09;&#xff0c;\u53cc\u5411\u94fe\u8868\u7684\u4f18\u52bf\u5728\u4e8e&#xff1a;\u5220\u9664\u8282\u70b9\u65f6\u65e0\u9700\u4ece\u5934\u904d\u5386\u67e5\u627e\u524d\u9a71&#xff08;\u5df2\u77e5\u8282\u70b9\u65f6\u53ef\u76f4\u63a5\u901a\u8fc7prev\u64cd\u4f5c&#xff09;&#xff0c;\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(1)&#xff1b;\u652f\u6301\u53cc\u5411\u904d\u5386&#xff08;\u5982\u4ece\u5c3e\u90e8\u5411\u524d\u67e5\u627e\u63d2\u5165\u4f4d\u7f6e&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u8fc7\u671f\u65f6\u95f4&#xff1a;time_t expire&#xff08;\u672c\u8d28\u662f\u4e00\u4e2a\u6574\u6570&#xff0c;\u4ee3\u8868\u4ece\u67d0\u4e2a\u65f6\u95f4\u70b9\u5230\u8fc7\u671f\u65f6\u523b\u7684\u79d2\u6570&#xff09;\u3002\u8fd9\u662f\u94fe\u8868\u6392\u5e8f\u7684\u552f\u4e00\u4f9d\u636e&#xff0c;\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u6309expire\u4ece\u5c0f\u5230\u5927&#xff08;\u5347\u5e8f&#xff09;\u6392\u5217\u3002<\/li>\n<li>\u56de\u8c03\u51fd\u6570&#xff1a;void (*cb_func)(client_data*)\u3002\u8fd9\u662f\u5b9a\u65f6\u5668\u8fc7\u671f\u65f6\u7684\u201c\u5904\u7406\u903b\u8f91\u5165\u53e3\u201d&#xff0c;\u901a\u5e38\u6307\u5411\u5173\u95ed\u5ba2\u6237\u7aef\u8fde\u63a5\u3001\u91ca\u653e\u8d44\u6e90\u7684\u51fd\u6570\u3002\u901a\u8fc7\u51fd\u6570\u6307\u9488\u8bbe\u8ba1&#xff0c;\u4f7f\u5b9a\u65f6\u5668\u8282\u70b9\u4e0e\u5177\u4f53\u5904\u7406\u903b\u8f91\u89e3\u8026&#xff08;\u540c\u4e00\u4e2a\u94fe\u8868\u53ef\u652f\u6301\u4e0d\u540c\u7684\u56de\u8c03\u903b\u8f91&#xff09;\u3002<\/li>\n<li>\u5173\u8054\u6570\u636e&#xff1a;client_data* user_data\u3002\u6307\u5411\u8be5\u5b9a\u65f6\u5668\u5bf9\u5e94\u7684\u5ba2\u6237\u7aef\u6570\u636e&#xff0c;\u4f7f\u5f97\u56de\u8c03\u51fd\u6570\u88ab\u8c03\u7528\u65f6&#xff0c;\u80fd\u901a\u8fc7\u8fd9\u4e2a\u6307\u9488\u627e\u5230\u8981\u5904\u7406\u7684\u5ba2\u6237\u7aef&#xff08;\u5982\u901a\u8fc7sockfd\u5173\u95ed\u8fde\u63a5&#xff09;\u3002<\/li>\n<\/ul>\n<h5>\u8282\u70b9\u7279\u6027&#xff1a;<\/h5>\n<p>\u6bcf\u4e2autil_timer\u8282\u70b9\u662f\u201c\u6570\u636e&#xff08;expire&#xff09;&#043; \u6307\u9488&#xff08;prev\/next&#xff09;&#043; \u4e1a\u52a1\u5173\u8054&#xff08;cb_func\/user_data&#xff09;\u201d\u7684\u7efc\u5408\u4f53&#xff0c;\u65e2\u6ee1\u8db3\u53cc\u5411\u94fe\u8868\u7684\u7ed3\u6784\u9700\u6c42&#xff0c;\u53c8\u627f\u8f7d\u4e86\u5b9a\u65f6\u5668\u7684\u4e1a\u52a1\u903b\u8f91\u3002<\/p>\n<h4>\u4e09\u3001sort_timer_lst\u7c7b&#xff1a;\u6709\u5e8f\u53cc\u5411\u94fe\u8868\u7684\u201c\u7ba1\u7406\u4e2d\u67a2\u201d<\/h4>\n<p>sort_timer_lst\u662f\u5bf9\u53cc\u5411\u94fe\u8868\u7684\u5c01\u88c5\u7ba1\u7406\u7c7b&#xff0c;\u63d0\u4f9b\u4e86\u5b9a\u65f6\u5668\u7684\u6dfb\u52a0\u3001\u8c03\u6574\u3001\u5220\u9664\u548c\u8fc7\u671f\u5904\u7406\u7b49\u6838\u5fc3\u64cd\u4f5c\u3002\u5176\u6838\u5fc3\u8bbe\u8ba1\u76ee\u6807\u662f&#xff1a;\u7ef4\u62a4\u94fe\u8868\u7684\u201c\u6309\u8fc7\u671f\u65f6\u95f4\u5347\u5e8f\u6392\u5217\u201d\u7279\u6027&#xff0c;\u5e76\u9ad8\u6548\u5904\u7406\u5b9a\u65f6\u5668\u4e8b\u4ef6\u3002<\/p>\n<h5>1. \u6210\u5458\u53d8\u91cf&#xff1a;\u94fe\u8868\u7684\u201c\u8fb9\u754c\u6807\u8bc6\u201d<\/h5>\n<ul>\n<li>head&#xff1a;\u6307\u5411\u94fe\u8868\u7684\u5934\u8282\u70b9&#xff08;expire\u6700\u5c0f\u7684\u8282\u70b9&#xff0c;\u6700\u5148\u53ef\u80fd\u8fc7\u671f&#xff09;\u3002<\/li>\n<li>tail&#xff1a;\u6307\u5411\u94fe\u8868\u7684\u5c3e\u8282\u70b9&#xff08;expire\u6700\u5927\u7684\u8282\u70b9&#xff0c;\u6700\u540e\u8fc7\u671f&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u4e2a\u6307\u9488\u7684\u4f5c\u7528\u662f\u7b80\u5316\u94fe\u8868\u64cd\u4f5c&#xff1a;\u4f8b\u5982\u6dfb\u52a0\u8282\u70b9\u65f6\u53ef\u4ece\u5934\u90e8\u5f00\u59cb\u904d\u5386&#xff0c;\u5220\u9664\u8282\u70b9\u65f6\u65e0\u9700\u5224\u65ad\u662f\u5426\u4e3a\u5934\/\u5c3e\u8282\u70b9&#xff08;\u901a\u8fc7prev\/next\u76f4\u63a5\u64cd\u4f5c&#xff09;\u3002<\/p>\n<h5>2. \u6838\u5fc3\u65b9\u6cd5\u89e3\u6790&#xff1a;\u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u7684\u64cd\u4f5c\u903b\u8f91<\/h5>\n<h6>&#xff08;1&#xff09;add_timer(util_timer* timer)&#xff1a;\u6dfb\u52a0\u5b9a\u65f6\u5668&#xff08;\u6838\u5fc3\u662f\u201c\u4fdd\u6301\u6709\u5e8f\u201d&#xff09;<\/h6>\n<p>\u76ee\u6807&#xff1a;\u5c06\u65b0\u5b9a\u65f6\u5668\u63d2\u5165\u94fe\u8868&#xff0c;\u4f7f\u63d2\u5165\u540e\u94fe\u8868\u4ecd\u6309expire\u5347\u5e8f\u6392\u5217\u3002<br \/>\n\u5b9e\u73b0\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\u82e5\u94fe\u8868\u4e3a\u7a7a&#xff08;head &#061;&#061; NULL&#xff09;&#xff0c;\u5219\u65b0\u8282\u70b9\u65e2\u662f\u5934\u4e5f\u662f\u5c3e\u3002<\/li>\n<li>\u82e5\u65b0\u8282\u70b9expire\u5c0f\u4e8e\u5934\u8282\u70b9expire&#xff0c;\u5219\u63d2\u5165\u5230\u5934\u8282\u70b9\u524d&#xff08;\u6210\u4e3a\u65b0\u5934&#xff09;\u3002<\/li>\n<li>\u5426\u5219&#xff0c;\u8c03\u7528\u79c1\u6709\u65b9\u6cd5add_timer(timer, head)&#xff0c;\u4ecehead\u5f00\u59cb\u904d\u5386&#xff0c;\u627e\u5230\u7b2c\u4e00\u4e2aexpire\u5927\u4e8e\u65b0\u8282\u70b9expire\u7684\u8282\u70b9&#xff0c;\u5c06\u65b0\u8282\u70b9\u63d2\u5165\u5230\u8be5\u8282\u70b9\u7684\u524d\u9762&#xff08;\u901a\u8fc7\u8c03\u6574prev\u548cnext\u6307\u9488\u5b8c\u6210\u53cc\u5411\u94fe\u8868\u7684\u63d2\u5165&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b&#xff1a;<br \/>\n\u73b0\u6709\u94fe\u8868&#xff1a;timer1(expire&#061;10) &lt;-&gt; timer2(expire&#061;20) &lt;-&gt; timer3(expire&#061;30)<br \/>\n\u63d2\u5165timer4(expire&#061;25)&#xff0c;\u904d\u5386\u627e\u5230timer3&#xff08;\u7b2c\u4e00\u4e2aexpire&gt;25\u7684\u8282\u70b9&#xff09;&#xff0c;\u63d2\u5165\u540e&#xff1a;<br \/>\ntimer1 &lt;-&gt; timer2 &lt;-&gt; timer4 &lt;-&gt; timer3<\/p>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(n)&#xff08;\u6700\u574f\u60c5\u51b5\u9700\u904d\u5386\u6574\u4e2a\u94fe\u8868&#xff0c;\u5982\u63d2\u5165\u5230\u5c3e\u90e8&#xff09;\u3002<\/p>\n<h6>&#xff08;2&#xff09;adjust_timer(util_timer* timer)&#xff1a;\u8c03\u6574\u5b9a\u65f6\u5668\u4f4d\u7f6e&#xff08;\u5e94\u5bf9\u8fc7\u671f\u65f6\u95f4\u53d8\u5316&#xff09;<\/h6>\n<p>\u573a\u666f&#xff1a;\u5f53\u5ba2\u6237\u7aef\u6709\u65b0\u6d3b\u52a8&#xff08;\u5982\u53d1\u9001\u6570\u636e&#xff09;\u65f6&#xff0c;\u9700\u8981\u5ef6\u957f\u5176\u5b9a\u65f6\u5668\u7684\u8fc7\u671f\u65f6\u95f4&#xff08;\u5982\u4eceexpire&#061;10\u6539\u4e3aexpire&#061;30&#xff09;&#xff0c;\u6b64\u65f6\u8282\u70b9\u5728\u94fe\u8868\u4e2d\u7684\u4f4d\u7f6e\u9700\u8981\u91cd\u65b0\u8c03\u6574\u3002<\/p>\n<p>\u5b9e\u73b0\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\u82e5\u5b9a\u65f6\u5668\u662f\u5934\u8282\u70b9&#xff0c;\u6216\u65b0expire\u4ecd\u5c0f\u4e8e\u5176\u540e\u7ee7\u8282\u70b9\u7684expire&#xff1a;\u65e0\u9700\u8c03\u6574&#xff08;\u4ecd\u4fdd\u6301\u6709\u5e8f&#xff09;\u3002<\/li>\n<li>\u5426\u5219&#xff1a;\u5148\u8c03\u7528del_timer(timer)\u4ece\u94fe\u8868\u4e2d\u5220\u9664\u8be5\u8282\u70b9&#xff0c;\u518d\u8c03\u7528add_timer(timer)\u91cd\u65b0\u63d2\u5165&#xff08;\u6309\u65b0expire\u627e\u5230\u6b63\u786e\u4f4d\u7f6e&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u672c\u8d28&#xff1a;\u901a\u8fc7\u201c\u5220\u9664&#043;\u91cd\u65b0\u63d2\u5165\u201d\u5b9e\u73b0\u4f4d\u7f6e\u8c03\u6574&#xff0c;\u5229\u7528\u53cc\u5411\u94fe\u8868\u7684\u52a8\u6001\u6027\u9002\u5e94\u6570\u636e\u53d8\u5316\u3002<\/p>\n<h6>&#xff08;3&#xff09;del_timer(util_timer* timer)&#xff1a;\u5220\u9664\u5b9a\u65f6\u5668&#xff08;\u53cc\u5411\u94fe\u8868\u7684\u8282\u70b9\u79fb\u9664&#xff09;<\/h6>\n<p>\u5b9e\u73b0\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\u82e5\u8282\u70b9\u662f\u5934\u8282\u70b9&#xff08;timer &#061;&#061; head&#xff09;&#xff1a;\u66f4\u65b0head\u4e3atimer-&gt;next&#xff1b;\u82e5\u65b0head\u4e0d\u4e3a\u7a7a&#xff0c;\u9700\u5c06\u65b0head-&gt;prev\u7f6e\u4e3aNULL&#xff08;\u5426\u5219\u65b0\u5934\u7684\u524d\u9a71\u4ecd\u6307\u5411\u88ab\u5220\u9664\u8282\u70b9&#xff09;\u3002<\/li>\n<li>\u82e5\u8282\u70b9\u662f\u5c3e\u8282\u70b9&#xff08;timer &#061;&#061; tail&#xff09;&#xff1a;\u66f4\u65b0tail\u4e3atimer-&gt;prev&#xff1b;\u82e5\u65b0tail\u4e0d\u4e3a\u7a7a&#xff0c;\u9700\u5c06\u65b0tail-&gt;next\u7f6e\u4e3aNULL\u3002<\/li>\n<li>\u82e5\u8282\u70b9\u662f\u4e2d\u95f4\u8282\u70b9&#xff1a;\u901a\u8fc7timer-&gt;prev-&gt;next &#061; timer-&gt;next\u548ctimer-&gt;next-&gt;prev &#061; timer-&gt;prev&#xff0c;\u5c06\u8282\u70b9\u4ece\u94fe\u8868\u4e2d\u201c\u6458\u51fa\u201d\u3002<\/li>\n<\/ul>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(1)&#xff08;\u5df2\u77e5\u8282\u70b9\u4f4d\u7f6e\u65f6&#xff0c;\u65e0\u9700\u904d\u5386&#xff09;\u3002<\/p>\n<h6>&#xff08;4&#xff09;tick()&#xff1a;\u5904\u7406\u8fc7\u671f\u5b9a\u65f6\u5668&#xff08;\u94fe\u8868\u6709\u5e8f\u6027\u7684\u6838\u5fc3\u4ef7\u503c&#xff09;<\/h6>\n<p>\u4f5c\u7528&#xff1a;\u5b9a\u671f&#xff08;\u5982\u6bcf\u96941\u79d2&#xff09;\u8c03\u7528&#xff0c;\u68c0\u67e5\u5e76\u5904\u7406\u6240\u6709\u5df2\u8fc7\u671f\u7684\u5b9a\u65f6\u5668\u3002<\/p>\n<p>\u5b9e\u73b0\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\u82e5\u94fe\u8868\u4e3a\u7a7a&#xff0c;\u76f4\u63a5\u8fd4\u56de\u3002<\/li>\n<li>\u5faa\u73af\u5224\u65ad\u5934\u8282\u70b9head\u662f\u5426\u8fc7\u671f&#xff08;head-&gt;expire &lt;&#061; \u5f53\u524d\u65f6\u95f4&#xff09;&#xff1a;\n<ul>\n<li>\u82e5\u662f&#xff1a;\u6267\u884c\u5934\u8282\u70b9\u7684\u56de\u8c03\u51fd\u6570&#xff08;head-&gt;cb_func(head-&gt;user_data)&#xff0c;\u5982\u5173\u95ed\u5ba2\u6237\u7aef\u8fde\u63a5&#xff09;\u3002<\/li>\n<li>\u4fdd\u5b58\u5f53\u524d\u5934\u8282\u70b9\u5230\u4e34\u65f6\u53d8\u91cftmp&#xff0c;\u66f4\u65b0head\u4e3ahead-&gt;next&#xff1b;\u82e5\u65b0head\u4e0d\u4e3a\u7a7a&#xff0c;\u5c06new head-&gt;prev\u7f6e\u4e3aNULL\u3002<\/li>\n<li>\u91ca\u653etmp\u8282\u70b9\u7684\u5185\u5b58\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u76f4\u5230\u5934\u8282\u70b9\u672a\u8fc7\u671f&#xff08;\u7531\u4e8e\u94fe\u8868\u6709\u5e8f&#xff0c;\u540e\u7eed\u8282\u70b9expire\u5747\u5927\u4e8e\u5934\u8282\u70b9&#xff0c;\u65e0\u9700\u7ee7\u7eed\u5224\u65ad&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b&#xff1a;<br \/>\n\u5f53\u524d\u65f6\u95f4\u4e3a25&#xff0c;\u94fe\u8868&#xff1a;timer1(10) &lt;-&gt; timer2(20) &lt;-&gt; timer4(25) &lt;-&gt; timer3(30)<br \/>\ntick()\u4f1a\u4f9d\u6b21\u5904\u7406timer1&#xff08;10\u226425&#xff09;\u3001timer2&#xff08;20\u226425&#xff09;\u3001timer4&#xff08;25\u226425&#xff09;&#xff0c;\u6700\u7ec8\u94fe\u8868\u4ec5\u5269timer3\u3002<\/p>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(k)&#xff08;k\u4e3a\u8fc7\u671f\u8282\u70b9\u6570&#xff0c;\u901a\u5e38\u8fdc\u5c0f\u4e8e\u603b\u8282\u70b9\u6570n&#xff09;&#xff0c;\u8fd9\u662f\u94fe\u8868\u201c\u6709\u5e8f\u6027\u201d\u5e26\u6765\u7684\u6548\u7387\u4f18\u52bf&#xff08;\u65e0\u9700\u904d\u5386\u6240\u6709\u8282\u70b9&#xff09;\u3002<\/p>\n<h4>\u56db\u3001\u6570\u636e\u7ed3\u6784\u8bbe\u8ba1\u7684\u201c\u6743\u8861\u4e0e\u9002\u914d\u201d<\/h4>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u9009\u62e9\u6709\u5e8f\u53cc\u5411\u94fe\u8868\u4f5c\u4e3a\u5b9a\u65f6\u5668\u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784&#xff0c;\u662f\u5bf9\u201c\u5b9e\u73b0\u590d\u6742\u5ea6\u201d\u548c\u201c\u573a\u666f\u9700\u6c42\u201d\u7684\u6743\u8861&#xff1a;<\/p>\n<h5>\u4f18\u52bf&#xff1a;<\/h5>\n<li>\u5b9e\u73b0\u7b80\u5355&#xff1a;\u53cc\u5411\u94fe\u8868\u7684\u8282\u70b9\u63d2\u5165\u3001\u5220\u9664\u3001\u904d\u5386\u903b\u8f91\u76f4\u89c2&#xff0c;\u4ee3\u7801\u91cf\u5c11&#xff0c;\u6613\u4e8e\u7ef4\u62a4\u3002<\/li>\n<li>\u6709\u5e8f\u6027\u9002\u914d\u5b9a\u65f6\u5668\u573a\u666f&#xff1a;\u5b9a\u65f6\u5668\u7684\u6838\u5fc3\u9700\u6c42\u662f\u201c\u6309\u65f6\u95f4\u987a\u5e8f\u5904\u7406\u8fc7\u671f\u4e8b\u4ef6\u201d&#xff0c;\u6709\u5e8f\u94fe\u8868\u7684tick()\u64cd\u4f5c\u53ef\u9ad8\u6548\u5904\u7406\u5934\u90e8\u8fc7\u671f\u8282\u70b9\u3002<\/li>\n<li>\u52a8\u6001\u8c03\u6574\u7075\u6d3b&#xff1a;\u901a\u8fc7adjust_timer\u7684\u201c\u5220\u63d2\u201d\u903b\u8f91&#xff0c;\u53ef\u9002\u5e94\u5b9a\u65f6\u5668\u8fc7\u671f\u65f6\u95f4\u7684\u52a8\u6001\u53d8\u5316\u3002<\/li>\n<h5>\u5c40\u9650\u6027&#xff1a;<\/h5>\n<li>\u63d2\u5165\u6548\u7387\u4f4e&#xff08;O(n)&#xff09;&#xff1a;\u5f53\u5b9a\u65f6\u5668\u6570\u91cf\u5e9e\u5927&#xff08;\u598210\u4e07\u7ea7&#xff09;\u65f6&#xff0c;\u63d2\u5165\u64cd\u4f5c\u9700\u8981\u904d\u5386\u94fe\u8868&#xff0c;\u6027\u80fd\u74f6\u9888\u660e\u663e\u3002<\/li>\n<li>\u4e0d\u9002\u5408\u9ad8\u9891\u66f4\u65b0\u573a\u666f&#xff1a;\u82e5\u5ba2\u6237\u7aef\u6d3b\u52a8\u9891\u7e41&#xff08;\u9700\u9891\u7e41\u8c03\u7528adjust_timer&#xff09;&#xff0c;\u201c\u5220\u63d2\u201d\u64cd\u4f5c\u7684\u7d2f\u8ba1\u5f00\u9500\u4f1a\u589e\u5927\u3002<\/li>\n<h5>\u66ff\u4ee3\u65b9\u6848&#xff08;\u66f4\u4f18\u6570\u636e\u7ed3\u6784&#xff09;&#xff1a;<\/h5>\n<ul>\n<li>\u65f6\u95f4\u8f6e&#xff08;Time Wheel&#xff09;&#xff1a;\u5c06\u65f6\u95f4\u5212\u5206\u4e3a\u56fa\u5b9a\u523b\u5ea6&#xff08;\u59821\u79d2\/\u683c&#xff09;&#xff0c;\u6bcf\u4e2a\u523b\u5ea6\u5bf9\u5e94\u4e00\u4e2a\u94fe\u8868&#xff0c;\u5b9a\u65f6\u5668\u6309\u201c\u8fc7\u671f\u65f6\u95f4\u00f7\u523b\u5ea6\u201d\u6620\u5c04\u5230\u5bf9\u5e94\u683c\u5b50\u3002\u63d2\u5165\u548c\u5220\u9664\u6548\u7387\u63a5\u8fd1O(1)&#xff0c;\u9002\u5408\u5b9a\u65f6\u65f6\u95f4\u5206\u6563\u4f46\u66f4\u65b0\u9891\u7e41\u7684\u573a\u666f&#xff08;\u5982\u670d\u52a1\u5668\u5fc3\u8df3\u68c0\u6d4b&#xff09;\u3002<\/li>\n<li>\u6700\u5c0f\u5806&#xff08;Min-Heap&#xff09;&#xff1a;\u7528\u5806\u7ed3\u6784\u5b58\u50a8\u5b9a\u65f6\u5668&#xff0c;\u5806\u9876\u4e3aexpire\u6700\u5c0f\u7684\u8282\u70b9\u3002\u63d2\u5165\u548c\u5220\u9664\u6548\u7387\u4e3aO(log n)&#xff0c;\u9002\u5408\u5b9a\u65f6\u5668\u6570\u91cf\u591a\u4f46\u66f4\u65b0\u4e0d\u9891\u7e41\u7684\u573a\u666f\u3002<\/li>\n<\/ul>\n<h4>\u603b\u7ed3<\/h4>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u662f\u201c\u6570\u636e\u7ed3\u6784\u670d\u52a1\u4e8e\u4e1a\u52a1\u903b\u8f91\u201d\u7684\u5178\u578b\u6848\u4f8b&#xff1a;<\/p>\n<ul>\n<li>\u7528client_data\u5173\u8054\u201c\u7f51\u7edc\u8fde\u63a5\u201d\u548c\u201c\u5b9a\u65f6\u5668\u201d&#xff0c;\u89e3\u51b3\u4e1a\u52a1\u5bf9\u8c61\u4e0e\u6570\u636e\u7ed3\u6784\u7684\u7ed1\u5b9a\u95ee\u9898&#xff1b;<\/li>\n<li>\u7528util_timer\u5b9e\u73b0\u201c\u53cc\u5411\u94fe\u8868\u8282\u70b9&#043;\u5b9a\u65f6\u5668\u4fe1\u606f\u201d\u7684\u878d\u5408&#xff0c;\u6ee1\u8db3\u7ed3\u6784\u548c\u4e1a\u52a1\u53cc\u91cd\u9700\u6c42&#xff1b;<\/li>\n<li>\u7528sort_timer_lst\u7ba1\u7406\u6709\u5e8f\u53cc\u5411\u94fe\u8868&#xff0c;\u901a\u8fc7\u7ef4\u62a4expire\u7684\u5347\u5e8f\u6027&#xff0c;\u5b9e\u73b0\u9ad8\u6548\u7684\u8fc7\u671f\u4e8b\u4ef6\u5904\u7406\u3002<\/li>\n<\/ul>\n<p>\u5176\u8bbe\u8ba1\u7b80\u6d01\u4e14\u9002\u914d\u4e2d\u5c0f\u89c4\u6a21\u7684\u5b9a\u65f6\u5668\u573a\u666f&#xff08;\u5982\u8f7b\u91cf\u7ea7\u670d\u52a1\u5668&#xff09;&#xff0c;\u4f46\u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u9700\u7ed3\u5408\u66f4\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784&#xff08;\u5982\u65f6\u95f4\u8f6e&#xff09;\u4f18\u5316\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e37\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u57fa\u4e8e\u6709\u5e8f\u53cc\u5411\u94fe\u8868\u7684\u5b9a\u65f6\u5668\u7ba1\u7406\u6a21\u5757\uff0c\u4e3b\u8981\u7528\u4e8e\u7f51\u7edc\u7f16\u7a0b\u4e2d\u7684\u8d85\u65f6\u8fde\u63a5\u7ba1\u7406\u3002\u6838\u5fc3\u7ed3\u6784\u5305\u62ec\uff1a1\uff09client_data\u5b58\u50a8\u5ba2\u6237\u7aef\u8fde\u63a5\u4fe1\u606f\u5e76\u5173\u8054\u5b9a\u65f6\u5668\uff1b2\uff09util_timer\u4f5c\u4e3a\u94fe\u8868\u8282\u70b9\uff0c\u5c01\u88c5\u8fc7\u671f\u65f6\u95f4\u3001\u56de\u8c03\u51fd\u6570\u548c\u53cc\u5411\u6307\u9488\uff1b3\uff09sort_timer_lst\u7ba1\u7406\u94fe\u8868\uff0c\u63d0\u4f9b\u6dfb\u52a0\u3001\u5220\u9664\u3001\u8c03\u6574\u548c\u8fc7\u671f\u68c0\u67e5\u529f\u80fd\u3002\u94fe\u8868\u6309\u8fc7\u671f\u65f6\u95f4\u5347\u5e8f\u6392\u5217\uff0c\u4f7f\u5f97tick()\u80fd\u9ad8\u6548\u5904\u7406\u8d85\u65f6\u4e8b\u4ef6\u3002\u8be5\u8bbe\u8ba1\u5b9e\u73b0\u7b80\u5355\uff0c\u901a\u8fc7\u53cc\u5411\u6307\u9488\u5b9e\u73b0O(1)\u5220\u9664\u548cO(n)\u63d2\u5165\uff0c\u9002\u5408\u4e2d\u5c0f\u89c4\u6a21\u8fde\u63a5\u7ba1\u7406\uff0c\u4f46\u5728\u9ad8\u9891\u66f4\u65b0\u6216\u6d77\u91cf\u8fde\u63a5\u573a\u666f\u53ef\u80fd\u5b58\u5728\u6027\u80fd\u74f6\u9888\u3002\u76f8\u6bd4\u66f4\u9ad8\u6548\u7684\u65f6\u95f4\u8f6e<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4952,3355,1813,2640],"topic":[],"class_list":{"0":"post-55448","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-server","7":"tag-c","9":"tag-1813","10":"tag-2640"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u5b9e\u4f8b\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/55448.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u5b9e\u4f8b\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e37\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u57fa\u4e8e\u6709\u5e8f\u53cc\u5411\u94fe\u8868\u7684\u5b9a\u65f6\u5668\u7ba1\u7406\u6a21\u5757\uff0c\u4e3b\u8981\u7528\u4e8e\u7f51\u7edc\u7f16\u7a0b\u4e2d\u7684\u8d85\u65f6\u8fde\u63a5\u7ba1\u7406\u3002\u6838\u5fc3\u7ed3\u6784\u5305\u62ec\uff1a1\uff09client_data\u5b58\u50a8\u5ba2\u6237\u7aef\u8fde\u63a5\u4fe1\u606f\u5e76\u5173\u8054\u5b9a\u65f6\u5668\uff1b2\uff09util_timer\u4f5c\u4e3a\u94fe\u8868\u8282\u70b9\uff0c\u5c01\u88c5\u8fc7\u671f\u65f6\u95f4\u3001\u56de\u8c03\u51fd\u6570\u548c\u53cc\u5411\u6307\u9488\uff1b3\uff09sort_timer_lst\u7ba1\u7406\u94fe\u8868\uff0c\u63d0\u4f9b\u6dfb\u52a0\u3001\u5220\u9664\u3001\u8c03\u6574\u548c\u8fc7\u671f\u68c0\u67e5\u529f\u80fd\u3002\u94fe\u8868\u6309\u8fc7\u671f\u65f6\u95f4\u5347\u5e8f\u6392\u5217\uff0c\u4f7f\u5f97tick()\u80fd\u9ad8\u6548\u5904\u7406\u8d85\u65f6\u4e8b\u4ef6\u3002\u8be5\u8bbe\u8ba1\u5b9e\u73b0\u7b80\u5355\uff0c\u901a\u8fc7\u53cc\u5411\u6307\u9488\u5b9e\u73b0O(1)\u5220\u9664\u548cO(n)\u63d2\u5165\uff0c\u9002\u5408\u4e2d\u5c0f\u89c4\u6a21\u8fde\u63a5\u7ba1\u7406\uff0c\u4f46\u5728\u9ad8\u9891\u66f4\u65b0\u6216\u6d77\u91cf\u8fde\u63a5\u573a\u666f\u53ef\u80fd\u5b58\u5728\u6027\u80fd\u74f6\u9888\u3002\u76f8\u6bd4\u66f4\u9ad8\u6548\u7684\u65f6\u95f4\u8f6e\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/55448.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-13T14:34:53+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/55448.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/55448.html\",\"name\":\"\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u5b9e\u4f8b\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-13T14:34:53+00:00\",\"dateModified\":\"2025-08-13T14:34:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/55448.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/55448.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/55448.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u5b9e\u4f8b\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u5b9e\u4f8b\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/55448.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u5b9e\u4f8b\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e37\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u57fa\u4e8e\u6709\u5e8f\u53cc\u5411\u94fe\u8868\u7684\u5b9a\u65f6\u5668\u7ba1\u7406\u6a21\u5757\uff0c\u4e3b\u8981\u7528\u4e8e\u7f51\u7edc\u7f16\u7a0b\u4e2d\u7684\u8d85\u65f6\u8fde\u63a5\u7ba1\u7406\u3002\u6838\u5fc3\u7ed3\u6784\u5305\u62ec\uff1a1\uff09client_data\u5b58\u50a8\u5ba2\u6237\u7aef\u8fde\u63a5\u4fe1\u606f\u5e76\u5173\u8054\u5b9a\u65f6\u5668\uff1b2\uff09util_timer\u4f5c\u4e3a\u94fe\u8868\u8282\u70b9\uff0c\u5c01\u88c5\u8fc7\u671f\u65f6\u95f4\u3001\u56de\u8c03\u51fd\u6570\u548c\u53cc\u5411\u6307\u9488\uff1b3\uff09sort_timer_lst\u7ba1\u7406\u94fe\u8868\uff0c\u63d0\u4f9b\u6dfb\u52a0\u3001\u5220\u9664\u3001\u8c03\u6574\u548c\u8fc7\u671f\u68c0\u67e5\u529f\u80fd\u3002\u94fe\u8868\u6309\u8fc7\u671f\u65f6\u95f4\u5347\u5e8f\u6392\u5217\uff0c\u4f7f\u5f97tick()\u80fd\u9ad8\u6548\u5904\u7406\u8d85\u65f6\u4e8b\u4ef6\u3002\u8be5\u8bbe\u8ba1\u5b9e\u73b0\u7b80\u5355\uff0c\u901a\u8fc7\u53cc\u5411\u6307\u9488\u5b9e\u73b0O(1)\u5220\u9664\u548cO(n)\u63d2\u5165\uff0c\u9002\u5408\u4e2d\u5c0f\u89c4\u6a21\u8fde\u63a5\u7ba1\u7406\uff0c\u4f46\u5728\u9ad8\u9891\u66f4\u65b0\u6216\u6d77\u91cf\u8fde\u63a5\u573a\u666f\u53ef\u80fd\u5b58\u5728\u6027\u80fd\u74f6\u9888\u3002\u76f8\u6bd4\u66f4\u9ad8\u6548\u7684\u65f6\u95f4\u8f6e","og_url":"https:\/\/www.wsisp.com\/helps\/55448.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-13T14:34:53+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/55448.html","url":"https:\/\/www.wsisp.com\/helps\/55448.html","name":"\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u5b9e\u4f8b\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-13T14:34:53+00:00","dateModified":"2025-08-13T14:34:53+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/55448.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/55448.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/55448.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u5b9e\u4f8b\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/55448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=55448"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/55448\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=55448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=55448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=55448"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=55448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}