score = (左边32位放置 A维度正序值) + (右边32位放置 INT_MAX - 时间秒数值)
package main
import (
"fmt"
"time"
)
const INT_MAX = int64(^uint32(0) >> 1)
func main() {
fmt.Println(INT_MAX)
now := time.Now()
secondes := now.Unix()
fmt.Println("原时间 = ",secondes)
offset := int64(29989)
fmt.Println("原offset = ",offset)
score := offset << 32 | secondes
fmt.Println("总分数 = ",score)
sss := score & 0x7fffffff
fmt.Printf("sss type %T ", sss )
fmt.Println("转码时间 = ",sss)
fmt.Println("转码offset = " , int32(score >> 32))
time.Sleep(2*time.Second)
now1 := time.Now().Unix()
fmt.Println("转码时间now1 = ",now1)
score1 := offset << 32 | (INT_MAX - now1)
time.Sleep(2*time.Second)
now2 := time.Now().Unix()
fmt.Println("转码时间now2 = ",now2)
score2 := offset << 32 | (INT_MAX - now2)
time.Sleep(2*time.Second)
now3 := time.Now().Unix()
fmt.Println("转码时间now3 = ",now3)
score3 := offset << 32 | (INT_MAX - now3)
// 排序分值
fmt.Println("总分数1 = ",score1)
fmt.Println("总分数2 = ",score2)
fmt.Println("总分数3 = ",score3)
// 逆推
fmt.Println("逆推转码时间now1 = ",INT_MAX - score1 & 0x7fffffff)
fmt.Println("逆推转码时间now2 = ",INT_MAX - score2 & 0x7fffffff)
fmt.Println("逆推转码时间now3 = ",INT_MAX - score3 & 0x7fffffff)
}
结果:
转码时间now1 = 1623627431
转码时间now2 = 1623627433
转码时间now3 = 1623627435
总分数1 = 128802298095960
总分数2 = 128802298095958
总分数3 = 128802298095956
逆推转码时间now1 = 1623627431
逆推转码时间now2 = 1623627433
逆推转码时间now3 = 1623627435