package main
import (
"fmt"
"math/big"
"sync"
"time"
)
//var myMap = make(map[uint]uint, 10)
//var lock sync.Mutex
var synMap sync.Map
func test(n *big.Int) {
res := big.NewInt(1)
for i := big.NewInt(1); i.Cmp(n) == -1; i.Add(i, big.NewInt(1)) {
res.Mul(i, res)
//fmt.Printf("i值为:%v,n为%v,res为 %v\n", i,n, res)
}
//lock.Lock()
//myMap[n] = res
//lock.Unlock()
if n.Sub(n,big.NewInt(1)).Cmp(big.NewInt(0))==1{
synMap.Store(n, res)
}
}
func normal(n uint) {
var res uint = 1
var i uint = 1
for ; i <= n; i++ {
res *= i
}
//lock.Lock()
//myMap[n] = res
//lock.Unlock()
synMap.Store(n, res)
}
func main() {
var i uint = 1
for ; i < 200; i++ {
//go normal(i)
go test(big.NewInt(int64(i)))
}
time.Sleep(time.Second)
synMap.Range(func(k, v interface{}) bool {
fmt.Print(k)
fmt.Print(":")
fmt.Printf("%v", v)
fmt.Println()
return true
})
//for k, v := range myMap {
// fmt.Printf("map[%d]=%d\n", k, v)
//}
}