<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>NotionNext BLOG</title>
        <link>https://apricityjin.top/</link>
        <description>这是一个由NotionNext生成的站点</description>
        <lastBuildDate>Fri, 13 Oct 2023 16:18:04 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2023, ApricityJin</copyright>
        <item>
            <title><![CDATA[数据持久化]]></title>
            <link>https://apricityjin.top/article/ecea5745-34e0-4e0e-92c1-ec0d4d9a7e8e</link>
            <guid>https://apricityjin.top/article/ecea5745-34e0-4e0e-92c1-ec0d4d9a7e8e</guid>
            <pubDate>Sun, 03 Sep 2023 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-full-width notion-block-ecea574534e04e0e92c1ec0d4d9a7e8e"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-85ddcb54faa8427bb1191d9bf17dfd59" data-id="85ddcb54faa8427bb1191d9bf17dfd59"><span><div id="85ddcb54faa8427bb1191d9bf17dfd59" class="notion-header-anchor"></div><a class="notion-hash-link" href="#85ddcb54faa8427bb1191d9bf17dfd59" title="前言"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">前言</span></span></h2><blockquote class="notion-quote notion-block-7959c80a070c4fbfab628603fb555447"><div>iOS中的永久存储，也就是在关机重新启动设备，或者关闭应用时，不会丢失数据。</div><div class="notion-text notion-block-8c72069a04c14e88bfa93aa82137a77b">在实际开发应用时，往往需要持久存储数据的，这样用户才能在对应用进行操作后，再次启动能看到自己更改的结果与痕迹。</div></blockquote><div class="notion-text notion-block-65323d18b3a4425b87577fa0cdf28a29">我在开发中所使用的数据持久化的三种方式:</div><ul class="notion-list notion-list-disc notion-block-2d6d323f94204cd5a21625542b11bcf0"><li><code class="notion-inline-code">归档，解档</code></li></ul><ul class="notion-list notion-list-disc notion-block-a6a382719d774301871d7d8ea770bd88"><li><code class="notion-inline-code">NSUserDefault</code></li></ul><ul class="notion-list notion-list-disc notion-block-979f8dce0f564e2f8d2757f37f86aa23"><li><code class="notion-inline-code">SQLite-FMDB</code></li></ul><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-eca40ca0a50e49b3ae931fdbeb8fec8e" data-id="eca40ca0a50e49b3ae931fdbeb8fec8e"><span><div id="eca40ca0a50e49b3ae931fdbeb8fec8e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#eca40ca0a50e49b3ae931fdbeb8fec8e" title="iOS应用的沙盒结构"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">iOS应用的沙盒结构</span></span></h2><blockquote class="notion-quote notion-block-cf8fd63bd4544f3ba5439d38d3666f9f"><div>前言:</div><div class="notion-text notion-block-9623e877702f47eaa66a27850bd31af2">处于安全考虑,iOS系统的沙盒机制规定每个应用都只能访问当前沙盒目录下面的文件(也有例外，比如在用户授权情况下访问通讯录，相册等).</div><div class="notion-text notion-block-01e9864f5c134b3e8c7b5e65e4a49a1d">由于iOS中应用的数据存储是沙盒机制，因此读取和写入文件，我们需要调用C函数 “ NSSearchPathForDirectoriesInDomains（）” 来查找各种目录.</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-2d8b33ddc4614f5b8dd813fb62128707" data-id="2d8b33ddc4614f5b8dd813fb62128707"><span><div id="2d8b33ddc4614f5b8dd813fb62128707" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2d8b33ddc4614f5b8dd813fb62128707" title="主要路径"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">主要路径</span></span></h3><div class="notion-text notion-block-38125f2ed2a044a4ac2b33f22d9c64ba">这里我介绍iOS应用沙盒下比较重要的几个路径:</div><ol start="1" class="notion-list notion-list-numbered notion-block-2548a2d262d446c5a8f787dddb404401"><li>Documents
