github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/structure/sets/skipset/util.go (about) 1 package skipset 2 3 import ( 4 _ "unsafe" // for linkname 5 6 "github.com/songzhibin97/go-baseutils/sys/fastrand" 7 8 "github.com/songzhibin97/go-baseutils/internal/wyhash" 9 ) 10 11 const ( 12 maxLevel = 16 13 p = 0.25 14 defaultHighestLevel = 3 15 ) 16 17 func hash(s string) uint64 { 18 return wyhash.Sum64String(s) 19 } 20 21 //go:linkname cmpstring runtime.cmpstring 22 func cmpstring(a, b string) int 23 24 func randomLevel() int { 25 level := 1 26 for fastrand.Uint32n(1/p) == 0 { 27 level++ 28 } 29 if level > maxLevel { 30 return maxLevel 31 } 32 return level 33 }