Files
learning_go/ch12/3/ch12_3.go
2026-02-21 16:25:56 +03:00

29 lines
489 B
Go

package main
import (
"fmt"
"math"
"sync"
)
func CreateSqrtMap() map[int]float64 {
numKeys := 100_000
newMap := make(map[int]float64)
for i := range numKeys {
newMap[i] = math.Sqrt(float64(i))
}
return newMap
}
var initCreateMapSqrt func() map[int]float64 = sync.OnceValue(CreateSqrtMap)
func main() {
sqrtMap := initCreateMapSqrt()
n := 100_000 / 1_000
for i := range n {
keyVal := i * 1_000
fmt.Printf("Value of map by key[%d]: %f\n", keyVal, sqrtMap[keyVal])
}
}