作用:您应该将所有的应用程序数据文件写入到这个目录下。这个目录用于存储用户数据。该路径可通过配置实现iTunes共享文件。可被iTunes备份。 </li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-80e4fe66cce9445388658aacd11e2ef0"><li>Library</li><ol class="notion-list notion-list-numbered notion-block-80e4fe66cce9445388658aacd11e2ef0"><li>Preferences 目录：包含应用程序的偏好设置文件。您不应该直接创建偏好设置文件，而是应该使用NSUserDefaults类来取得和设置应用程序的偏好。</li><li>Caches 目录：用于存放应用程序专用的支持文件，保存应用程序再次启动过程中需要的信息。 </li></ol></ol><ol start="3" class="notion-list notion-list-numbered notion-block-927cb349477542a084c3dbeb03391d8b"><li>tmp
作用:这个目录用于存放临时文件，保存应用程序再次启动过程中不需要的信息。该路径下的文件不会被iTunes备份。</li></ol><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-56511598081e42fb8010552b9dee0994" data-id="56511598081e42fb8010552b9dee0994"><span><div id="56511598081e42fb8010552b9dee0994" class="notion-header-anchor"></div><a class="notion-hash-link" href="#56511598081e42fb8010552b9dee0994" title="获取各个路径"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">获取各个路径</span></span></h3><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-30391ddd96ba42b58d6d097d2d394ed6" data-id="30391ddd96ba42b58d6d097d2d394ed6"><span><div id="30391ddd96ba42b58d6d097d2d394ed6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#30391ddd96ba42b58d6d097d2d394ed6" title="归档,解档"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">归档,解档</span></span></h2><blockquote class="notion-quote notion-block-ee40fa761bf1403ca3dd9b5c0222c2eb"><div>归档(archiving)也是指另一种形式的序列化。但强大的一点是，它是任何对象都可以实现的更常规的储存数据类型；</div><div class="notion-text notion-block-d5ecee035c50426bbfde4ea1c7968ab8">如果要将各种类型的对象存储到文件中，而不仅仅是字符串、数组、字典类型，利用<code class="notion-inline-code">NSKeyedArchiver</code>类创建带健（keyed）的档案来完成将非常灵活.</div><div class="notion-text notion-block-16fb8045dfb74ce88b6dd8ea5d4e23b9">在带健的档案中，会为每个归档对象提供一个名称，即健（key）。根据这个key可以从归档中检索该对象。这样，就可以按照任意顺序将对象写入归档并进行检索。另外，如果向类中添加了新的实例变量或删除了实例变量，程序也可以进行处理.</div><div class="notion-text notion-block-bdcc43b2b3c04d47b046b46fc25b14d5">待归档的自定义对象需要遵循NSCoding协议。</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-c210bdd5355644cab19c0ec5991c278f" data-id="c210bdd5355644cab19c0ec5991c278f"><span><div id="c210bdd5355644cab19c0ec5991c278f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c210bdd5355644cab19c0ec5991c278f" title="使用"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">使用</span></span></h3><div class="notion-text notion-block-bb28c649847b4e5abe420839842e1dd6"><b>注意:</b></div><div class="notion-text notion-block-7937f93ff512419cb4a8918299e31119">iOS13前后的归档解档使用不同的API.</div><div class="notion-text notion-block-fdeaeee018c644e28af2066878df493a"><code class="notion-inline-code">iOS13之前</code></div><div class="notion-text notion-block-da88ead8b901419ea490f8fe043030dc">归档解档的代码</div><div class="notion-text notion-block-37435ecdfe19493eacb76a2fcbc2aeb4"><code class="notion-inline-code">iOS13之后</code></div><div class="notion-text notion-block-4e96233b60e841688c28e8d5bd3606e0">归档解档的代码</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-50309196b41746d4815b1104b2bb0140" data-id="50309196b41746d4815b1104b2bb0140"><span><div id="50309196b41746d4815b1104b2bb0140" class="notion-header-anchor"></div><a class="notion-hash-link" href="#50309196b41746d4815b1104b2bb0140" title="NSUserDefault"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">NSUserDefault</span></span></h2><blockquote class="notion-quote notion-block-7ec0818312084ed2b9b5308a372d64bf"><div>NSUserDefaults用来存储 用户设置 系统配置等一些小的数据。</div><div class="notion-text notion-block-84540e1c80f44e6d8c04989a69f0b91d">因为数据是明文存储在 plist 文件中，不安全，即使只是修改一个 key 都会 load 整个文件，数据多加载慢(IO 内存)，不适合存储大量数据。</div><div class="notion-text notion-block-d3393e841f7b49bb9d8f36e89e1ed4c0">它是单例的，也是线程安全的，是以键值对 key-value 的形式保存在沙盒中</div><div class="notion-text notion-block-9419a011e40549c2beee993867d390cb">存储路径为：沙盒路径的Library——&gt;Preferences文件夹中,相当于全局的变量.</div></blockquote><div class="notion-text notion-block-1ee8a232755b473d9a08c14c2e240350">支持的数据类型有NSString、 NSNumber、NSDate、 NSArray、NSDictionary、BOOL、NSInteger、NSFloat等系统定义的数据类型，如果要存放其他数据类型或者自定义的对象（如自定义的类对象），则必须将其转换成NSData存储。即使对象是NSArray或NSDictionary，他们存储的类型也应该是以上范围包括的。</div><div class="notion-text notion-block-8cb44b03edf4489aaed2bb120b4b9143">在进行自定义对象的归档时需要实现NSCoding协议，不实现协议方法则抛出异常，类似于序列化与反序列话，获得的对象都是不一致的。</div><div class="notion-text notion-block-68e7eb39e9e843e8bb56ef9d67377da6">NSUserDefaults返回的值是不可改变的，即使存储的时候是可变的值。 对相同的Key赋值约等于一次覆盖。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-f7f09fbba10842b6926dfdcb36d8e991" data-id="f7f09fbba10842b6926dfdcb36d8e991"><span><div id="f7f09fbba10842b6926dfdcb36d8e991" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f7f09fbba10842b6926dfdcb36d8e991" title="得到偏好设置的单例对象"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">得到偏好设置的单例对象</span></span></h3><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e401c948e3bf4e1a9df820c2d64fb769" data-id="e401c948e3bf4e1a9df820c2d64fb769"><span><div id="e401c948e3bf4e1a9df820c2d64fb769" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e401c948e3bf4e1a9df820c2d64fb769" title="储存数据的几个方法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">储存数据的几个方法</span></span></h3><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-fc63d6fa2cf344f591d1428fa6e878b6" data-id="fc63d6fa2cf344f591d1428fa6e878b6"><span><div id="fc63d6fa2cf344f591d1428fa6e878b6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fc63d6fa2cf344f591d1428fa6e878b6" title="得到数据的几个方法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">得到数据的几个方法</span></span></h3><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-d0a46622e35e40f6b59d88d2b27d3770" data-id="d0a46622e35e40f6b59d88d2b27d3770"><span><div id="d0a46622e35e40f6b59d88d2b27d3770" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d0a46622e35e40f6b59d88d2b27d3770" title="移除数据"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">移除数据</span></span></h3><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e73d1aee794941e78bb9c8f347cd0c19" data-id="e73d1aee794941e78bb9c8f347cd0c19"><span><div id="e73d1aee794941e78bb9c8f347cd0c19" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e73d1aee794941e78bb9c8f347cd0c19" title="立即写入-synchronize"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">立即写入-synchronize</span></span></h3><div class="notion-text notion-block-bee76f4513354ac4a168169bc050508e">NSUserDefaults是定时把缓存中的数据写入磁盘的，而不是即时写入，为了防止在写完NSUserDefaults后程序退出导致的数据丢失，可以在写入数据后使用synchronize强制立即将数据写入磁盘：</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-018d4d18d6d94733ac3419b493c1e22d" data-id="018d4d18d6d94733ac3419b493c1e22d"><span><div id="018d4d18d6d94733ac3419b493c1e22d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#018d4d18d6d94733ac3419b493c1e22d" title="SQLite-FMDB"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">SQLite-FMDB</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-61675cda6b5047cc8e00eae146c82eae" data-id="61675cda6b5047cc8e00eae146c82eae"><span><div id="61675cda6b5047cc8e00eae146c82eae" class="notion-header-anchor"></div><a class="notion-hash-link" href="#61675cda6b5047cc8e00eae146c82eae" title="什么是FMDB"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是FMDB</span></span></h3><div class="notion-text notion-block-6707081f920f49729841b99b3f931e21">iOS中使用C语言函数对原生SQLite数据库进行增删改查操作，复杂麻烦，于是，就出现了一系列将SQLite API封装的库，如FMDB。 FMDB是针对libsqlite3框架进行封装的三方框架，它以OC的方式封装了SQLite的C语言的API，使用步骤与SQLite相似。 </div><div class="notion-text notion-block-e73e82d238954a7eb81b864cd7aaf590">FMDB的优点是：</div><ol start="1" class="notion-list notion-list-numbered notion-block-ff6ccc1029d24c7e9e10f64f6ff32bae"><li>使用时面向对象，避免了复杂的C语言代码</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-813ad8a4894345bfb3c62e6578d7d984"><li>对比苹果自带的Core Data框架，更加轻量级和灵活</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-15b08a05ac794ecdb6ad844efb6049e3"><li>提供多线程安全处理数据库操作方法，保证多线程安全跟数据准确性</li></ol><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-32523cb4cb5242b2ad89d8644cf50e1f" data-id="32523cb4cb5242b2ad89d8644cf50e1f"><span><div id="32523cb4cb5242b2ad89d8644cf50e1f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#32523cb4cb5242b2ad89d8644cf50e1f" title="主要类型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">主要类型</span></span></h3><div class="notion-text notion-block-799f2315147346c89b017c6b2fec491a"><code class="notion-inline-code">FMDatabase</code>：一个FMDatabase对象代表一个单独的SQLite数据库，通过SQLite语句执行数据库的增删改查操作 <code class="notion-inline-code">FMResultSet</code>：使用FMDatabase对象查询数据库后的结果集 <code class="notion-inline-code">FMDatabaseQueue</code>：用于多线程操作数据库，它保证线程安全</div><div class="notion-text notion-block-60103dd1cdb045659d8ca399de280553">FMDB使用方式：</div><ol start="1" class="notion-list notion-list-numbered notion-block-d2111d436d34493e8fdf580600d69d6c"><li>GitHub中下载FMDB，将文件导入工程中</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-f7688e00b3f241bd97c405df0f75cbf4"><li>导入libsqlite3.0框架，导入头文件FMDatabase.h</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-0603cca456a240188695b9812e9fc4ae"><li>创建数据库路径，创建数据库，操作前开启数据库，构建操作SQLite语句，数据库执行增删改查操作，操作完关闭数据库</li></ol><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-2e5cb15adca74d4d800f4f2ecdcc0d0a" data-id="2e5cb15adca74d4d800f4f2ecdcc0d0a"><span><div id="2e5cb15adca74d4d800f4f2ecdcc0d0a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2e5cb15adca74d4d800f4f2ecdcc0d0a" title="接下来介绍FMDB的基本操作:"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">接下来介绍FMDB的基本操作:</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-096d2a3d645a42aeb1b8df80d25be932" data-id="096d2a3d645a42aeb1b8df80d25be932"><span><div id="096d2a3d645a42aeb1b8df80d25be932" class="notion-header-anchor"></div><a class="notion-hash-link" href="#096d2a3d645a42aeb1b8df80d25be932" title="Insert"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Insert</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-fe585ced5f2447a285a9a094166f97c8" data-id="fe585ced5f2447a285a9a094166f97c8"><span><div id="fe585ced5f2447a285a9a094166f97c8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fe585ced5f2447a285a9a094166f97c8" title="Delete"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Delete</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-28b1156bcaf644608a1a141aac83eb91" data-id="28b1156bcaf644608a1a141aac83eb91"><span><div id="28b1156bcaf644608a1a141aac83eb91" class="notion-header-anchor"></div><a class="notion-hash-link" href="#28b1156bcaf644608a1a141aac83eb91" title="Update"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Update</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4338b92171a04527a0984662ae08cd40" data-id="4338b92171a04527a0984662ae08cd40"><span><div id="4338b92171a04527a0984662ae08cd40" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4338b92171a04527a0984662ae08cd40" title="Select"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Select</span></span></h4><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-818b9ba75bf04e34b956e5419a2feaba" data-id="818b9ba75bf04e34b956e5419a2feaba"><span><div id="818b9ba75bf04e34b956e5419a2feaba" class="notion-header-anchor"></div><a class="notion-hash-link" href="#818b9ba75bf04e34b956e5419a2feaba" title="接下来看看具体使用"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">接下来看看具体使用</span></span></h3><div class="notion-text notion-block-42948582774442e48eba695d8aca6465">首先创建一个类 <code class="notion-inline-code">Student</code></div><div class="notion-text notion-block-5fedcc9796254b49a0518cdf74db34fb">然后在ViewController中添加两个属性:</div><div class="notion-text notion-block-01668c84bb764edd830757e98583031b">接下来执行FMDB操作</div><div class="notion-text notion-block-5df1285aa3414d73b10aebd1cb937ddf"><b>增删改查:</b></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-bd7fb62e166b47b18d4938e6c29dc6d8" data-id="bd7fb62e166b47b18d4938e6c29dc6d8"><span><div id="bd7fb62e166b47b18d4938e6c29dc6d8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#bd7fb62e166b47b18d4938e6c29dc6d8" title="FMDB的事务"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">FMDB的事务</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-bd7db609228d4f119710786bd2a8b447"><li><b>事务定义：</b> 事务(Transaction)是并发操作的基本单位，是指单个逻辑工作单位执行的一系列操作序列，这些操作要不都成功，要不就不成功，事务是数据库维护数据一致性的单位，在每个事务结束时，都能保证数据一致性与准确性，通常事务跟程序是两个不同的概念，一个程序中包含多个事务，事务主要解决并发条件下操作数据库，保证数据</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-8bdfd497048441538268e73c111c2c82"><li><b>事务特征：</b> </li><ol class="notion-list notion-list-numbered notion-block-8bdfd497048441538268e73c111c2c82"><div class="notion-text notion-block-91d67031652a4bf0acffa3864881e292">原子性（Atomic）：事务中包含的一系列操作被看作一个逻辑单元，这个逻辑单元要不全部成功，要不全部失败
一致性（Consistency）：事务中包含的一系列操作，只有合法的数据被写入数据库，一些列操作失败之后，事务会滚到最初创建事务的状态 
隔离性（Isolation）：对数据进行修改的多个事务之间是隔离的，每个事务是独立的，不应该以任何方式来影响其他事务 
持久性（Durability）事务完成之后，事务处理的结果必须得到固化，它对于系统的影响是永久的，该修改即使出现系统固执也将一直保留，真实的修改了数据库</div></ol></ol><ul class="notion-list notion-list-disc notion-block-3eff1a503c10450aa487b88d18af2e3a"><li>如何在项目中使用事务操作SQLite</li></ul></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[单链表]]></title>
            <link>https://apricityjin.top/article/fa96ecf8-feab-4940-a43d-e1dfc0b614e1</link>
            <guid>https://apricityjin.top/article/fa96ecf8-feab-4940-a43d-e1dfc0b614e1</guid>
            <pubDate>Sun, 03 Sep 2023 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-fa96ecf8feab4940a43de1dfc0b614e1"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-b01831d1d6934422be92f0dcc298d61e" data-id="b01831d1d6934422be92f0dcc298d61e"><span><div id="b01831d1d6934422be92f0dcc298d61e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b01831d1d6934422be92f0dcc298d61e" title="链表是什么"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">链表是什么</span></span></h2><div class="notion-text notion-block-38f613247dee41eda1265a2a63fc7d64"><code class="notion-inline-code">我的理解:</code></div><ul class="notion-list notion-list-disc notion-block-c1f4e187d158478e9a7c36045c221fda"><li>链表是一种常见的基础数据结构，是一种线性表.</li></ul><ul class="notion-list notion-list-disc notion-block-82c24dcb4934495b8560839c6988f77c"><li>链表并不会按线性的顺序存储数据而是采用动态分配存储单元方式，在每一个节点(Node)储存数据,并保存下一个节点.</li></ul><ul class="notion-list notion-list-disc notion-block-60b51282fa70486f9a8ec9871f945035"><li>链表能够有效地节省存储空间（同数组比较）。</li></ul><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-764f07431de34815a426e0783cd18365" data-id="764f07431de34815a426e0783cd18365"><span><div id="764f07431de34815a426e0783cd18365" class="notion-header-anchor"></div><a class="notion-hash-link" href="#764f07431de34815a426e0783cd18365" title="链表的存在解决了什么问题"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">链表的存在解决了什么问题</span></span></h2><div class="notion-text notion-block-b93594fa9ed2431d9f9a5eb10abdadcb"><code class="notion-inline-code">我的理解:</code></div><div class="notion-text notion-block-6745af21bad2468793bcaae968dae589">我们之前已经接触了数组，感到数组已经是万能的数据存储位置了，但是，如果我们一直使用比较复杂的数据（也就是比较多的数据时），我就会很反感，因为对于数组这种数据结构，在使用之前，一定要对其大小进行一番定义，这样一来，它的存储空间在数据处理过程中显得极为不方便，因为谁也不想对将要处理的数据做一个空间的预算，并且还要让其空间足够大，这样才能满足储存数据的要求（但是如果分配的太多，就会浪费内存），上面的一切都证明使用数组需要注意的东西真的很多很多，这样一来，我们就开始说说链表，链表也是一种数据结构，它弥补了数组带来的诸多不便，让我们可以任意为一些数据进行空间的分配，根据需要进行内存单元的开辟。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-6dea8f1860a548f488622e385d71cad9" data-id="6dea8f1860a548f488622e385d71cad9"><span><div id="6dea8f1860a548f488622e385d71cad9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6dea8f1860a548f488622e385d71cad9" title="具体实现"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">具体实现</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-eed5915e44964231ba8927809544b7f8" data-id="eed5915e44964231ba8927809544b7f8"><span><div id="eed5915e44964231ba8927809544b7f8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#eed5915e44964231ba8927809544b7f8" title="节点(Node)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">节点(Node)</span></span></h3><blockquote class="notion-quote notion-block-223e7e7d82c14242a2d9e7df2967fbc1"><div>一个链表就是一串节点(Node),每个节点的作用有二: 一是储存数据,并且一个链表储存相同类型的数据,不同链表储存的数据可以不同; 二是储存下一个节点,当下一个位置没有数据,即当前数据是最后一个数据时,节点保存的下一个节点为空.</div></blockquote><div class="notion-text notion-block-8ee58ba1dcbd4d998b5c32d73bcbdcfa">这里我先创建一个叫<code class="notion-inline-code">Node</code>的类,同时也是<code class="notion-inline-code">泛型</code>,并重写<code class="notion-inline-code">description</code>.</div><div class="notion-text notion-block-404930af295040388c2d75f8dde2719e">完成这个类的创建之后,在<code class="notion-inline-code">main.swift</code>文件里写以下代码可以检测创建的<code class="notion-inline-code">Node</code>类是否达到了我们对节点的功能要求:</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-69ccc96c4a014632a2c7a78340d6648c" data-id="69ccc96c4a014632a2c7a78340d6648c"><span><div id="69ccc96c4a014632a2c7a78340d6648c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#69ccc96c4a014632a2c7a78340d6648c" title="链表(LinkedList)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">链表(LinkedList)</span></span></h3><blockquote class="notion-quote notion-block-0f756c8399294f1283b3564a4a170e32"><div>我们又遇到一个新问题： 如果我有很多个数据，并且要把他们储存在节点（Node）中，如果我用上诉方法创建链表将会是灾难性的，并且没有任何方法让我对其进行管理。 那么接下来我就会用一个结构体LinkedList来解决这个问题。</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-c0a22764178140878e4da194d0003ba5" data-id="c0a22764178140878e4da194d0003ba5"><span><div id="c0a22764178140878e4da194d0003ba5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c0a22764178140878e4da194d0003ba5" title="完成链表的基础"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">完成链表的基础</span></span></h4><div class="notion-text notion-block-3a1b751a0910412eb1ef787787d1dc53">我们把<code class="notion-inline-code">LinkedList</code>定义为 Struct 类型，同时也是<code class="notion-inline-code">泛型</code>。 重写<code class="notion-inline-code">description</code>方法,这样可以在输出的时候更有利于链表的透明化。</div><div class="notion-text notion-block-3adf7f3bf85a42b5b9a7ade5c970c6ef"><code class="notion-inline-code">head</code>是第一个元素；<code class="notion-inline-code">tail</code>是最后一个元素。 另外添加了<code class="notion-inline-code">isEmpty()</code>, <code class="notion-inline-code">length()</code>方法，方便后续使用。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-aa95e5698b1d49b8a5115c3549de8b5a" data-id="aa95e5698b1d49b8a5115c3549de8b5a"><span><div id="aa95e5698b1d49b8a5115c3549de8b5a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#aa95e5698b1d49b8a5115c3549de8b5a" title="对链表进行操作"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">对链表进行操作</span></span></h4><div class="notion-text notion-block-a61c8fd9be214d3abdc4da1ac7ac7663">这里我们定义3种添加元素的方法：</div><ol start="1" class="notion-list notion-list-numbered notion-block-8dd94d249e344abe8878fdf922a29f9d"><li>push(): 在链表的头结点前面添加元素;</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-7c1fdb1edd96449f83e571b36e2c65ea"><li>append(): 在链表的尾节点后面添加元素;</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-85b8214d0e5b49958639541819560b06"><li>insert(after:): 在某个节点后面添加元素。</li></ol><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-a5e42853ecd54769a716a46a11600feb" data-id="a5e42853ecd54769a716a46a11600feb"><span><div id="a5e42853ecd54769a716a46a11600feb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a5e42853ecd54769a716a46a11600feb" title="移除元素"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">移除元素</span></span></h4><div class="notion-text notion-block-7aed202f9acb49f79521dee711a1741f">这里我们定义与添加元素对应的移除方法:</div><ol start="1" class="notion-list notion-list-numbered notion-block-0034f9efca6b40f3a24d13e3cc8d90ac"><li>pop(): 移除链表第一个元素,并将 head 指向第二个元素;</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-293a8f1c4d4d457eb3e660e5850ed896"><li>removeLast(): 移除链表的最后一个元素;</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-06b402b3705e40db81d3e78286c460f7"><li>remove(at:): 移除索引值节点的元素.</li></ol><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-dbb44120088743d8865d8f0a52aaee03" data-id="dbb44120088743d8865d8f0a52aaee03"><span><div id="dbb44120088743d8865d8f0a52aaee03" class="notion-header-anchor"></div><a class="notion-hash-link" href="#dbb44120088743d8865d8f0a52aaee03" title="总结"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">总结</span></span></h2><div class="notion-text notion-block-37dc813a188a49a69a8c9b51d0e8223f">本文简单实现了链表. 目前添加和移除元素的方法比较少, 如果有兴趣的话, 可以添加更多的方法, 例如 append 一个链表, insert 一个链表等等.</div><div class="notion-text notion-block-6e00eaaedd25435ab986b80aa0e8360b">关于 Apple 给 Swift 写的链表实现,可以看本篇最后推荐的文章,这里就不多赘述.</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-b0cb0aa2ad2f41d7b63ddb1a46d988e9" data-id="b0cb0aa2ad2f41d7b63ddb1a46d988e9"><span><div id="b0cb0aa2ad2f41d7b63ddb1a46d988e9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b0cb0aa2ad2f41d7b63ddb1a46d988e9" title="更多"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">更多</span></span></h2><blockquote class="notion-quote notion-block-1c8f2395eccd45b98aea81b31c3e721c"><div>本文的许多点来自于网络,我将我推荐的文章放在这里:

