Skip to content

Commit 0f90c5b

Browse files
committed
add treap ascii img
1 parent 5a03573 commit 0f90c5b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

memory.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,48 @@ type treapNode struct {
12871287
- spanKey 是 mspan 指针,其地址的值作为二叉搜索树的第二个排序依据,即页数相同的情况下,spanKey 大的会在当前节点的右边
12881288
- priority 是随机生成的权重值,该权重值会被作为小顶堆的排序依据
12891289

1290+
下面是一个 treap 结构的示例:
1291+
1292+
```
1293+
┌──────────────────────┐
1294+
│ │
1295+
│ │
1296+
│ npagesKey: 130 │
1297+
│ spanKey: 0x1234567 │
1298+
│ priority: 1 │
1299+
│ │
1300+
│ │
1301+
└──────────────────────┘
1302+
1303+
┌────────────────────┴──────────────────┐
1304+
│ │
1305+
▼ ▼
1306+
┌──────────────────────┐ ┌──────────────────────┐
1307+
│ │ │ │
1308+
│ │ │ │
1309+
│ npagesKey: 129 │ │ npagesKey: 132 │
1310+
│ spanKey: 0x4231560 │ │ spanKey: 0x2234521 │
1311+
│ priority: 10 │ │ priority: 12 │
1312+
│ │ │ │
1313+
│ │ │ │
1314+
└──────────────────────┘ └──────────────────────┘
1315+
1316+
┌───────────┴───────────────────┐
1317+
│ │
1318+
▼ ▼
1319+
┌──────────────────────┐ ┌──────────────────────┐
1320+
│ │ │ │
1321+
│ │ │ │
1322+
│ npagesKey: 132 │ │ npagesKey: 136 │
1323+
│ spanKey: 0x2234000 │ │ spanKey: 0x2314213 │
1324+
│ priority: 14 │ │ priority: 131 │
1325+
│ │ │ │
1326+
│ │ │ │
1327+
└──────────────────────┘ └──────────────────────┘
1328+
```
1329+
1330+
可以看到,把 npagesKey 和 spanKey 当作数据的话,treap 就是二叉搜索树。把 priority 当作数据,treap 就是小顶堆。
1331+
12901332
## 栈内存分配流程
12911333

12921334
```go

0 commit comments

Comments
 (0)