Posts

go test 工具 file with name endwith `_test.go` was build by `go test` instead of `go build` there are three kind of Function need to be remember: Function which Name starts with `Test` was used as UnitTest or FunctionalTest Function which Name starts with `Benchmark` was used as Benmark. Function which Name starts with ‘Example` was used as Example. Test Function test function must: import `testing` package has `t *testing.T` as only argument use tool-function in `testing.
Jul 18, 2021
3 min read
introduce 在编译是不知道类型的情况下,可在运行时查看值,调用方法,更新变量,以及对布局进行操作的机制. 反射让我们把类型当作头等值 动态类型 vs 动态值 反射定义了两个重要的类型 reflect.Type, reflect.Value reflect.Type 类型描述符 接口值的动态类型也是类型描述符 满足fmt.Stringer接口 t := reflect.TypeOf(3) fmt.Println(t.String()) fmt.Println(t) // 反射总是返回具体类型 var w io.Writer = os.Stdout fmt.Println(reflect.TypeOf(w)) // return os.File int int *os.File reflect.Value v := reflect.ValueOf(3) fmt.Println(v) // this will handle reflect.Value fmt.Println("%v\n", v) // implement the fmt.Stringer interface, but only return `Type` if not string fmt.Println(v.String()) // get `Value` Type t := v.Type() fmt.Println(t.String()) // the reverse operator x := v.Interface() // return `interface{}` i := x.
Jul 18, 2021
6 min read
tree root 树根 node 节点 leaf 叶子节点 parent 父节点 children 子节点 兄弟节点 二叉查找树 性质 parent have two child, left and right key(left) <= key(parent) <= key(right) TODOAVL树 带平衡条件的特殊二叉树. TODO 源码实现 性质 every node has a height property every node: abs(height(left(node)) - height(right(node)) <= 1 支持的操作 查找 同二叉树 插入 需要通过旋转来保持AVl性质. 分四种情况: 左左 右右 左右 右左 两两对称, 同方向使用单旋, 不同方式需要使用双旋转. 递归向上保持??? TODO伪码 TODO删除 TODOred-black tree concept black-height 黑高度, 从节点到叶子节点的黑节点数
Jul 18, 2021
1 min read