9c93a35685
2020/12/31:添加container包使用示例和源码分析
2020/12/31:添加validator.v8源码解析和使用示例
37 lines
596 B
Go
37 lines
596 B
Go
/*
|
||
* @Author : huangzj
|
||
* @Time : 2020/12/2 15:39
|
||
* @Description:
|
||
*/
|
||
|
||
package testContainer
|
||
|
||
type Person struct {
|
||
Name string //名字
|
||
Age int //年龄
|
||
Money float64 //身价
|
||
}
|
||
|
||
type heapTool []*Person
|
||
|
||
func (h *heapTool) Less(i, j int) bool {
|
||
return (*h)[i].Age < (*h)[j].Age
|
||
}
|
||
|
||
func (h *heapTool) Swap(i, j int) {
|
||
(*h)[i], (*h)[j] = (*h)[j], (*h)[i]
|
||
}
|
||
|
||
func (h *heapTool) Len() int {
|
||
return len(*h)
|
||
}
|
||
|
||
func (h *heapTool) Pop() (v interface{}) {
|
||
*h, v = (*h)[:h.Len()-1], (*h)[h.Len()-1]
|
||
return
|
||
}
|
||
|
||
func (h *heapTool) Push(v interface{}) {
|
||
*h = append(*h, v.(*Person))
|
||
}
|