import{_ as a,o as n,c as l,X as s,k as p}from"./chunks/framework.6e839c56.js";const g=JSON.parse('{"title":"CopyOnWriteList","description":"","frontmatter":{},"headers":[],"relativePath":"api/packages/datastructure/copyonwritelist.md","filePath":"api/packages/datastructure/copyonwritelist.md"}'),o={name:"api/packages/datastructure/copyonwritelist.md"},e=s(`<h1 id="CopyOnWriteList" tabindex="-1">CopyOnWriteList <a class="header-anchor" href="#CopyOnWriteList" aria-label="Permalink to &quot;CopyOnWriteList&quot;">​</a></h1><p>CopyOnWriteList 是一个线程安全的 List 实现，底层使用 go 切片。写入时，会复制一份新的切片，写入完成后，再将新的切片赋值给原来的切片。读取时，直接读取原来的切片。</p><h2 id="源码" tabindex="-1">源码 <a class="header-anchor" href="#源码" aria-label="Permalink to &quot;源码&quot;">​</a></h2><ul><li><a href="https://github.com/duke-git/lancet/blob/main/datastructure/list/copyonwritelist.go" target="_blank" rel="noreferrer">https://github.com/duke-git/lancet/blob/main/datastructure/list/copyonwritelist.go</a></li></ul><h2 id="用法" tabindex="-1">用法 <a class="header-anchor" href="#用法" aria-label="Permalink to &quot;用法&quot;">​</a></h2><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span></code></pre></div>`,6),t=p("div",{STYLE:"page-break-after: always;"},null,-1),c=s(`<h2 id="目录" tabindex="-1">目录 <a class="header-anchor" href="#目录" aria-label="Permalink to &quot;目录&quot;">​</a></h2><ul><li><a href="#NewCopyOnWriteList">NewCopyOnWriteList</a></li><li><a href="#Size">Size</a></li><li><a href="#Get">Get</a></li><li><a href="#Set">Set</a></li><li><a href="#Remove">Remove</a></li><li><a href="#IndexOf">IndexOf</a></li><li><a href="#LastIndexOf">LastIndexOf</a></li><li><a href="#IsEmpty">IsEmpty</a></li><li><a href="#Contain">Contain</a></li><li><a href="#ValueOf">ValueOf</a></li><li><a href="#Add">Add</a></li><li><a href="#AddAll">AddAll</a></li><li><a href="#AddByIndex">AddByIndex</a></li><li><a href="#DeleteAt">DeleteAt</a></li><li><a href="#DeleteIf">DeleteIf</a></li><li><a href="#DeleteBy">DeleteBy</a></li><li><a href="#DeleteRange">DeleteRange</a></li><li><a href="#Equal">Equal</a></li></ul><h2 id="文档" tabindex="-1">文档 <a class="header-anchor" href="#文档" aria-label="Permalink to &quot;文档&quot;">​</a></h2><h3 id="NewCopyOnWriteList" tabindex="-1">NewCopyOnWriteList <a class="header-anchor" href="#NewCopyOnWriteList" aria-label="Permalink to &quot;NewCopyOnWriteList&quot;">​</a></h3><p>返回一个具有空切片的 CopyOnWriteList。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">CopyOnWriteList</span><span style="color:#F6F6F4;">[T any] </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data []T</span></span>
<span class="line"><span style="color:#F6F6F4;">    lock sync.Locker</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">() </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">]</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    data </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span>
<span class="line"><span style="color:#393A34;">    lock sync</span><span style="color:#999999;">.</span><span style="color:#393A34;">Locker</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">NewCopyOnWriteList</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span></span></code></pre></div><h4 id="示例" tabindex="-1">示例 <a class="header-anchor" href="#示例" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">	l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l)</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Size" tabindex="-1">Size <a class="header-anchor" href="#Size" aria-label="Permalink to &quot;Size&quot;">​</a></h3><p>返回 CopyOnWriteList 的长度。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (l </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">Size</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">int</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">l </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Size</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span></span></code></pre></div><h4 id="示例-1" tabindex="-1">示例 <a class="header-anchor" href="#示例-1" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">Size</span><span style="color:#F6F6F4;">())</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">Size</span><span style="color:#999999;">())</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Get" tabindex="-1">Get <a class="header-anchor" href="#Get" aria-label="Permalink to &quot;Get&quot;">​</a></h3><p>返回列表中指定位置的元素</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">Get</span><span style="color:#F6F6F4;">(index </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">) </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Get</span><span style="color:#999999;">(</span><span style="color:#393A34;">index </span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">T</span></span></code></pre></div><h4 id="示例-2" tabindex="-1">示例 <a class="header-anchor" href="#示例-2" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">	l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">Get</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">Get</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Set" tabindex="-1">Set <a class="header-anchor" href="#Set" aria-label="Permalink to &quot;Set&quot;">​</a></h3><p>将此列表中指定位置的元素替换为指定元素。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">Set</span><span style="color:#F6F6F4;">(index </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">, e T) (oldValue </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">T, ok </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Set</span><span style="color:#999999;">(</span><span style="color:#393A34;">index </span><span style="color:#AB5959;">int</span><span style="color:#999999;">,</span><span style="color:#393A34;"> e T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">oldValue </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> ok </span><span style="color:#AB5959;">bool</span><span style="color:#999999;">)</span></span></code></pre></div><h4 id="示例-3" tabindex="-1">示例 <a class="header-anchor" href="#示例-3" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">    l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">Set</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">Set</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">4</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Remove" tabindex="-1">Remove <a class="header-anchor" href="#Remove" aria-label="Permalink to &quot;Remove&quot;">​</a></h3><h3 id="IndexOf" tabindex="-1">IndexOf <a class="header-anchor" href="#IndexOf" aria-label="Permalink to &quot;IndexOf&quot;">​</a></h3><p>返回列表中值的索引，如果没有找到返回-1。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">IndexOf</span><span style="color:#F6F6F4;">(e T) </span><span style="color:#97E1F1;font-style:italic;">int</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">IndexOf</span><span style="color:#999999;">(</span><span style="color:#393A34;">e T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span></span></code></pre></div><h4 id="示例-4" tabindex="-1">示例 <a class="header-anchor" href="#示例-4" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">IndexOf</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">IndexOf</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="LastIndexOf" tabindex="-1">LastIndexOf <a class="header-anchor" href="#LastIndexOf" aria-label="Permalink to &quot;LastIndexOf&quot;">​</a></h3><p>返回指定元素在此列表中最后出现的索引，如果此列表不包含该元素，则返回-1。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">LastIndexOf</span><span style="color:#F6F6F4;">(e T) </span><span style="color:#97E1F1;font-style:italic;">int</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">LastIndexOf</span><span style="color:#999999;">(</span><span style="color:#393A34;">e T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span></span></code></pre></div><h4 id="示例-5" tabindex="-1">示例 <a class="header-anchor" href="#示例-5" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">	l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">LastIndexOf</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">,</span><span style="color:#2F798A;">1</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">LastIndexOf</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsEmpty" tabindex="-1">IsEmpty <a class="header-anchor" href="#IsEmpty" aria-label="Permalink to &quot;IsEmpty&quot;">​</a></h3><p>如果此列表不包含任何元素，则返回 true。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">IsEmpty</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">IsEmpty</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><h4 id="示例-6" tabindex="-1">示例 <a class="header-anchor" href="#示例-6" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">	l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{})</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">IsEmpty</span><span style="color:#F6F6F4;">())</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">IsEmpty</span><span style="color:#999999;">())</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Contain" tabindex="-1">Contain <a class="header-anchor" href="#Contain" aria-label="Permalink to &quot;Contain&quot;">​</a></h3><p>判断 CopyOnWriteList 是否包含某个元素</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">Contain</span><span style="color:#F6F6F4;">(e T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Contain</span><span style="color:#999999;">(</span><span style="color:#393A34;">e T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><h4 id="示例-7" tabindex="-1">示例 <a class="header-anchor" href="#示例-7" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">Contain</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">Contain</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ValueOf" tabindex="-1">ValueOf <a class="header-anchor" href="#ValueOf" aria-label="Permalink to &quot;ValueOf&quot;">​</a></h3><p>返回列表中索引处的值指针</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">ValueOf</span><span style="color:#F6F6F4;">(index </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">) []T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ValueOf</span><span style="color:#999999;">(</span><span style="color:#393A34;">index </span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span></code></pre></div><h4 id="示例-8" tabindex="-1">示例 <a class="header-anchor" href="#示例-8" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">ValueOf</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">ValueOf</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Add" tabindex="-1">Add <a class="header-anchor" href="#Add" aria-label="Permalink to &quot;Add&quot;">​</a></h3><p>将指定的元素追加到此列表的末尾。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">Add</span><span style="color:#F6F6F4;">(e T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Add</span><span style="color:#999999;">(</span><span style="color:#393A34;">e T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><h4 id="示例-9" tabindex="-1">示例 <a class="header-anchor" href="#示例-9" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">	l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">	l.</span><span style="color:#97E1F1;">Add</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">getList</span><span style="color:#F6F6F4;">())</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">	l</span><span style="color:#999999;">.</span><span style="color:#998418;">Add</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">getList</span><span style="color:#999999;">())</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="AddAll" tabindex="-1">AddAll <a class="header-anchor" href="#AddAll" aria-label="Permalink to &quot;AddAll&quot;">​</a></h3><p>将指定集合中的所有元素追加到此列表的末尾</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">AddAll</span><span style="color:#F6F6F4;">(e []T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AddAll</span><span style="color:#999999;">(</span><span style="color:#393A34;">e </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><h4 id="示例-10" tabindex="-1">示例 <a class="header-anchor" href="#示例-10" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">    l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    l.</span><span style="color:#97E1F1;">AddAll</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">getList</span><span style="color:#F6F6F4;">())</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    l</span><span style="color:#999999;">.</span><span style="color:#998418;">AddAll</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">4</span><span style="color:#999999;">,</span><span style="color:#2F798A;">5</span><span style="color:#999999;">,</span><span style="color:#2F798A;">6</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">getList</span><span style="color:#999999;">())</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="AddByIndex" tabindex="-1">AddByIndex <a class="header-anchor" href="#AddByIndex" aria-label="Permalink to &quot;AddByIndex&quot;">​</a></h3><p>将指定元素插入此列表中的指定位置。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">AddByIndex</span><span style="color:#F6F6F4;">(index </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">, e T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AddByIndex</span><span style="color:#999999;">(</span><span style="color:#393A34;">index </span><span style="color:#AB5959;">int</span><span style="color:#999999;">,</span><span style="color:#393A34;"> e T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><h4 id="示例-11" tabindex="-1">示例 <a class="header-anchor" href="#示例-11" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">	l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">	list.</span><span style="color:#97E1F1;">AddByIndex</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">getList</span><span style="color:#F6F6F4;">())</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">	list</span><span style="color:#999999;">.</span><span style="color:#998418;">AddByIndex</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">6</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">getList</span><span style="color:#999999;">())</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DeleteAt" tabindex="-1">DeleteAt <a class="header-anchor" href="#DeleteAt" aria-label="Permalink to &quot;DeleteAt&quot;">​</a></h3><p>移除此列表中指定位置的元素。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">DeleteAt</span><span style="color:#F6F6F4;">(index </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">) (oldValue </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">T, ok </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DeleteAt</span><span style="color:#999999;">(</span><span style="color:#393A34;">index </span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">oldValue </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> ok </span><span style="color:#AB5959;">bool</span><span style="color:#999999;">)</span></span></code></pre></div><h4 id="示例-12" tabindex="-1">示例 <a class="header-anchor" href="#示例-12" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">	l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">	list.</span><span style="color:#97E1F1;">DeleteAt</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">getList</span><span style="color:#F6F6F4;">())</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">	list</span><span style="color:#999999;">.</span><span style="color:#998418;">DeleteAt</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">getList</span><span style="color:#999999;">())</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DeleteIf" tabindex="-1">DeleteIf <a class="header-anchor" href="#DeleteIf" aria-label="Permalink to &quot;DeleteIf&quot;">​</a></h3><p>从此列表中删除第一个出现的指定元素(如果该元素存在)。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">DeleteIf</span><span style="color:#F6F6F4;">(f </span><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;">(T) </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;">) (oldValue </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">T, ok </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DeleteIf</span><span style="color:#999999;">(</span><span style="color:#393A34;">f </span><span style="color:#1E754F;">func</span><span style="color:#999999;">(</span><span style="color:#393A34;">T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">oldValue </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> ok </span><span style="color:#AB5959;">bool</span><span style="color:#999999;">)</span></span></code></pre></div><h4 id="示例-13" tabindex="-1">示例 <a class="header-anchor" href="#示例-13" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">    l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    list.</span><span style="color:#97E1F1;">DeleteIf</span><span style="color:#F6F6F4;">(</span><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;">(i </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> i </span><span style="color:#F286C4;">==</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">2</span></span>
<span class="line"><span style="color:#F6F6F4;">    })</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">getList</span><span style="color:#F6F6F4;">())</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    list</span><span style="color:#999999;">.</span><span style="color:#998418;">DeleteIf</span><span style="color:#999999;">(</span><span style="color:#1E754F;">func</span><span style="color:#999999;">(</span><span style="color:#393A34;">i </span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> i </span><span style="color:#AB5959;">==</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">2</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">getList</span><span style="color:#999999;">())</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DeleteBy" tabindex="-1">DeleteBy <a class="header-anchor" href="#DeleteBy" aria-label="Permalink to &quot;DeleteBy&quot;">​</a></h3><p>从此列表中删除第一个出现的指定元素(如果该元素存在)。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">DeleteBy</span><span style="color:#F6F6F4;">(e T) (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">T </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DeleteBy</span><span style="color:#999999;">(</span><span style="color:#393A34;">e T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">T </span><span style="color:#AB5959;">bool</span><span style="color:#999999;">)</span></span></code></pre></div><h4 id="示例-14" tabindex="-1">示例 <a class="header-anchor" href="#示例-14" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">()  {</span></span>
<span class="line"><span style="color:#F6F6F4;">	l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    list.</span><span style="color:#97E1F1;">DeleteBy</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">getList</span><span style="color:#F6F6F4;">())</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;">  </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    list</span><span style="color:#999999;">.</span><span style="color:#998418;">DeleteBy</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">getList</span><span style="color:#999999;">())</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DeleteRange" tabindex="-1">DeleteRange <a class="header-anchor" href="#DeleteRange" aria-label="Permalink to &quot;DeleteRange&quot;">​</a></h3><p>从该列表中删除索引介于 fromIndex(包含)和 toIndex(不包含)之间的所有元素。 (左闭右开)。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">DeleteRange</span><span style="color:#F6F6F4;">(start </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">, end </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DeleteRange</span><span style="color:#999999;">(</span><span style="color:#393A34;">start </span><span style="color:#AB5959;">int</span><span style="color:#999999;">,</span><span style="color:#393A34;"> end </span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span></code></pre></div><h4 id="示例-15" tabindex="-1">示例 <a class="header-anchor" href="#示例-15" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">8</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">9</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    list.</span><span style="color:#97E1F1;">DeleteRange</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">getList</span><span style="color:#F6F6F4;">())</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">,</span><span style="color:#2F798A;">4</span><span style="color:#999999;">,</span><span style="color:#2F798A;">5</span><span style="color:#999999;">,</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#2F798A;">7</span><span style="color:#999999;">,</span><span style="color:#2F798A;">8</span><span style="color:#999999;">,</span><span style="color:#2F798A;">9</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    list</span><span style="color:#999999;">.</span><span style="color:#998418;">DeleteRange</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">getList</span><span style="color:#999999;">())</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Equal" tabindex="-1">Equal <a class="header-anchor" href="#Equal" aria-label="Permalink to &quot;Equal&quot;">​</a></h3><p>如果指定的对象等于此列表，则返回 true。</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">CopyOnWriteList[T]) </span><span style="color:#62E884;">Equal</span><span style="color:#F6F6F4;">(e []T) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">CopyOnWriteList</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Equal</span><span style="color:#999999;">(</span><span style="color:#393A34;">e </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><h4 id="示例-16" tabindex="-1">示例 <a class="header-anchor" href="#示例-16" aria-label="Permalink to &quot;示例&quot;">​</a></h4><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    l </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> list.</span><span style="color:#97E1F1;">NewCopyOnWriteList</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">8</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">9</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(l.</span><span style="color:#97E1F1;">Equal</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">8</span><span style="color:#F6F6F4;">,</span><span style="color:#BF9EEE;">9</span><span style="color:#F6F6F4;">}))</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/datastructure/list</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">l</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> list</span><span style="color:#999999;">.</span><span style="color:#998418;">NewCopyOnWriteList</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">,</span><span style="color:#2F798A;">4</span><span style="color:#999999;">,</span><span style="color:#2F798A;">5</span><span style="color:#999999;">,</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#2F798A;">7</span><span style="color:#999999;">,</span><span style="color:#2F798A;">8</span><span style="color:#999999;">,</span><span style="color:#2F798A;">9</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">l</span><span style="color:#999999;">.</span><span style="color:#998418;">Equal</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#2F798A;">3</span><span style="color:#999999;">,</span><span style="color:#2F798A;">4</span><span style="color:#999999;">,</span><span style="color:#2F798A;">5</span><span style="color:#999999;">,</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#2F798A;">7</span><span style="color:#999999;">,</span><span style="color:#2F798A;">8</span><span style="color:#999999;">,</span><span style="color:#2F798A;">9</span><span style="color:#999999;">}))</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div>`,89),r=[e,t,c];function y(F,i,d,E,A,u){return n(),l("div",null,r)}const f=a(o,[["render",y]]);export{g as __pageData,f as default};
