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