{"id":3722,"date":"2022-12-30T13:50:18","date_gmt":"2022-12-30T05:50:18","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3722"},"modified":"2022-12-30T13:50:18","modified_gmt":"2022-12-30T05:50:18","slug":"%e6%b7%b1%e5%85%a5%e6%8e%a2%e7%b4%a2go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84%e5%a0%86","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/go\/%e6%b7%b1%e5%85%a5%e6%8e%a2%e7%b4%a2go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84%e5%a0%86\/","title":{"rendered":"\u6df1\u5165\u63a2\u7d22Go\u8a9e\u8a00\u4e2d\u7684\u5806"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Go, \u5806\"><\/p>\n<p>Go \u8a9e\u8a00\u7684\u5806\u662f\u4e00\u500b\u91cd\u8981\u7684\u8cc7\u6599\u7d50\u69cb\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u5730\u5efa\u7acb\u548c\u7ba1\u7406\u8cc7\u6599\u3002\u5806\u662f\u4e00\u7a2e\u5b8c\u5168\u4e8c\u5143\u6a39\uff0c\u5176\u4e2d\u6bcf\u500b\u7bc0\u9ede\u90fd\u6709\u4e00\u500b\u503c\uff0c\u4e26\u4e14\u6bcf\u500b\u7bc0\u9ede\u7684\u503c\u90fd\u5927\u65bc\u6216\u7b49\u65bc\u5176\u5b50\u7bc0\u9ede\u7684\u503c\u3002\u5806\u7684\u6700\u5927\u512a\u9ede\u662f\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u5730\u67e5\u627e\u6700\u5927\u6216\u6700\u5c0f\u7684\u503c\uff0c\u800c\u4e0d\u9700\u8981\u904d\u6b77\u6574\u500b\u6a39\u3002<\/p>\n<p>Go \u8a9e\u8a00\u7684\u5806\u53ef\u4ee5\u4f7f\u7528\u5169\u7a2e\u65b9\u5f0f\u4f86\u5efa\u7acb\uff1a\u6700\u5927\u5806\u548c\u6700\u5c0f\u5806\u3002\u6700\u5927\u5806\u662f\u4e00\u7a2e\u5b8c\u5168\u4e8c\u5143\u6a39\uff0c\u5176\u4e2d\u6bcf\u500b\u7bc0\u9ede\u7684\u503c\u90fd\u5927\u65bc\u6216\u7b49\u65bc\u5176\u5b50\u7bc0\u9ede\u7684\u503c\u3002\u6700\u5c0f\u5806\u5247\u662f\u4e00\u7a2e\u5b8c\u5168\u4e8c\u5143\u6a39\uff0c\u5176\u4e2d\u6bcf\u500b\u7bc0\u9ede\u7684\u503c\u90fd\u5c0f\u65bc\u6216\u7b49\u65bc\u5176\u5b50\u7bc0\u9ede\u7684\u503c\u3002<\/p>\n<p><!--more--><\/p>\n<p>Go \u8a9e\u8a00\u7684\u5806\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\u4f86\u5efa\u7acb\uff1a<\/p>\n<pre class=\"brush: go\">\npackage main\n\nimport (\n    \"container\/heap\"\n)\n\n\/\/ An IntHeap is a min-heap of ints.\ntype IntHeap []int\n\nfunc (h IntHeap) Len() int           { return len(h) }\nfunc (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }\nfunc (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }\n\nfunc (h *IntHeap) Push(x interface{}) {\n    \/\/ Push and Pop use pointer receivers because they modify the slice's length,\n    \/\/ not just its contents.\n    *h = append(*h, x.(int))\n}\n\nfunc (h *IntHeap) Pop() interface{} {\n    old := *h\n    n := len(old)\n    x := old[n-1]\n    *h = old[0 : n-1]\n    return x\n}\n\n\/\/ This example inserts several ints into an IntHeap, checks the minimum,\n\/\/ and removes them in order of priority.\nfunc main() {\n    h := &#038;IntHeap{2, 1, 5}\n    heap.Init(h)\n    heap.Push(h, 3)\n    fmt.Printf(\"minimum: %d\\n\", (*h)[0])\n    for h.Len() > 0 {\n        fmt.Printf(\"%d \", heap.Pop(h))\n    }\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u5efa\u7acb\u4e86\u4e00\u500b\u6700\u5c0f\u5806\uff0c\u4e26\u4e14\u53ef\u4ee5\u67e5\u627e\u6700\u5c0f\u503c\uff0c\u4ee5\u53ca\u6309\u7167\u512a\u5148\u9806\u5e8f\u522a\u9664\u5143\u7d20\u3002<\/p>\n<p>Go \u8a9e\u8a00\u7684\u5806\u9084\u53ef\u4ee5\u7528\u65bc\u6392\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\u4f86\u5be6\u73fe\uff1a<\/p>\n<pre class=\"brush: go\">\npackage main\n\nimport (\n    \"container\/heap\"\n    \"fmt\"\n)\n\n\/\/ An IntHeap is a min-heap of ints.\ntype IntHeap []int\n\nfunc (h IntHeap) Len() int           { return len(h) }\nfunc (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }\nfunc (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }\n\nfunc (h *IntHeap) Push(x interface{}) {\n    \/\/ Push and Pop use pointer receivers because they modify the slice's length,\n    \/\/ not just its contents.\n    *h = append(*h, x.(int))\n}\n\nfunc (h *IntHeap) Pop() interface{} {\n    old := *h\n    n := len(old)\n    x := old[n-1]\n    *h = old[0 : n-1]\n    return x\n}\n\n\/\/ This example sorts a slice of ints using a heap.\nfunc main() {\n    h := &#038;IntHeap{2, 1, 5}\n    heap.Init(h)\n    heap.Push(h, 3)\n    fmt.Printf(\"minimum: %d\\n\", (*h)[0])\n    for h.Len() > 0 {\n        fmt.Printf(\"%d \", heap.Pop(h))\n    }\n    \/\/ Output: 1 2 3 5\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4f7f\u7528\u5806\u4f86\u5c0d\u4e00\u500b\u6574\u6578\u5207\u7247\u9032\u884c\u6392\u5e8f\uff0c\u8f38\u51fa\u7d50\u679c\u70ba 1 2 3 5\u3002<\/p>\n<p>Go \u8a9e\u8a00\u7684\u5806\u662f\u4e00\u500b\u975e\u5e38\u6709\u7528\u7684\u8cc7\u6599\u7d50\u69cb\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u5730\u5efa\u7acb\u548c\u7ba1\u7406\u8cc7\u6599\uff0c\u4e26\u4e14\u53ef\u4ee5\u7528\u65bc\u67e5\u627e\u6700\u5927\u6216\u6700\u5c0f\u7684\u503c\uff0c\u4ee5\u53ca\u6392\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eGo\u8a9e\u8a00\u4e2d\u7684\u5806\uff0c\u8a73\u7d30\u4ecb\u7d39\u5806\u7684\u6982\u5ff5\u3001\u5806\u7684\u64cd\u4f5c\u3001\u5806\u7684\u61c9\u7528\u7b49\uff0c\u8b93\u8b80\u8005\u66f4\u52a0\u4e86\u89e3Go\u8a9e\u8a00\u4e2d\u7684\u5806\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[171,172],"tags":[169,170],"class_list":["post-3722","post","type-post","status-publish","format-standard","hentry","category-go","category-golang","tag-go","tag-golang"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-Y2","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=3722"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3722\/revisions"}],"predecessor-version":[{"id":3723,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3722\/revisions\/3723"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}