add ch12_3

This commit is contained in:
lbenedar
2026-02-21 16:25:56 +03:00
parent cb314c36a9
commit b1935a4057
2 changed files with 31 additions and 0 deletions

28
ch12/3/ch12_3.go Normal file
View File

@@ -0,0 +1,28 @@
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])
}
}

3
ch12/3/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module gitea.local.lab/Lbenedar/learning_go/ch12/3
go 1.25.0