mirror of
https://gitee.com/willfree/tcpserver-client.git
synced 2026-06-08 14:49:33 +08:00
最小堆测试查找和删除操作
This commit is contained in:
@@ -57,6 +57,14 @@ func (h *CanBeUsedAddrHeap) IsExistAddr(addr CanBeUsedAddr) int{
|
||||
}
|
||||
return -1
|
||||
}
|
||||
func (h *CanBeUsedAddrHeap) IsExistAddrIP(ip string) int{
|
||||
for i := 0; i < len(*h); i++ {
|
||||
if (*h)[i].ip==ip {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// 打印所有元素
|
||||
func (h *CanBeUsedAddrHeap) PrintSelf() {
|
||||
|
||||
+17
-11
@@ -44,18 +44,24 @@ func main() {
|
||||
heap.Push(&h,addr5)
|
||||
h.PrintSelf()
|
||||
|
||||
addrPop := heap.Pop(&h).(CanBeUsedAddr)
|
||||
fmt.Println("pop ip: "+addrPop.ip)
|
||||
h.PrintSelf()
|
||||
addrPop = heap.Pop(&h).(CanBeUsedAddr)
|
||||
fmt.Println("pop ip: "+addrPop.ip)
|
||||
addrPop = heap.Pop(&h).(CanBeUsedAddr)
|
||||
fmt.Println("pop ip: "+addrPop.ip)
|
||||
addrPop = heap.Pop(&h).(CanBeUsedAddr)
|
||||
fmt.Println("pop ip: "+addrPop.ip)
|
||||
addrPop = heap.Pop(&h).(CanBeUsedAddr)
|
||||
fmt.Println("pop ip: "+addrPop.ip)
|
||||
fmt.Println("ip 3 exist: ",h.IsExistAddrIP("3"))
|
||||
fmt.Println("ip 4 exist: ",h.IsExistAddrIP("4"))
|
||||
fmt.Println("ip 0 exist: ",h.IsExistAddrIP("0"))
|
||||
heap.Remove(&h,3)
|
||||
h.PrintSelf()
|
||||
|
||||
//addrPop := heap.Pop(&h).(CanBeUsedAddr)
|
||||
//fmt.Println("pop ip: "+addrPop.ip)
|
||||
//h.PrintSelf()
|
||||
//addrPop = heap.Pop(&h).(CanBeUsedAddr)
|
||||
//fmt.Println("pop ip: "+addrPop.ip)
|
||||
//addrPop = heap.Pop(&h).(CanBeUsedAddr)
|
||||
//fmt.Println("pop ip: "+addrPop.ip)
|
||||
//addrPop = heap.Pop(&h).(CanBeUsedAddr)
|
||||
//fmt.Println("pop ip: "+addrPop.ip)
|
||||
//addrPop = heap.Pop(&h).(CanBeUsedAddr)
|
||||
//fmt.Println("pop ip: "+addrPop.ip)
|
||||
//h.PrintSelf()
|
||||
//addrServer := new(AddrServer)
|
||||
//addrServer.start()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user