- 博客(16)
- 收藏
- 关注
原创 Merge sort
核心思路先将一个数据拆分成不可拆分的部分,然后在对小部分进行排序,小部分排完序号,在不断往上归并 例如,a,c,d 分别为排序好的小段,然后在针对a,c合并为e,在e和d进行合并。
2024-01-16 23:12:21
399
1
原创 eth s.snaps.Cap(root, 128) 和 TriesInMemory
Geth 在处理每个新区块时,会创建一个新的状态树,为了优化性能,Geth 会将最近的状态树保留在内存中,而不是立即写入磁盘。当发生链重组(reorg)时,Geth 可能需要回滚到一个旧的状态,如果 Geth 在内存中保留了足够的状态树,它就可以快速地回滚到旧的状态,而不需要从磁盘中读取数据。s.snaps.Cap(root, 128) 是 Geth 的一个实际的函数调用,它在 writeBlockWithState 函数中被调用,用于在处理新的区块时修剪(pruning)旧的状态数据。
2023-06-14 00:48:20
154
原创 eth TriesInMemory 的含义
这样做的原因是,如果发生链重组(reorg,即区块链的主链发生变化,旧的区块被新的区块替代),Geth可能需要回滚到一个旧的状态。如果Geth在内存中保留了足够的状态树,它就可以快速地回滚到旧的状态,而不需要从磁盘中读取数据,这可以大大提高性能。为了优化性能,Geth会将最近的状态树保留在内存中,而不是立即写入磁盘。disklayer就是一个扁平的kv db,上面的128层diff layer就是我们可以修改的。的值可能会增加Geth的内存使用,而减小这个值可能会降低处理链重组的性能。
2023-06-14 00:09:02
153
原创 eth blockChain.go::BlockChain:writeBlockWithState
这个函数是Geth处理新区块的核心部分,但是它是一个内部函数,不会被直接暴露给用户。每当一个新的区块被网络传播到你的节点,你的节点需要将这个区块以及由这个区块引发的所有状态变化(比如账户余额的变化,智能合约的变化等等)保存到本地数据库。是一个非常重要的内部函数。这个函数的职责是将一个新的区块以及与之对应的状态更新写入到Geth的本地数据库中。将区块中的每个交易引发的状态变化写入到数据库的状态部分。将区块链的“头”(也就是最新的区块)更新为新的区块。将区块的数据写入到本地数据库的区块链部分。
2023-06-14 00:03:45
102
转载 golang string join
To compare different join string way used memoryCodefunc randomString(n int) string { b := make([]byte, n) for i := range b { b[i] = letterBytes[rand.Intn(len(letterBytes))] } return string(b)}func concat(n int) string { var s strings.Bui..
2022-05-19 14:58:13
458
原创 <two>Insertion sort
Inserttion sortIt is a simple sorting algorithm that work simliar to the way you sort palying cards in your hand. split into sorted and an unsorted patpick a number N, compare (n~1,and n-1 has sorted.), if n < (n-1), index[n] <n-1. and n-1 compa
2022-05-17 15:14:52
114
原创 Golang Bibble core notes
1. Execute defer inside the loopDescribe:Executing defer inside the loop will cause the resource to be relased late,because defer id executed after the method endsError Code:func error_code_defer() { for i := 0; i < 50; i++ { f, err := o
2022-05-17 11:33:29
107
原创 Find a digit fomr matrix
DescribeFind a digit from a two-dimensional array ,the array increae from left to right and from top to buttomCode:func findNumberIn2DArray(matrix [][]int, target int) bool { if len(matrix)==0{ return false } row:=0 ...
2022-05-16 23:24:11
166
原创 <two>Selection Sort
Core idea:each find max number,put it in unused postionIntroduceloop : Afind a number i and i is max number in array. swap i and n. then n=n-1repeat A until n ==0Code private static void selectSort(int[] a) { for (int i = 0;...
2022-05-14 20:32:09
145
原创 <one>Bubble sort
Bubble sort core idea: a stability sorting algorithm .find a max number and put it in last position by compare.Introduce: Begain A: starting from the first index , compare the first and the second.if the first greater than ...
2022-05-13 21:45:52
100
原创 An example of use golang generate test case
First step, write a sample of golang objectpackage objimport "log"func NewFarmer() (farmer *Farmer) { return &Farmer{life: &User{}}}func (this *Farmer) habbies() { this.life.Eat() this.life.Work()}type Farmer struct { life Life}type
2022-05-03 16:31:23
361
原创 read data from a closed chan with has data
func closeChan() { command := make(chan bool, 5) command <- true command <- true command <- true command <- true close(command) fmt.Printf("close chan has finished\n") for i := 0; i < 10; i++ { fmt.Printf("from a closed chan:%v\n".
2022-04-21 11:45:39
93
原创 tcp protocal
The tcp protocal is located in the transport layer protocal ,which is a reliable connection-oriented protocol.You can get a general idea of how it wroks in the diagram below
2022-03-12 18:40:10
4015
原创 sql in 和 exits
一 .概念in 查询返回一个列表,提供的列表给外查询使用exit 是对自查询进行判断是否存在行,存在则 true,不存在则为 falsefor x in ( select * from t1 ) loop if ( exists ( select null from t2 where y = x.x ) then OUTPUT THE RECORD! end if end loop 二.使用性能1. 如果查询的两个表大小差...
2022-03-07 15:47:43
2330
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人