Skip to content

Commit

Permalink
list: Add unrolled linked list
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Aug 12, 2024
1 parent 38df857 commit 0bb13e7
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
88 changes: 88 additions & 0 deletions src/list/assets/unrolled-linked-list.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<mxfile host="Electron" modified="2024-08-12T04:51:14.192Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.2.5 Chrome/120.0.6099.109 Electron/28.1.0 Safari/537.36" etag="lwBsjKLUz9HUVrydQkuL" version="24.2.5" type="device">
<diagram name="Page-1" id="G8ZvJWXJsHYqm7BaVf0D">
<mxGraphModel dx="1420" dy="821" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="6nbiD8FfBm9z2fzWC2GB-10" value="Unrolled Linked List" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Ubuntu;fontSize=20;fontStyle=0;" parent="1" vertex="1">
<mxGeometry x="320" y="480" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-52" value="3" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#82b366;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#d5e8d4;" vertex="1" parent="1">
<mxGeometry x="320" y="240" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-128" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;" edge="1" parent="1" source="0Mc5ShmmSgY_8YMRMMed-72" target="0Mc5ShmmSgY_8YMRMMed-122">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-72" value="" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" vertex="1" parent="1">
<mxGeometry x="280" y="240" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-137" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;" edge="1" parent="1" source="0Mc5ShmmSgY_8YMRMMed-113" target="0Mc5ShmmSgY_8YMRMMed-72">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-113" value="Head" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Ubuntu;fontSize=16;fontStyle=0;" vertex="1" parent="1">
<mxGeometry x="275" y="160" width="50" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-116" value="1" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="360" y="240" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-117" value="2" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="400" y="240" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-118" value="3" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="440" y="240" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-119" value="" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="480" y="240" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-120" value="" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="520" y="240" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-121" value="4" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#82b366;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#d5e8d4;" vertex="1" parent="1">
<mxGeometry x="320" y="320" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-136" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=14;fontStyle=0;endArrow=block;endFill=1;fillColor=#dae8fc;" edge="1" parent="1" source="0Mc5ShmmSgY_8YMRMMed-122" target="0Mc5ShmmSgY_8YMRMMed-130">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-122" value="" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" vertex="1" parent="1">
<mxGeometry x="280" y="320" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-123" value="4" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="360" y="320" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-124" value="5" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="400" y="320" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-125" value="6" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="440" y="320" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-126" value="7" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="480" y="320" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-127" value="" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="520" y="320" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-129" value="2" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#82b366;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#d5e8d4;" vertex="1" parent="1">
<mxGeometry x="320" y="400" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-130" value="" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#b85450;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#f8cecc;" vertex="1" parent="1">
<mxGeometry x="280" y="400" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-131" value="8" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="360" y="400" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-132" value="9" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="400" y="400" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-133" value="" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="440" y="400" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-134" value="" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="480" y="400" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="0Mc5ShmmSgY_8YMRMMed-135" value="" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;strokeColor=#6c8ebf;strokeWidth=1;fontFamily=Ubuntu;fontSize=16;fontStyle=0;fillColor=#dae8fc;" vertex="1" parent="1">
<mxGeometry x="520" y="400" width="40" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
3 changes: 3 additions & 0 deletions src/list/assets/unrolled-linked-list.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion src/list/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,22 @@ struct person {
![list of list](assets/list-of-list.svg)
## Unrolled Linked List
## Unrolled Linked List
上面的链表中, 每个节点都只存储一个元素值, 我们也可以在一个节点中存储多个元素值.
这种链表就是 Unrolled Linked List.
特点:
- CPU 缓存更友好, 提高缓存命中率
- 访问相邻的元素的性能更好
其结构图如下所示:
![unrolled linked list](assets/unrolled-linked-list.svg)
C语言中的结构体声明如下:
```C
{{#include assets/list-types.c:44:49}}
```

0 comments on commit 0bb13e7

Please sign in to comment.