{"id":4009,"date":"2023-11-02T14:08:19","date_gmt":"2023-11-02T06:08:19","guid":{"rendered":"https:\/\/white-night.club\/?p=4009"},"modified":"2024-02-24T09:14:52","modified_gmt":"2024-02-24T01:14:52","slug":"pg22","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/02\/pg22\/","title":{"rendered":"MIT6.5830 Lab1-GoDB\u5b9e\u9a8c\u8bb0\u5f55\uff08\u4e03\uff09"},"content":{"rendered":"\n<p>\u84b8\u84b8\u65e5\u4e0a\u3002\u770b\u770b\u80fd\u4e0d\u80fd\u4e00\u6b21\u5b9e\u9a8c\u8bb0\u5f55\u5c31\u5b8c\u6210Exercise 4\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u5b9e\u9a8c\u8bb0\u5f55<\/p>\n<cite><em>NewHeapFile<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5b8c\u4e8b\u5f00\u5934\u96be\uff0c\u5bf9\u4e8eheap_file\u800c\u8a00\u4e5f\u4e00\u6837\u3002<\/p>\n\n\n\n<p>\u521b\u5efa\u65b0\u7684\u5806\u6587\u4ef6\uff1f\u4e0d\u592a\u61c2\uff0c\u5148\u6765\u770b\u770bheapfile\u7684\u7ed3\u6784<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"type HeapFile struct {\n\t\/\/ TODO: some code goes here\n\t\/\/ HeapFile should include the fields below;  you may want to add\n\t\/\/ additional fields\n\tbufPool *BufferPool\n\tsync.Mutex\n\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">type<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">HeapFile<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">struct<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ HeapFile should include the fields below;  you may want to add<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ additional fields<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tbufPool *BufferPool<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tsync.Mutex<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u4e00\u4e2a\u4e92\u65a5\u9501\u548c\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684BufferPool\uff0c\u800cBufferPool\u662f\u4ec0\u4e48\uff1f\u5728\u4e0b\u9762\u7684\u6ce8\u91ca\u6709\u63d0\u5230<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ - bp: the BufferPool that is used to store pages read from the HeapFile\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ - bp: the BufferPool that is used to store pages read from the HeapFile<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u90a3\u4e48heapfile\u901a\u8fc7bufPool\u7ba1\u7406\u591a\u4e2a\u9875\uff0c\u5927\u6982\u61c2\u4e86\u4e4b\u540e\u63a5\u4e0b\u6765\u5c31\u6765\u5b9e\u73b0NewHeapFile\u3002\u770b\u4e0b\u6ce8\u91ca\uff0cheapfile\u6709\u5b57\u6bb5\uff0c\u6709HeapFile\u7684\u6587\u4ef6\u540d\uff0c\u90a3\u4e48\u8fd8\u5f97\u5f80heapfile\u7684struct\u91cc\u5934\u52a0\u70b9\u4e1c\u897f\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"type HeapFile struct {\n\t\/\/ TODO: some code goes here\n\t\/\/ HeapFile should include the fields below;  you may want to add\n\t\/\/ additional fields\n\tbufPool *BufferPool\n\tsync.Mutex\n\tDesc     *TupleDesc\n\tFromFile string\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">type<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">HeapFile<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">struct<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ HeapFile should include the fields below;  you may want to add<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ additional fields<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tbufPool *BufferPool<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tsync.Mutex<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tDesc     *TupleDesc<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tFromFile <\/span><span style=\"color: #4EC9B0\">string<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u90a3NewHeapFile\u4e5f\u5f88\u597d\u5199\u4e86\uff0c\u6ce8\u91ca\u91cc\u8fd8\u63d0\u5230\u5982\u679cfromFile\u4e0d\u5b58\u5728\u8bf4\u660edb\u8fd8\u6ca1\u6709heapFile\uff0c\u90a3\u6211\u4eec\u8fd8\u9700\u8981\u81ea\u5df1\u65b0\u5efa\u4e00\u4e2afromFile\u3002\u7136\u540e\u6211\u4eec\u76f4\u63a5\u8fd4\u56de\u5373\u53ef\u3002\u522b\u5fd8\u4e86file.close()\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func NewHeapFile(fromFile string, td *TupleDesc, bp *BufferPool) (*HeapFile, error) {\n\t\/\/ TODO: some code goes here\n\tfile, _ := os.OpenFile(fromFile, os.O_RDWR|os.O_CREATE, 0666)\n\tdefer file.Close()\n\treturn &amp;HeapFile{FromFile: fromFile, Desc: td, bufPool: bp}, nil \/\/replace me\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">NewHeapFile<\/span><span style=\"color: #D4D4D4\">(fromFile <\/span><span style=\"color: #4EC9B0\">string<\/span><span style=\"color: #D4D4D4\">, td *TupleDesc, bp *BufferPool) (*HeapFile, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">file<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> := os.<\/span><span style=\"color: #DCDCAA\">OpenFile<\/span><span style=\"color: #D4D4D4\">(fromFile, os.O_RDWR|os.O_CREATE, <\/span><span style=\"color: #B5CEA8\">0666<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">defer<\/span><span style=\"color: #D4D4D4\"> file.<\/span><span style=\"color: #DCDCAA\">Close<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> &amp;HeapFile{FromFile: fromFile, Desc: td, bufPool: bp}, <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #6A9955\">\/\/replace me<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u63a5\u4e0b\u6765\u662fNumPages\uff0c\u600e\u4e48\u8ba1\u7b97heapfile\u4e2d\u6709\u591a\u5c11\u9875\u5462\uff1f\u6211\u60f3\u7684\u662f\u76f4\u63a5\u4eceBufferPool\u62ff\u4e0d\u5c31\u597d\u4e86&#8230;.\u4f46markdown\u91cc\u9762\u5199\u4e86\u8981\u6c42\uff0c\u8981\u6211\u4eec\u901a\u8fc7fromFile\u7684\u6587\u4ef6\u5927\u5c0f\uff08File.Stat)\u8ba1\u7b97\u5f97\u5230numpages\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u6211\u5c31\u5728\u8fd9\u4e0a\u9762\u82b1\u4e86\u4e00\u5929\u7684\u65f6\u95f4\u4feebug\uff0c\u63a5\u4e0b\u6765\u6162\u6162\u8bb2\u5427\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u5b9e\u9a8cbug\u4fee\u6b63<\/p>\n<cite><em>numpages=0<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u7b97numpages\u4e0d\u96be\u3002\u4ee3\u7801\u5f88\u7b80\u5355\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *HeapFile) NumPages() int {\n\t\/\/ TODO: some code goes here\n\tfileInfo, err := os.Stat(f.FromFile)\n\tif err == nil {\n\t\tfilesize := int(fileInfo.Size())\n\t\treturn filesize \/ PageSize\n\t}\n\treturn 0 \/\/replace me\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *HeapFile) <\/span><span style=\"color: #DCDCAA\">NumPages<\/span><span style=\"color: #D4D4D4\">() <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">fileInfo<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := os.<\/span><span style=\"color: #DCDCAA\">Stat<\/span><span style=\"color: #D4D4D4\">(f.FromFile)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">filesize<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">int<\/span><span style=\"color: #D4D4D4\">(fileInfo.<\/span><span style=\"color: #DCDCAA\">Size<\/span><span style=\"color: #D4D4D4\">())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> filesize \/ PageSize<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #6A9955\">\/\/replace me<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u4f46\u662f\u6211\u53d1\u73b0\u4e0d\u7ba1\u600e\u4e48\u7b97numpages\u4e00\u76f4\u662f0\uff0c\u51e0\u6b21debug\u4e4b\u540e\u6211\u53d1\u73b0pagesize\u80af\u5b9a\u6ca1\u95ee\u9898\uff0c\u4e00\u76f4\u662f4096\u3002\u90a3\u4e48\u95ee\u9898\u5c31\u5728\u4e8eint(filesize)\/pagesize\u8fd9\u4e00\u6b65\u3002<\/p>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u662f0\uff1f\u65e2\u7136pagesize\u4e0d\u4e3a0\u90a3\u53ea\u6709\u53ef\u80fd\u662ffilesize\u4e3a0\u3002\u5f53\u7136\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5f80\u540e\u5199\u7684\u8bddpagesize\u80af\u5b9a\u662f0\u3002\u4f46\u662f\u6211debug\u4e4b\u540e\u53d1\u73b0pagesize=48\uff0c\u8bf4\u660epagesize\u4e5f\u4e0d\u7b49\u4e8e0\u3002\u90a3\u4e48<mark style=\"background-color:rgba(0, 0, 0, 0);color:#fcb900\" class=\"has-inline-color\">\u95ee\u9898\u5c31\u51fa\u5728\u4e24\u4e2a\u6570\u76f8\u9664\u8fd9\u91cc<\/mark>\u3002<\/p>\n\n\n\n<p>\u4e8e\u662f\u6211\u60f3\u4e86\u60f3\uff0c\u5728\u4e0a\u4e00\u8282\u7684heap_page\u4e2d\uff0c\u6211\u4eec\u662f\u600e\u4e48\u628atuple\u5199\u5165\u7f13\u51b2\u533a\uff0c\u53c8\u8bfb\u53d6\u7f13\u51b2\u533a\u7684\uff1f<\/p>\n\n\n\n<p>\u6309\u6211\u4e0a\u4e00\u8282\u7684\u601d\u8def\uff0c\u6709\u591a\u5c11\u8bb0\u5f55\u5c31\u5199\u591a\u5c11\u8bb0\u5f55\u3002\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c<mark style=\"background-color:rgba(0, 0, 0, 0);color:#fcb900\" class=\"has-inline-color\">heap page\u6700\u540e\u4e00\u5b9a\u67094096\u5b57\u8282\u5417\uff1f\u4e0d\u4e00\u5b9a\uff0c\u4e0d\u662f\u5417\uff1f<\/mark>\u6709\u591a\u5c11\u5199\u591a\u5c11\uff0c\u90a3\u5269\u4e0b\u7684\u7a7a\u95f4\u5b8c\u5168\u5c31\u662f\u7a7a\u7684\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u8fd8\u9700\u8981\u5728\u5269\u4e0b\u7684\u4f4d\u7f6e\u586b\u4e0a0\u8865\u5168page\u76f4\u5230\u5b83\u67094096\u5b57\u8282\u3002\u4e14\u8bfb\u53d6\u7684\u65f6\u5019\u53ea\u8bfb\u53d6\u6709\u6548\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u6211\u4eec\u9700\u8981\u4fee\u6539\u8bfb\u5199\u7f13\u51b2\u533a\u7684\u4e24\u4e2a\u51fd\u6570\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\u5b9e\u9a8c\u63d0\u5230\u4e86\uff1a\u4ece\u7f13\u51b2\u533a\u8bfb\u56de\u8bb0\u5f55\u7684\u65f6\u5019\uff0crid\u4e0d\u4e00\u5b9a\u548c\u5199\u5165\u8bb0\u5f55\u7684rid\u76f8\u7b49\uff0c\u4e3b\u8981\u662f\u56e0\u4e3atuple\u672c\u8eab\u5c31\u662f\u65e0\u5e8f\u5b58\u653e\u5728heap_page\u91cc\u7684\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-cyan-blue-color has-text-color\">\n<p>\u5199\u8005\u6ce8<\/p>\n<cite>\u4e00\u4e2apage\u5199\u5165buffer\u4e4b\u540e\uff0c\u8be5buffer\u53ef\u80fd\u7531\u5176\u5b83\u65b0\u7684page\u6765\u8bfb\u53d6\u3002\u6240\u4ee5\u4e0d\u80fd\u901a\u8fc7\u5728page\u7ed3\u6784\u4e2d\u52a0\u4e00\u4e2ausefulBytes\u6765\u5224\u65ad\u54ea\u4e9b\u6570\u636e\u6709\u6548&#8211;\u56e0\u4e3a\u5176\u5b83\u65b0\u7684page\u62ff\u4e0d\u5230\u8fd9\u4e2a\u503c\u3002<\/cite><\/blockquote>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (h *heapPage) toBuffer() (*bytes.Buffer, error) {\n\t\/\/ TODO: some code goes here\n\tbytesBuffer := new(bytes.Buffer)\n\terr := binary.Write(bytesBuffer, binary.LittleEndian, h.Hdr)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tfor _, tuple := range h.Tuple {\n\t\tif tuple != nil {\n\t\t\terr := tuple.writeTo(bytesBuffer)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\t}\n\tpaddingSize := 4096 - bytesBuffer.Len()\n\tpaddingBytes := make([]byte, paddingSize)\n\t_, err = bytesBuffer.Write(paddingBytes)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn bytesBuffer, nil \/\/replace me\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (h *heapPage) <\/span><span style=\"color: #DCDCAA\">toBuffer<\/span><span style=\"color: #D4D4D4\">() (*bytes.Buffer, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">bytesBuffer<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">new<\/span><span style=\"color: #D4D4D4\">(bytes.Buffer)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := binary.<\/span><span style=\"color: #DCDCAA\">Write<\/span><span style=\"color: #D4D4D4\">(bytesBuffer, binary.LittleEndian, h.Hdr)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">tuple<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #C586C0\">range<\/span><span style=\"color: #D4D4D4\"> h.Tuple {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> tuple != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := tuple.<\/span><span style=\"color: #DCDCAA\">writeTo<\/span><span style=\"color: #D4D4D4\">(bytesBuffer)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">paddingSize<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">4096<\/span><span style=\"color: #D4D4D4\"> - bytesBuffer.<\/span><span style=\"color: #DCDCAA\">Len<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">paddingBytes<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">make<\/span><span style=\"color: #D4D4D4\">([]<\/span><span style=\"color: #4EC9B0\">byte<\/span><span style=\"color: #D4D4D4\">, paddingSize)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> = bytesBuffer.<\/span><span style=\"color: #DCDCAA\">Write<\/span><span style=\"color: #D4D4D4\">(paddingBytes)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> bytesBuffer, <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #6A9955\">\/\/replace me<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u6211\u505a\u5b8c\u4e4b\u540e\u53d1\u73b0initFromBuffer\u8fd8\u6709\u4e2abug\u3002\u4e4b\u524d\u8bfb\u53d6\u7684\u65f6\u5019\u9519\u8bef\u7684\u521d\u59cb\u5316\u4e86Rid\uff0c\u5bfc\u81f4\u4ece\u78c1\u76d8\u4e2d\u8bfb\u53d6\u7684\u7b2c\u4e00\u4e2arid\u4f1a\u53d8\u6210\u4e86int\u7c7b\u578b\u7684\u503c\u3002\u5bfc\u81f4\u6ca1\u6cd5\u83b7\u53d6\u5230\u9875\u53f7pageNo\u3002\u65b0\u5efa\u4e00\u4e2aRecordID\u5bf9\u8c61\u7136\u540e\u521d\u59cb\u5316\u5373\u53ef\u3002<\/p>\n\n\n\n<p>rid\u53ef\u4ee5\u4e0d\u7528\u548c\u5199\u5165\u7684\u65f6\u5019\u4e00\u6837\uff0c\u6240\u4ee5\u76f4\u63a5SlotNo\u76f4\u63a5\u53d6i\u5c31\u884c\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(234, 191, 191, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (h *heapPage) initFromBuffer(buf *bytes.Buffer) error {\n\t\/\/ TODO: some code goes here\n\terr := binary.Read(buf, binary.LittleEndian, &amp;h.Hdr)\n\tif err != nil {\n\t\treturn err\n\t}\n\tfor i := 0; i &lt; int(h.Hdr.UsedSlots); i++ {\n\t\ttuple, err := readTupleFrom(buf, h.Desc)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\th.Tuple[i] = tuple\n\t\trid := RecordID{PageNo: h.PageNo, SlotNo: i}\n\t\th.Tuple[i].Rid = rid\n\t}\n\treturn nil \/\/replace me\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (h *heapPage) <\/span><span style=\"color: #DCDCAA\">initFromBuffer<\/span><span style=\"color: #D4D4D4\">(buf *bytes.Buffer) <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := binary.<\/span><span style=\"color: #DCDCAA\">Read<\/span><span style=\"color: #D4D4D4\">(buf, binary.LittleEndian, &amp;h.Hdr)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">; i &lt; <\/span><span style=\"color: #DCDCAA\">int<\/span><span style=\"color: #D4D4D4\">(h.Hdr.UsedSlots); i++ {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">tuple<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">readTupleFrom<\/span><span style=\"color: #D4D4D4\">(buf, h.Desc)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\th.Tuple[i] = tuple<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">rid<\/span><span style=\"color: #D4D4D4\"> := RecordID{PageNo: h.PageNo, SlotNo: i}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\th.Tuple[i].<\/span><span style=\"color: #9CDCFE\">Rid<\/span><span style=\"color: #D4D4D4\"> = rid<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #6A9955\">\/\/replace me<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u7136\u540e\u81ea\u5df1\u5728heap_file_test\u4e2d\u5199\u4e00\u4e2atest\u8bd5\u8bd5\uff0c\u770b\u770b\u80fd\u4e0d\u80fd\u62ff\u5230numpage=1\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func TestNumPage(t *testing.T) {\n\tvar td = TupleDesc{Fields: []FieldType{\n\t\t{Fname: &quot;name&quot;, Ftype: StringType},\n\t\t{Fname: &quot;age&quot;, Ftype: IntType},\n\t}}\n\tbp := NewBufferPool(3)\n\tos.Remove(TestingFile)\n\thf, _ := NewHeapFile(TestingFile, &amp;td, bp)\n\tvar t1 = Tuple{\n\t\tDesc: td,\n\t\tFields: []DBValue{\n\t\t\tStringField{&quot;sam&quot;},\n\t\t\tIntField{25},\n\t\t}}\n\thf.insertTuple(&amp;t1, NewTID())\n\tfmt.Println(hf.NumPages())\n\t_ = hf\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">TestNumPage<\/span><span style=\"color: #D4D4D4\">(t *testing.T) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">td<\/span><span style=\"color: #D4D4D4\"> = TupleDesc{Fields: []FieldType{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t{Fname: <\/span><span style=\"color: #CE9178\">&quot;name&quot;<\/span><span style=\"color: #D4D4D4\">, Ftype: StringType},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t{Fname: <\/span><span style=\"color: #CE9178\">&quot;age&quot;<\/span><span style=\"color: #D4D4D4\">, Ftype: IntType},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">bp<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">NewBufferPool<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tos.<\/span><span style=\"color: #DCDCAA\">Remove<\/span><span style=\"color: #D4D4D4\">(TestingFile)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">hf<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">NewHeapFile<\/span><span style=\"color: #D4D4D4\">(TestingFile, &amp;td, bp)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">t1<\/span><span style=\"color: #D4D4D4\"> = Tuple{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tDesc: td,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tFields: []DBValue{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\tStringField{<\/span><span style=\"color: #CE9178\">&quot;sam&quot;<\/span><span style=\"color: #D4D4D4\">},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\tIntField{<\/span><span style=\"color: #B5CEA8\">25<\/span><span style=\"color: #D4D4D4\">},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\thf.<\/span><span style=\"color: #DCDCAA\">insertTuple<\/span><span style=\"color: #D4D4D4\">(&amp;t1, <\/span><span style=\"color: #DCDCAA\">NewTID<\/span><span style=\"color: #D4D4D4\">())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tfmt.<\/span><span style=\"color: #DCDCAA\">Println<\/span><span style=\"color: #D4D4D4\">(hf.<\/span><span style=\"color: #DCDCAA\">NumPages<\/span><span style=\"color: #D4D4D4\">())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> = hf<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u80fd\u62ff\u5230\uff0c\u8bf4\u660e\u95ee\u9898\u89e3\u51b3\u3002\u540c\u65f6\u6211\u5728\u68c0\u67e5\u7684\u65f6\u5019\u53d1\u73b0insertTuple\u4e2d\u9ad8\u4eae\u7684\u5730\u65b9\u6ca1\u5199return\u5bfc\u81f4\u5faa\u73af\u6267\u884c\u591a\u6b21\uff0c\u6240\u4ee5\u8fd9\u91cc\u4e5f\u4fee\u6539\u4e00\u4e0b\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Insert the tuple into a free slot on the page, or return an error if there are\n\/\/ no free slots.  Set the tuples rid and return it.\nfunc (h *heapPage) insertTuple(t *Tuple) (recordID, error) {\n\t\/\/ TODO: some code goes here\n\trid := RecordID{PageNo: h.PageNo, SlotNo: 0}\n\tif h.Hdr.UsedSlots == h.Hdr.TotalSlots {\n\t\treturn rid, errors.New(&quot;no free slots&quot;)\n\t}\n\tfor i, tuple := range h.Tuple {\n\t\tif tuple == nil {\n\t\t\th.Tuple[i] = t\n\t\t\trid.SlotNo = i\n\t\t\th.Tuple[i].Rid = rid\n\t\t\th.Hdr.UsedSlots += 1\n\t\t\treturn rid, nil\n\t\t}\n\t}\n\treturn rid, errors.New(&quot;Can't insert Tuple&quot;) \/\/replace me\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ Insert the tuple into a free slot on the page, or return an error if there are<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ no free slots.  Set the tuples rid and return it.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (h *heapPage) <\/span><span style=\"color: #DCDCAA\">insertTuple<\/span><span style=\"color: #D4D4D4\">(t *Tuple) (recordID, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">rid<\/span><span style=\"color: #D4D4D4\"> := RecordID{PageNo: h.PageNo, SlotNo: <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> h.Hdr.UsedSlots == h.Hdr.TotalSlots {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> rid, errors.<\/span><span style=\"color: #DCDCAA\">New<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;no free slots&quot;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">tuple<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #C586C0\">range<\/span><span style=\"color: #D4D4D4\"> h.Tuple {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> tuple == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\th.Tuple[i] = t<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">rid.SlotNo<\/span><span style=\"color: #D4D4D4\"> = i<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\th.Tuple[i].<\/span><span style=\"color: #9CDCFE\">Rid<\/span><span style=\"color: #D4D4D4\"> = rid<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\th.Hdr.UsedSlots += <\/span><span style=\"color: #B5CEA8\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> rid, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> rid, errors.<\/span><span style=\"color: #DCDCAA\">New<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;Can&#39;t insert Tuple&quot;<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\">\/\/replace me<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u63a5\u4e0b\u6765\u7ee7\u7eed\u5b9e\u9a8c\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-cyan-blue-color has-text-color\">\n<p>\u5199\u8005\u6ce8<\/p>\n<cite>\u867d\u7136\u8fd9\u6bb5\u5199\u7684\u5f88\u5c11\uff0c\u4f46\u6211\u771f\u7684\u82b1\u4e866\u4e2a\u5c0f\u65f6\u591a\u7684\u65f6\u95f4\u53cd\u590ddebug\u3002bufferpool.getPage()\u4e4b\u7c7b\u7684\u9519\u8bef\u771f\u7684\u5f88\u96be\u627e\u51fa\u6765\uff0c\u4e0d\u8fc7debug\u5b8c\u4e4b\u540e\u6211\u5bf9godb\u7684\u7406\u89e3\u4e5f\u66f4\u6df1\u4e86\u5012\u662f\u771f\u7684\u3002<\/cite><\/blockquote>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u5b9e\u9a8c\u6b65\u9aa4<\/p>\n<cite>getPage<\/cite><\/blockquote>\n\n\n\n<p>\u5728\u6b64\u4e4b\u524d\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u56de\u5230buffer_pool\u4e2d\u8865\u5168\u51e0\u6bb5\u4ee3\u7801\u3002\u56e0\u4e3a\u6211\u4eec\u63a5\u4e0b\u6765\u7684\u64cd\u4f5c\u90fd\u8981\u548cbufferpool\u6253\u4ea4\u9053\u3002<\/p>\n\n\n\n<p>\u4ecegetPage\u7684\u6ce8\u91ca\u5165\u624b\uff0c\u518d\u5230pageKey\u7684\u6ce8\u91ca\uff0c\u53ef\u4ee5\u63a8\u51fabufferpool\u901a\u8fc7hashmap\u7684\u65b9\u5f0f\u5b58\u50a8\u4e0d\u540c\u7684heappage\u3002\u5176\u4e2dkey\u7684\u7c7b\u578b\u4e3aheaphash\u3002<\/p>\n\n\n\n<p>\u4f46\u662fpageKey\u8fd4\u56de\u7684\u662fany\uff0c\u6240\u4ee5\u6211\u4eec\u8fd8\u662f\u9009any\u7c7b\u578b\u4f5c\u4e3akey\u3002\u6240\u4ee5\u6240\u4ee5bp\u7684\u7ed3\u6784\u548c\u521d\u59cb\u5316\u5e94\u8be5\u4e3a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"type BufferPool struct {\n\t\/\/ TODO: some code goes here\n\tNumPages int\n\tPages    map[any]*Page\n}\n\n\/\/ Create a new BufferPool with the specified number of pages\nfunc NewBufferPool(numPages int) *BufferPool {\n\t\/\/ TODO: some code goes here\n\treturn &amp;BufferPool{NumPages: numPages, Pages: make(map[any]*Page, numPages)}\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">type<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">BufferPool<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">struct<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tNumPages <\/span><span style=\"color: #4EC9B0\">int<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tPages    <\/span><span style=\"color: #569CD6\">map<\/span><span style=\"color: #D4D4D4\">[any]*Page<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ Create a new BufferPool with the specified number of pages<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">NewBufferPool<\/span><span style=\"color: #D4D4D4\">(numPages <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">) *BufferPool {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> &amp;BufferPool{NumPages: numPages, Pages: <\/span><span style=\"color: #DCDCAA\">make<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">map<\/span><span style=\"color: #D4D4D4\">[any]*Page, numPages)}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u987a\u5e26\u8865\u5168pageKey<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *HeapFile) pageKey(pgNo int) any {\n\n\t\/\/ TODO: some code goes here\n\thH := heapHash{FileName: f.FromFile, PageNo: pgNo}\n\treturn hH\n\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *HeapFile) <\/span><span style=\"color: #DCDCAA\">pageKey<\/span><span style=\"color: #D4D4D4\">(pgNo <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">) any {<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">hH<\/span><span style=\"color: #D4D4D4\"> := heapHash{FileName: f.FromFile, PageNo: pgNo}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> hH<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u63a5\u4e0b\u6765\u8865\u5168getPage\u3002\u5982\u679c\u7f13\u51b2\u6c60\u6ca1\u6709page\uff0c\u90a3\u5c31\u7ed9\u5bf9\u5e94\u7684\u4e0b\u6807\u521d\u59cb\u5316\u4e00\u4e2apage\u3002\u800c\u7f13\u51b2\u6c60\u7684\u5927\u5c0f\u6709NumPages\u51b3\u5b9a\u3002\u4e5f\u5c31\u662f\u8bf4\u8fd9\u4e2a\u7f13\u51b2\u6c60\u6700\u591a\u5b583\u9875\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (bp *BufferPool) GetPage(file DBFile, pageNo int, tid TransactionID, perm RWPerm) (*Page, error) {\n\t\/\/ TODO: some code goes here\n\tkey := file.pageKey(pageNo)\n\tif bp.Pages[key] == nil {\n\t\tpage, err := file.readPage(pageNo)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tbp.Pages[key] = page\n\t\treturn bp.Pages[key], nil\n\t} else {\n\t\treturn bp.Pages[key], nil\n\t}\n\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (bp *BufferPool) <\/span><span style=\"color: #DCDCAA\">GetPage<\/span><span style=\"color: #D4D4D4\">(file DBFile, pageNo <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">, tid TransactionID, perm RWPerm) (*Page, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">key<\/span><span style=\"color: #D4D4D4\"> := file.<\/span><span style=\"color: #DCDCAA\">pageKey<\/span><span style=\"color: #D4D4D4\">(pageNo)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> bp.Pages[key] == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">page<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := file.<\/span><span style=\"color: #DCDCAA\">readPage<\/span><span style=\"color: #D4D4D4\">(pageNo)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tbp.Pages[key] = page<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> bp.Pages[key], <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t} <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> bp.Pages[key], <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u81f3\u4e8e\u9501\u548c\u9a71\u9010\u7b97\u6cd5\u6211\u51b3\u5b9a\u5148\u4e0d\u7ba1\u3002\u7b49\u540e\u7eed\u7684lab\u5b9e\u73b0\u4e8b\u52a1\u7684\u65f6\u5019\u518d\u4e00\u8d77\u5904\u7406\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u5b9e\u9a8c\u6b65\u9aa4<\/p>\n<cite><em>\u5b8c\u6210heap_file<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u8981\u60f3\u8dd1\u901aheap_file_test.go\u7684\u5168\u90e8test\uff0c\u8fd8\u6709\u201c\u4ebf\u201d\u4e9b\u4ee3\u7801\u8981\u8865\u5168\u3002<\/p>\n\n\n\n<p>readPage\u8fd8\u597d\uff0c\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u4ece\u78c1\u76d8\u8bfbpage\u3002\u7531\u4e8e\u6bcf\u9875\u90fd\u4e00\u5b9a\u662f4096\u5927\u5c0f\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u4ece\u6307\u5b9a\u4e0b\u6807\u5f00\u59cb\u8bfb\u53d6\u6307\u5b9a\u9875\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *HeapFile) readPage(pageNo int) (*Page, error) {\n\t\/\/ TODO: some code goes here\n\tfile, _ := os.OpenFile(f.FromFile, os.O_RDWR|os.O_CREATE, 0666)\n\tdefer file.Close()\n\tbytesBuffer := make([]byte, PageSize)\n\t_, err := file.ReadAt(bytesBuffer, int64(pageNo*PageSize))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\thp := newHeapPage(f.Desc, pageNo, f)\n\thp.initFromBuffer(bytes.NewBuffer(bytesBuffer))\n\tvar page Page = hp\n\treturn &amp;page, nil\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *HeapFile) <\/span><span style=\"color: #DCDCAA\">readPage<\/span><span style=\"color: #D4D4D4\">(pageNo <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">) (*Page, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">file<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> := os.<\/span><span style=\"color: #DCDCAA\">OpenFile<\/span><span style=\"color: #D4D4D4\">(f.FromFile, os.O_RDWR|os.O_CREATE, <\/span><span style=\"color: #B5CEA8\">0666<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">defer<\/span><span style=\"color: #D4D4D4\"> file.<\/span><span style=\"color: #DCDCAA\">Close<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">bytesBuffer<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">make<\/span><span style=\"color: #D4D4D4\">([]<\/span><span style=\"color: #4EC9B0\">byte<\/span><span style=\"color: #D4D4D4\">, PageSize)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := file.<\/span><span style=\"color: #DCDCAA\">ReadAt<\/span><span style=\"color: #D4D4D4\">(bytesBuffer, <\/span><span style=\"color: #DCDCAA\">int64<\/span><span style=\"color: #D4D4D4\">(pageNo*PageSize))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">hp<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">newHeapPage<\/span><span style=\"color: #D4D4D4\">(f.Desc, pageNo, f)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\thp.<\/span><span style=\"color: #DCDCAA\">initFromBuffer<\/span><span style=\"color: #D4D4D4\">(bytes.<\/span><span style=\"color: #DCDCAA\">NewBuffer<\/span><span style=\"color: #D4D4D4\">(bytesBuffer))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">page<\/span><span style=\"color: #D4D4D4\"> Page = hp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> &amp;page, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>insertTuple\u5c31\u8981\u8003\u8651\u8003\u8651\u4e86\u3002\u5982\u679c\u6570\u636e\u5e93\u6587\u4ef6\u662f\u7a7a\u7684\u90a3\u6211\u4eec\u5f97\u65b0\u5efa\u4e00\u4e2apage\u6254\u8fdbbp\uff0c\u518dbp\u4e2d\u5bf9page\u4f5c\u64cd\u4f5c\u3002\u6ce8\u91ca\u8fd8\u63d0\u5230\u8981\u628a\u5b83\u5199\u5165\u78c1\u76d8\uff08flushpage\uff09\uff0c\u6240\u4ee5\u4ee3\u7801\u5982\u4e0b<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *HeapFile) insertTuple(t *Tuple, tid TransactionID) error {\n\t\/\/ TODO: some code goes here\n\tinserted := false\n\tfor i := 0; i &lt; f.NumPages(); i++ {\n\t\tpg, err := f.bufPool.GetPage(f, i, tid, ReadPerm)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\thp := (*pg).(*heapPage)\n\t\tfor j := 0; j &lt; int(hp.Hdr.TotalSlots); j++ {\n\t\t\tif hp.Tuple[j] == nil {\n\t\t\t\thp.insertTuple(t)\n\t\t\t\tinserted = true\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\t}\n\tif !inserted {\n\t\t\/\/Create HeapPage, insert tuple, flush page\n\t\thp := newHeapPage(f.Desc, f.NumPages(), f)\n\t\thp.insertTuple(t)\n\t\tvar page Page = hp\n\t\tf.flushPage(&amp;page)\n\t}\n\treturn nil \/\/replace me\n\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *HeapFile) <\/span><span style=\"color: #DCDCAA\">insertTuple<\/span><span style=\"color: #D4D4D4\">(t *Tuple, tid TransactionID) <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">inserted<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #569CD6\">false<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">; i &lt; f.<\/span><span style=\"color: #DCDCAA\">NumPages<\/span><span style=\"color: #D4D4D4\">(); i++ {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">pg<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := f.bufPool.<\/span><span style=\"color: #DCDCAA\">GetPage<\/span><span style=\"color: #D4D4D4\">(f, i, tid, ReadPerm)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">hp<\/span><span style=\"color: #D4D4D4\"> := (*pg).(*heapPage)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">j<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">; j &lt; <\/span><span style=\"color: #DCDCAA\">int<\/span><span style=\"color: #D4D4D4\">(hp.Hdr.TotalSlots); j++ {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> hp.Tuple[j] == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\thp.<\/span><span style=\"color: #DCDCAA\">insertTuple<\/span><span style=\"color: #D4D4D4\">(t)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #9CDCFE\">inserted<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #569CD6\">true<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> !inserted {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #6A9955\">\/\/Create HeapPage, insert tuple, flush page<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">hp<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">newHeapPage<\/span><span style=\"color: #D4D4D4\">(f.Desc, f.<\/span><span style=\"color: #DCDCAA\">NumPages<\/span><span style=\"color: #D4D4D4\">(), f)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\thp.<\/span><span style=\"color: #DCDCAA\">insertTuple<\/span><span style=\"color: #D4D4D4\">(t)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">page<\/span><span style=\"color: #D4D4D4\"> Page = hp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tf.<\/span><span style=\"color: #DCDCAA\">flushPage<\/span><span style=\"color: #D4D4D4\">(&amp;page)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #6A9955\">\/\/replace me<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u5220\u9664tuple\u4e5f\u8fd8\u597d\u3002\u9996\u5148\u5220\u9664\u80af\u5b9a\u662f\u4ece\u5df2\u6709\u7684tuple\u4e2d\u6311\u4e00\u4e2a\u5220\u9664\u3002\u90a3\u4e48\u6211\u4eec\u53ea\u9700\u8981\u901a\u8fc7\u6bcf\u4e2atuple\u552f\u4e00\u4e0d\u91cd\u590d\u7684rid\u6765\u5224\u65ad\u5373\u53ef\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *HeapFile) deleteTuple(t *Tuple, tid TransactionID) error {\n\t\/\/ TODO: some code goes here\n\tfor i := 0; i &lt; f.NumPages(); i++ {\n\t\tpg, err := f.bufPool.GetPage(f, i, tid, ReadPerm)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\thp := (*pg).(*heapPage)\n\t\terr = hp.deleteTuple(t.Rid)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil \/\/replace me\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *HeapFile) <\/span><span style=\"color: #DCDCAA\">deleteTuple<\/span><span style=\"color: #D4D4D4\">(t *Tuple, tid TransactionID) <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">; i &lt; f.<\/span><span style=\"color: #DCDCAA\">NumPages<\/span><span style=\"color: #D4D4D4\">(); i++ {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">pg<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := f.bufPool.<\/span><span style=\"color: #DCDCAA\">GetPage<\/span><span style=\"color: #D4D4D4\">(f, i, tid, ReadPerm)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">hp<\/span><span style=\"color: #D4D4D4\"> := (*pg).(*heapPage)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> = hp.<\/span><span style=\"color: #DCDCAA\">deleteTuple<\/span><span style=\"color: #D4D4D4\">(t.Rid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #6A9955\">\/\/replace me<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u63a5\u4e0b\u6765\u5c31\u662fflushpage\u3002\u628apage\u5199\u5230\u78c1\u76d8\u4e0a\u3002\u6ca1\u5565\u80fd\u8bb2\u7684\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *HeapFile) flushPage(p *Page) error {\n\t\/\/ TODO: some code goes here\n\t\/\/You should write page to file(Disk)\n\tfile, _ := os.OpenFile(f.FromFile, os.O_RDWR|os.O_CREATE, 0666)\n\tdefer file.Close()\n\t\/\/Turn page to byte array\n\thp := (*p).(*heapPage)\n\tbuffer, err := hp.toBuffer()\n\tif err != nil {\n\t\treturn err\n\t}\n\tnumOfBytes, err := file.WriteAt(buffer.Bytes(), int64(hp.PageNo*PageSize))\n\n\t_ = numOfBytes \/\/TODO: remove this line after Debug\n\treturn err     \/\/replace me\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *HeapFile) <\/span><span style=\"color: #DCDCAA\">flushPage<\/span><span style=\"color: #D4D4D4\">(p *Page) <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/You should write page to file(Disk)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">file<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> := os.<\/span><span style=\"color: #DCDCAA\">OpenFile<\/span><span style=\"color: #D4D4D4\">(f.FromFile, os.O_RDWR|os.O_CREATE, <\/span><span style=\"color: #B5CEA8\">0666<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">defer<\/span><span style=\"color: #D4D4D4\"> file.<\/span><span style=\"color: #DCDCAA\">Close<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/Turn page to byte array<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">hp<\/span><span style=\"color: #D4D4D4\"> := (*p).(*heapPage)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">buffer<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := hp.<\/span><span style=\"color: #DCDCAA\">toBuffer<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">numOfBytes<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := file.<\/span><span style=\"color: #DCDCAA\">WriteAt<\/span><span style=\"color: #D4D4D4\">(buffer.<\/span><span style=\"color: #DCDCAA\">Bytes<\/span><span style=\"color: #D4D4D4\">(), <\/span><span style=\"color: #DCDCAA\">int64<\/span><span style=\"color: #D4D4D4\">(hp.PageNo*PageSize))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> = numOfBytes <\/span><span style=\"color: #6A9955\">\/\/TODO: remove this line after Debug<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> err     <\/span><span style=\"color: #6A9955\">\/\/replace me<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u8fd4\u56dedesc\u7684\u4e5f\u5f88\u7b80\u5355\uff0c\u76f4\u63a5return\u5c31\u884c\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *HeapFile) Descriptor() *TupleDesc {\n\t\/\/ TODO: some code goes here\n\treturn f.Desc \/\/replace me\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *HeapFile) <\/span><span style=\"color: #DCDCAA\">Descriptor<\/span><span style=\"color: #D4D4D4\">() *TupleDesc {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> f.Desc <\/span><span style=\"color: #6A9955\">\/\/replace me<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u63a5\u4e0b\u6765\u662f\u8fed\u4ee3\uff0c\u867d\u7136page\u6709\u81ea\u5df1\u7684Iterator\uff0c\u4f46\u5728\u8fd9\u91cc\u6211\u4eec\u5148\u81ea\u5df1\u5b9e\u73b0\u8fed\u4ee3\u7684\u65b9\u6cd5\uff08\u4e3b\u8981\u662f\u65b9\u4fbf\u8c03\u8bd5\uff09\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *HeapFile) Iterator(tid TransactionID) (func() (*Tuple, error), error) {\n\n\t\/\/ TODO: some code goes here\n\ti := 0\n\tj := 0\n\t\/\/var iter func() (*Tuple, error)\n\treturn func() (*Tuple, error) {\n\t\tfor i &lt; f.NumPages() {\n\t\t\tpg, err := f.bufPool.GetPage(f, i, tid, ReadPerm)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\thp := (*pg).(*heapPage)\n\t\t\tfor j &lt; int(hp.Hdr.TotalSlots) {\n\t\t\t\tif hp.Tuple[j] != nil {\n\t\t\t\t\ttuple := hp.Tuple[j]\n\t\t\t\t\tj++\n\t\t\t\t\treturn tuple, nil\n\t\t\t\t} else {\n\t\t\t\t\tj++\n\t\t\t\t}\n\t\t\t}\n\t\t\tj = 0\n\t\t\ti++\n\t\t}\n\t\treturn nil, nil\n\t}, nil\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *HeapFile) <\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid TransactionID) (<\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">), <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">j<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/var iter func() (*Tuple, error)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i &lt; f.<\/span><span style=\"color: #DCDCAA\">NumPages<\/span><span style=\"color: #D4D4D4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">pg<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := f.bufPool.<\/span><span style=\"color: #DCDCAA\">GetPage<\/span><span style=\"color: #D4D4D4\">(f, i, tid, ReadPerm)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">hp<\/span><span style=\"color: #D4D4D4\"> := (*pg).(*heapPage)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> j &lt; <\/span><span style=\"color: #DCDCAA\">int<\/span><span style=\"color: #D4D4D4\">(hp.Hdr.TotalSlots) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> hp.Tuple[j] != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\t<\/span><span style=\"color: #9CDCFE\">tuple<\/span><span style=\"color: #D4D4D4\"> := hp.Tuple[j]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\tj++<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> tuple, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t} <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t\tj++<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">j<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\ti++<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u5b9e\u9a8c\u6b65\u9aa4<\/p>\n<cite><em>\u901a\u8fc7heap_file_test.go<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u770b\u4e86\u4e0btest\uff0c\u8fd8\u8981\u8865\u5168bufferpool\u91cc\u9762\u7684flushAllPage\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (bp *BufferPool) FlushAllPages() {\n\t\/\/ TODO: some code goes here\n\tfor _, page := range bp.Pages {\n\t\tp := *page\n\t\tfile := *p.getFile()\n\t\tfile.flushPage(&amp;p)\n\t}\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (bp *BufferPool) <\/span><span style=\"color: #DCDCAA\">FlushAllPages<\/span><span style=\"color: #D4D4D4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">page<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #C586C0\">range<\/span><span style=\"color: #D4D4D4\"> bp.Pages {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">p<\/span><span style=\"color: #D4D4D4\"> := *page<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">file<\/span><span style=\"color: #D4D4D4\"> := *p.<\/span><span style=\"color: #DCDCAA\">getFile<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tfile.<\/span><span style=\"color: #DCDCAA\">flushPage<\/span><span style=\"color: #D4D4D4\">(&amp;p)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u8865\u5168\u4e4b\u540e\u76f4\u63a5run file test\uff0c\u8fc7\u3002\uff08\u82b1\u4e86\u51e0\u5929\u7ec8\u4e8e\u8fc7\u4e86\uff0c\u4ee4\u4eba\u611f\u6168\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full has-custom-border is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"987\" height=\"877\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/d8091870f256fd382fda1cfec2e5a83.png\" alt=\"\" class=\"wp-image-4082\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/d8091870f256fd382fda1cfec2e5a83.png 987w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/d8091870f256fd382fda1cfec2e5a83-300x267.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/d8091870f256fd382fda1cfec2e5a83-768x682.png 768w\" sizes=\"(max-width: 987px) 100vw, 987px\" \/><\/figure>\n\n\n\n<p>\u4ee5\u9632\u4e07\u4e00\u6211\u53c8\u5355\u72ec\u8dd1\u4e86\u6bcf\u4e2atest\u5355\u5143\u3002\u6211\u7a81\u7136\u53d1\u73b0\u4e2a\u5f88\u6709\u610f\u601d\u7684\u5730\u65b9\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u540c\u65f6\u8dd1\u591a\u4e2atest\uff0c\u7531\u4e8e\u5199\u5165\u7684\u90fd\u662f\u540c\u4e00\u4e2a\u6587\u4ef6\uff0cTest A\u548cTest B\u6700\u540e\u4f1a\u8bfb\u5230\u5bf9\u65b9\u7684\u6570\u636e\u3002\u4f46\u662f\u5355\u72ec\u8fd0\u884c\u6bcf\u4e2atest\u5355\u5143\u53c8\u4e0d\u4f1a\u51fa\u73b0\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\u8fd9\u5e94\u8be5\u4e0d\u7b97bug\uff0c\u6bd5\u7adf\u6211\u4eec\u8fd8\u6ca1\u5b9e\u73b0\u4e8b\u52a1\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u5b9e\u9a8c\u6b65\u9aa4<\/p>\n<cite><em>\u4f18\u5316heap file\u7684\u8fed\u4ee3\u5668<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u533f\u540d\u51fd\u6570\u5b66\u7684\u4e0d\u591f\u7cbe\u5c31\u4f1a\u50cf\u6211\u4e00\u6837\uff0c\u4e00\u4e2a\u8fed\u4ee3\u5668\u5199\u534a\u5929\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *HeapFile) Iterator(tid TransactionID) (func() (*Tuple, error), error) {\n\n\t\/\/ TODO: some code goes here\n\ti := 0\n\tvar iter func() (*Tuple, error)\n\t\n\treturn func() (*Tuple, error) {\n\t\tfor i &lt; f.NumPages() {\n\t\t\tpg, err := f.bufPool.GetPage(f, i, tid, ReadPerm)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\thp := (*pg).(*heapPage)\n\t\t\tif iter == nil {\n\t\t\t\titer = hp.tupleIter()\n\t\t\t}\n\t\t\tt, err := iter()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif t != nil {\n\t\t\t\treturn t, nil\n\t\t\t} else {\n\t\t\t\ti++\n\t\t\t\titer = nil\n\t\t\t}\n\t\t}\n\t\treturn nil, nil\n\t}, nil\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *HeapFile) <\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid TransactionID) (<\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">), <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #B5CEA8\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">iter<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i &lt; f.<\/span><span style=\"color: #DCDCAA\">NumPages<\/span><span style=\"color: #D4D4D4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">pg<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := f.bufPool.<\/span><span style=\"color: #DCDCAA\">GetPage<\/span><span style=\"color: #D4D4D4\">(f, i, tid, ReadPerm)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">hp<\/span><span style=\"color: #D4D4D4\"> := (*pg).(*heapPage)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> iter == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #9CDCFE\">iter<\/span><span style=\"color: #D4D4D4\"> = hp.<\/span><span style=\"color: #DCDCAA\">tupleIter<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">t<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">iter<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> t != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> t, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t} <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\ti++<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #9CDCFE\">iter<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u518drun file test\u4e00\u4e0b\uff0c\u5168pass\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full has-custom-border is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"966\" height=\"834\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/543d4b3067a6e2f3f9ac3600d0a088f.png\" alt=\"\" class=\"wp-image-4085\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/543d4b3067a6e2f3f9ac3600d0a088f.png 966w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/543d4b3067a6e2f3f9ac3600d0a088f-300x259.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/543d4b3067a6e2f3f9ac3600d0a088f-768x663.png 768w\" sizes=\"(max-width: 966px) 100vw, 966px\" \/><\/figure>\n\n\n\n<p>\u63a5\u4e0b\u6765lab1\u8fd8\u5269\u6700\u540e\u4e00\u4e2aexercise\u4e86\uff0c\u518d\u63a5\u518d\u5389\u54af\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lab1\u5b9e\u9a8c\u8bb0\u5f55\uff1aheap_file\u548c\u4feebug<\/p>\n","protected":false},"author":1,"featured_media":4082,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[44,33],"tags":[34],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4009"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=4009"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4009\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/4082"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=4009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}