diff --git a/ch12/3/ch12_3.go b/ch12/3/ch12_3.go new file mode 100644 index 0000000..54c6ba4 --- /dev/null +++ b/ch12/3/ch12_3.go @@ -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]) + } +} diff --git a/ch12/3/go.mod b/ch12/3/go.mod new file mode 100644 index 0000000..d10e9be --- /dev/null +++ b/ch12/3/go.mod @@ -0,0 +1,3 @@ +module gitea.local.lab/Lbenedar/learning_go/ch12/3 + +go 1.25.0