mirror of
https://gitee.com/willfree/tcpserver-client.git
synced 2026-10-04 19:52:23 +08:00
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"container/heap"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
// 测试最小堆
|
|
var h = CanBeUsedAddrHeap{}
|
|
time1:=time.Now()
|
|
fmt.Println("time1: ",time1)
|
|
addr1:=CanBeUsedAddr{ip: "1",updateTime: time1}
|
|
heap.Push(&h,addr1)
|
|
h.PrintSelf()
|
|
time.Sleep(time.Second*3)
|
|
|
|
time2:=time.Now()
|
|
fmt.Println("time2: ",time2)
|
|
addr2:=CanBeUsedAddr{ip: "2",updateTime: time2}
|
|
heap.Push(&h,addr2)
|
|
h.PrintSelf()
|
|
time.Sleep(time.Second*3)
|
|
|
|
time3:=time.Now()
|
|
fmt.Println("time3: ",time3)
|
|
addr3:=CanBeUsedAddr{ip: "3",updateTime: time3}
|
|
heap.Push(&h,addr3)
|
|
h.PrintSelf()
|
|
time.Sleep(time.Second*3)
|
|
|
|
m,_:=time.ParseDuration("-3m")
|
|
time4:=time.Now().Add(m)
|
|
fmt.Println("time4: ",time4)
|
|
addr4:=CanBeUsedAddr{ip: "4",updateTime: time4}
|
|
heap.Push(&h,addr4)
|
|
h.PrintSelf()
|
|
|
|
m,_=time.ParseDuration("-5m")
|
|
time5:=time.Now().Add(m)
|
|
fmt.Println("time5: ",time5)
|
|
addr5:=CanBeUsedAddr{ip: "5",updateTime: time5}
|
|
heap.Push(&h,addr5)
|
|
h.PrintSelf()
|
|
|
|
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()
|
|
|
|
//go startMainServer()
|
|
//
|
|
//// 等待用户输入。如果输入q,则退出程序
|
|
//inputReader := bufio.NewReader(os.Stdin)
|
|
//input, _ := inputReader.ReadString('\n')
|
|
//trimmedInput := strings.Trim(input, "\r\n")
|
|
//// 判断是否要退出
|
|
//if trimmedInput == "Q" {
|
|
// return
|
|
//}
|
|
}
|
|
|
|
// 启动记录可用IP的Server处理程序
|
|
func startMainServer() {
|
|
addrServer := new(AddrServer)
|
|
addrServer.start()
|
|
}
|
|
|
|
|