<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.jianshu.com/p/84b092fc1f3a">【数据结构与算法 - Swift 实现】02 - 链表
</a><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.jianshu.com/p/edbae3d56d8d">Swift 链表 LinkedList</a></div></blockquote><div class="notion-blank notion-block-a178cd72f026429e8d817a9db5d1329a"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[栈]]></title>
            <link>https://apricityjin.top/article/8616a938-24a7-4abe-b150-c683911aedd2</link>
            <guid>https://apricityjin.top/article/8616a938-24a7-4abe-b150-c683911aedd2</guid>
            <pubDate>Sun, 03 Sep 2023 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-8616a93824a74abeb150c683911aedd2"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-29be866765da4d66858f82f36ae32407" data-id="29be866765da4d66858f82f36ae32407"><span><div id="29be866765da4d66858f82f36ae32407" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29be866765da4d66858f82f36ae32407" title="什么是栈?"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是栈?</span></span></h2><div class="notion-text notion-block-cf303eeef2a34b3cb70799b07c4190fb">栈（stack）又名堆栈，它是一种运算受限的线性表。限定仅在表尾进行插入和删除操作的线性表。这一端被称为栈顶，相对地，把另一端称为栈底。 </div><div class="notion-text notion-block-3f21d85600f845b68fb08b2a6d374764">向一个栈插入新元素又称作进栈、入栈或压栈，它是把新元素放到栈顶元素的上面，使之成为新的栈顶元素；从一个栈删除元素又称作出栈或退栈，它是把栈顶元素删除掉，使其相邻的元素成为新的栈顶元素。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-fe496ac0040e46c7856049c93a828ca0" data-id="fe496ac0040e46c7856049c93a828ca0"><span><div id="fe496ac0040e46c7856049c93a828ca0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fe496ac0040e46c7856049c93a828ca0" title="对四则运算的算法实现"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">对四则运算的算法实现</span></span></h2><blockquote class="notion-quote notion-block-5408ee9c4a8f45dc9f95af0e6b5b034c"><div>问题描述: 设计一个程序，演示用算符优先法对算术表达式求值的过程。利用算符优先关系，实现对算术四则混合运算表达式的求值。</div><div class="notion-text notion-block-3c48aefe631e43a78c5d5bee03f785e9">（1）输入的形式：表达式，例如’2<em>(3+4)#, 包含的运算符只能有’+’ 、‘-’ 、’</em>’ 、‘/’ 、‘(’、 ‘)’，“#”代表输入结束符；</div><div class="notion-text notion-block-caaf246a00ff40ae80458fd635f0eb89">（2）输出的形式：运算结果，例如2*(3+4)=14；</div><div class="notion-text notion-block-8c389b9d2e7148728998d11d0ec0c6fb">（3）程序所能达到的功能：对表达式求值并输出。</div></blockquote></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[力扣经典题]]></title>
            <link>https://apricityjin.top/article/0e8e7e09-0411-4667-bf49-4ac4c12fca71</link>
            <guid>https://apricityjin.top/article/0e8e7e09-0411-4667-bf49-4ac4c12fca71</guid>
            <pubDate>Sun, 03 Sep 2023 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-0e8e7e0904114667bf494ac4c12fca71"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><blockquote class="notion-quote notion-block-5ec096c45e384fbbb6c9611a8f7811dd"><div>收录我认为对我的算法学习较为有帮助的算法题。</div><div class="notion-text notion-block-fdca080018614edb8c5997a5079eb6cc">题解来自于力扣、代码随想录、爱饲养的程序员等发布的文章。</div></blockquote><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-b28b7c4cfe644b208aa951a1920cb93f" data-id="b28b7c4cfe644b208aa951a1920cb93f"><span><div id="b28b7c4cfe644b208aa951a1920cb93f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b28b7c4cfe644b208aa951a1920cb93f" title="19. 删除链表的倒数第 N 个结点"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/remove-nth-node-from-end-of-list/">19. 删除链表的倒数第 N 个结点</a></span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-f675203e9883424ab58e3d4dd3c61f7f" data-id="f675203e9883424ab58e3d4dd3c61f7f"><span><div id="f675203e9883424ab58e3d4dd3c61f7f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f675203e9883424ab58e3d4dd3c61f7f" title="双指针"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>双指针</b></span></span></h4><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-55e4cbcd71de4f879ec2bac0a7a73c03" data-id="55e4cbcd71de4f879ec2bac0a7a73c03"><span><div id="55e4cbcd71de4f879ec2bac0a7a73c03" class="notion-header-anchor"></div><a class="notion-hash-link" href="#55e4cbcd71de4f879ec2bac0a7a73c03" title="24. 两两交换链表中的节点"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/swap-nodes-in-pairs/">24. 两两交换链表中的节点</a></span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-5b4d2c04f8624e69a27999922aa1a025" data-id="5b4d2c04f8624e69a27999922aa1a025"><span><div id="5b4d2c04f8624e69a27999922aa1a025" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5b4d2c04f8624e69a27999922aa1a025" title="迭代算法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>迭代算法</b></span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-edd509588a4047adb8ada173614c189b" data-id="edd509588a4047adb8ada173614c189b"><span><div id="edd509588a4047adb8ada173614c189b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#edd509588a4047adb8ada173614c189b" title="递归算法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>递归算法</b></span></span></h4><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-fb4da696e52944da9d5437725e620774" data-id="fb4da696e52944da9d5437725e620774"><span><div id="fb4da696e52944da9d5437725e620774" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fb4da696e52944da9d5437725e620774" title="27.移除元素"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/remove-element/description/">27.移除元素</a></span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-b02668eef59648808b935239bb124b5f" data-id="b02668eef59648808b935239bb124b5f"><span><div id="b02668eef59648808b935239bb124b5f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b02668eef59648808b935239bb124b5f" title="快慢指针"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>快慢指针</b></span></span></h4><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-3e6f0a3cdf93408a9174d5d39a05d210" data-id="3e6f0a3cdf93408a9174d5d39a05d210"><span><div id="3e6f0a3cdf93408a9174d5d39a05d210" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3e6f0a3cdf93408a9174d5d39a05d210" title="59.螺旋矩阵II"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/spiral-matrix-ii/description/">59.螺旋矩阵II</a></span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1c99c766a08d486da7ddf629c3bbdc63" data-id="1c99c766a08d486da7ddf629c3bbdc63"><span><div id="1c99c766a08d486da7ddf629c3bbdc63" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1c99c766a08d486da7ddf629c3bbdc63" title="循环填充"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>循环填充</b></span></span></h4><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-552b9fe17b7c4d018ff402821a90b8d9" data-id="552b9fe17b7c4d018ff402821a90b8d9"><span><div id="552b9fe17b7c4d018ff402821a90b8d9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#552b9fe17b7c4d018ff402821a90b8d9" title="142.环形链表II"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/linked-list-cycle-ii/">142.环形链表II</a></span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-ad0d95b259944a9a8bfe3c88cc322bcc" data-id="ad0d95b259944a9a8bfe3c88cc322bcc"><span><div id="ad0d95b259944a9a8bfe3c88cc322bcc" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ad0d95b259944a9a8bfe3c88cc322bcc" title="龟兔赛跑算法（快慢指针）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>龟兔赛跑算法（快慢指针）</b></span></span></h4><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-5389521b86604472983cb03366ef8d5e" data-id="5389521b86604472983cb03366ef8d5e"><span><div id="5389521b86604472983cb03366ef8d5e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5389521b86604472983cb03366ef8d5e" title="160.相交链表"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/intersection-of-two-linked-lists/">160.相交链表</a></span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-c6b30846a9a14e978df279c5a0464b98" data-id="c6b30846a9a14e978df279c5a0464b98"><span><div id="c6b30846a9a14e978df279c5a0464b98" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c6b30846a9a14e978df279c5a0464b98" title="双指针"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>双指针</b></span></span></h4><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4fbcf95d0dd84882b9032a3daecd4cdd" data-id="4fbcf95d0dd84882b9032a3daecd4cdd"><span><div id="4fbcf95d0dd84882b9032a3daecd4cdd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4fbcf95d0dd84882b9032a3daecd4cdd" title="169.多数元素 "><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/majority-element/">169.多数元素</a> </span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-ee886f1be97f4241a08441a39c164efd" data-id="ee886f1be97f4241a08441a39c164efd"><span><div id="ee886f1be97f4241a08441a39c164efd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ee886f1be97f4241a08441a39c164efd" title="Boyer-Moore 投票算法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Boyer-Moore 投票算法</b></span></span></h4><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-e60ad1ca51934a7d810871374c1b9e67" data-id="e60ad1ca51934a7d810871374c1b9e67"><span><div id="e60ad1ca51934a7d810871374c1b9e67" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e60ad1ca51934a7d810871374c1b9e67" title="203.移除链表元素"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/remove-linked-list-elements/">203.移除链表元素</a></span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-2adbe89299b54c148fad54a749747e84" data-id="2adbe89299b54c148fad54a749747e84"><span><div id="2adbe89299b54c148fad54a749747e84" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2adbe89299b54c148fad54a749747e84" title="双指针"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>双指针</b></span></span></h4><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-2e2f06a5a77c4ee7967ad4a36e790753" data-id="2e2f06a5a77c4ee7967ad4a36e790753"><span><div id="2e2f06a5a77c4ee7967ad4a36e790753" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2e2f06a5a77c4ee7967ad4a36e790753" title="206.反转链表"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/reverse-linked-list/">206.反转链表</a></span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-8bb5b5a8ba5e4559bce69f0073df190d" data-id="8bb5b5a8ba5e4559bce69f0073df190d"><span><div id="8bb5b5a8ba5e4559bce69f0073df190d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8bb5b5a8ba5e4559bce69f0073df190d" title="递归算法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>递归算法</b></span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-090562ee6cc64d8ea0e95a0b1080a71b" data-id="090562ee6cc64d8ea0e95a0b1080a71b"><span><div id="090562ee6cc64d8ea0e95a0b1080a71b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#090562ee6cc64d8ea0e95a0b1080a71b" title="双指针算法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>双指针算法</b></span></span></h4><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-9ab7d370aa3f42fe8bf9e5e6221b4dc5" data-id="9ab7d370aa3f42fe8bf9e5e6221b4dc5"><span><div id="9ab7d370aa3f42fe8bf9e5e6221b4dc5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9ab7d370aa3f42fe8bf9e5e6221b4dc5" title="209.长度最小的子数组"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/minimum-size-subarray-sum/">209.长度最小的子数组</a></span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-bda22d96e97549f49f6adc58de42f172" data-id="bda22d96e97549f49f6adc58de42f172"><span><div id="bda22d96e97549f49f6adc58de42f172" class="notion-header-anchor"></div><a class="notion-hash-link" href="#bda22d96e97549f49f6adc58de42f172" title="滑动窗口"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>滑动窗口</b></span></span></h4><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-9f5fbe87a1a34ab0946314e6492d31d6" data-id="9f5fbe87a1a34ab0946314e6492d31d6"><span><div id="9f5fbe87a1a34ab0946314e6492d31d6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9f5fbe87a1a34ab0946314e6492d31d6" title="253.会议室II"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://leetcode.cn/problems/meeting-rooms-ii">253.会议室II</a></span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e8af22f9ec9a489f99979074f3bf7165" data-id="e8af22f9ec9a489f99979074f3bf7165"><span><div id="e8af22f9ec9a489f99979074f3bf7165" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e8af22f9ec9a489f99979074f3bf7165" title="题目描述"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">题目描述</span></span></h3><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-64996784ecd9455d91e3066db359456f"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://prod-files-secure.s3.us-west-2.amazonaws.com/c32ee85f-749a-4c70-8918-f07a8a17f2ec/f8412419-11ec-4fc0-ba65-cc3596fb9d36/Untitled.png" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-0ae7574739bb47b39abb7c25800e74b0" data-id="0ae7574739bb47b39abb7c25800e74b0"><span><div id="0ae7574739bb47b39abb7c25800e74b0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0ae7574739bb47b39abb7c25800e74b0" title="题解"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">题解</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-045a1a3052864033aaf9b958769d8cbf" data-id="045a1a3052864033aaf9b958769d8cbf"><span><div id="045a1a3052864033aaf9b958769d8cbf" class="notion-header-anchor"></div><a class="notion-hash-link" href="#045a1a3052864033aaf9b958769d8cbf" title="最小堆"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">最小堆</span></span></h4><div class="notion-blank notion-block-43c666aa8ca64538900562433498b3f4"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CPU渲染和GPU渲染]]></title>
            <link>https://apricityjin.top/article/a1a44b11-eaac-4317-bc58-a32d2c601b4e</link>
            <guid>https://apricityjin.top/article/a1a44b11-eaac-4317-bc58-a32d2c601b4e</guid>
            <pubDate>Sun, 03 Sep 2023 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-a1a44b11eaac4317bc58a32d2c601b4e"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-b8e958b9aceb4ea4ae53f08c74f5189d" data-id="b8e958b9aceb4ea4ae53f08c74f5189d"><span><div id="b8e958b9aceb4ea4ae53f08c74f5189d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b8e958b9aceb4ea4ae53f08c74f5189d" title="什么是渲染"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是渲染</span></span></h2><div class="notion-text notion-block-19a455b25c5c4e69832c0f26419ad19b">渲染是使用计算机应用程序从 2D 或 3D 模型生成最终图像的过程。渲染过程就像一幅画的最终着色。最初，这幅画从简单的素描开始，当艺术家为画作添加颜色和纹理时，它最终变得栩栩如生。类似地，在渲染中，原始模型被赋予所有微小的细节，例如纹理、光照和摄像机角度，直到我们得到最终输出。</div><div class="notion-text notion-block-39caeee9602c47bdae0e6cd3e4472c2d">所以，让我们先看看基于 CPU 和 GPU 的渲染是什么，然后我们将讨论区分它们的特性。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-3420e105271c4ca3b7486806eb8c9901" data-id="3420e105271c4ca3b7486806eb8c9901"><span><div id="3420e105271c4ca3b7486806eb8c9901" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3420e105271c4ca3b7486806eb8c9901" title="什么是 CPU 与 GPU ？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是 CPU 与 GPU ？</span></span></h2><div class="notion-text notion-block-1a3b7d98787447a6acfc8e5f9d1b7739">CPU 代表中央处理单元（Central Processing Unit），也称为中央处理器、主处理器或简称处理器。CPU 是处理指令的计算机的主要组件。它运行计算、操作、运行程序，包括渲染。CPU 不断地接收来自用户或活动软件程序的输入，然后处理数据并产生输出，这些输出可以由应用程序存储或显示在屏幕上。</div><div class="notion-text notion-block-f00d5858eebf40d0a1bfa03463ec3eed">相比之下，图形处理单元（Graphics Processing Unit），即 GPU，已经成为最关键的计算技术，是微处理器的一种。GPU 有数千个以相对较低的时钟速度运行的小内核。在这种情况下，正是这些核心的数量让 GPU 能够提供强大的渲染性能。GPU专为并行处理而设计，用于广泛的应用程序，加速图形的渲染。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-84b0844690374f7691fec0861a6b1b98" data-id="84b0844690374f7691fec0861a6b1b98"><span><div id="84b0844690374f7691fec0861a6b1b98" class="notion-header-anchor"></div><a class="notion-hash-link" href="#84b0844690374f7691fec0861a6b1b98" title="CPU渲染"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">CPU渲染</span></span></h2><div class="notion-text notion-block-f10a50b4f7c64f619259d21b8dfec1cf">CPU渲染一般被认为是传统的图像渲染方式。CPU渲染依赖于计算机的中央处理器（CPU），它比GPU渲染有更多的内存，可以使用你系统的RAM和磁盘空间，CPU渲染方式的重点在于处理照明、材料和其他计算流程来产生渲染图像，这个过程需要进行复杂的计算，因此，CPU渲染对于算力的要求比较高。</div><div class="notion-text notion-block-1a09bc0d310540d3bafc26d62e55e6de">CPU 渲染的优点在于对场景的光照和相机的观察角度的处理比较精细，可以呈现出非常真实的光影效果，因此 CPU 渲染也常常被用于创作高端的影视、动画等特效。</div><div class="notion-text notion-block-7349da188f3048089f1c09a08fb4196b">而CPU渲染的缺点就在于它的计算能力是有限的，只能在单线程执行渲染任务。一旦要处理大规模场景、大量多边形、复杂材质和纹理时，CPU的计算速度就会变得十分缓慢。而这也是为什么在制作3D动画电影时，仅渲染一个5-10秒的场景都可能需要数天甚至数周时间的原因所在。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-b72d1c345060445097527597a5f76db2" data-id="b72d1c345060445097527597a5f76db2"><span><div id="b72d1c345060445097527597a5f76db2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b72d1c345060445097527597a5f76db2" title="GPU渲染"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">GPU渲染</span></span></h2><div class="notion-text notion-block-42debe71ab0843aba79f338da1eab44b">GPU渲染则是利用了图形处理器（GPU）的硬件加速器来完成的，所以GPU渲染能够做到的是快速地进行渲染处理，同时也能够处理大规模场景、大量多边形、复杂材质和纹理等高强度的3D渲染任务，其渲染速度远比CPU快得多。</div><div class="notion-text notion-block-f5b3ca15f5db4814b3dcadb7ff02efff">然而GPU渲染的特点在于，它能够进行大规模的并行处理，这代表着它可以同时处理多项渲染任务。但渲染速度又要比CPU高效很多，它让3D渲染的用户能够快速地预览并修改设计，从而增加各种创意的实验机会，这就是为什么现今许多电脑游戏和应用程序都需要GPU支持的原因。</div><div class="notion-text notion-block-4c289bc1121a4c1eb6799459131a59f7">而且，层次化的渲染算法很适用于GPU的并行处理结构，这就让很多GPU制造商将基于GPU的渲染器集成到他们的图形卡产品中，可以称之为“GPU着色器”。这种GPU加速的3D渲染技术比传统的CPU渲染更快、也更节省能源、更智能，而且在处理大型场景的时候也不会影响系统的运行速度。</div><div class="notion-text notion-block-9cedc3b1572f4b17b0fbba5d14754528">不过需要注意的是，GPU渲染的优势在于针对较大场景的3D渲染处理，它相比CPU渲染来说，在精度方面会有所下降。</div><div class="notion-blank notion-block-46eaaa561a66409284314505ab952d79"> </div><div class="notion-text notion-block-79044440c9c24c5aaa29166b4be66be5">GPU 有数千个以相对较低的时钟速度运行的小内核。在这种情况下，正是这些核心的数量让 GPU 能够提供强大的渲染性能。GPU 本质上被设计为以并行方式运行任务。这使它们比 CPU 更具优势，因为渲染是一项通常涉及许多元素的任务。因此，GPU 以其极快的渲染时间而闻名。</div><div class="notion-text notion-block-b3f2daaa9af844a58a09e1e296139282">快速渲染允许 GPU 实时处理图形，这就是为什么您会发现现代视频游戏使用 GPU 运行起来更加流畅。与游戏行业一起，GPU 已经彻底改变了加密、大数据、人工智能和机器学习领域。</div><div class="notion-text notion-block-b7897387d8bc4880bc04bfd60ab3b636">GPU 渲染在许多领域逐渐普及，正在挑战传统的 CPU 渲染系统。Autodesk 的 Arnold 推出了他们的GPU 渲染引擎，认识到其巨大潜力。</div><div class="notion-text notion-block-d609dd6e15e14ddb928c1319a0a505ba">尽管对差异的概述有助于更清楚地了解每个系统，但 CPU 和 GPU 的各种独特功能也值得了解。</div></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>