• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang mathutil.NewFC32函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cznic/mathutil.NewFC32函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFC32函数的具体用法?Golang NewFC32怎么用?Golang NewFC32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewFC32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestBug216

// https://code.google.com/p/camlistore/issues/detail?id=216
func TestBug216(t *testing.T) {
	const S = 2*kKV + 2 // 2*kKV+1 ok
	const N = 300000
	rng, err := mathutil.NewFC32(math.MinInt32, math.MaxInt32, true)
	if err != nil {
		t.Fatal(err)
	}
	k := make([]byte, S/2)
	v := make([]byte, S-S/2)
	tr := NewBTree(nil)
	for i := 0; i < N; i++ {
		for i := range k {
			k[i] = byte(rng.Next())
		}
		for i := range v {
			v[i] = byte(rng.Next())
		}

		if err := tr.Set(h2b(k, int64(i)), h2b(v, int64(i))); err != nil {
			t.Fatal(i, err)
		}

		if (i+1)%10000 == 0 {
			//dbg("%v", i+1)
		}
	}
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:28,代码来源:btree_test.go


示例2: rng

func rng() *mathutil.FC32 {
	x, err := mathutil.NewFC32(math.MinInt32/4, math.MaxInt32/4, false)
	if err != nil {
		panic(err)
	}

	return x
}
开发者ID:nikandfor,项目名称:b,代码行数:8,代码来源:all_test.go


示例3: r32

func r32() *mathutil.FC32 {
	r, err := mathutil.NewFC32(math.MinInt32, math.MaxInt32, true)
	if err != nil {
		panic(err)
	}

	return r
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:8,代码来源:all_test.go


示例4: fc

func fc() *mathutil.FC32 {
	r, err := mathutil.NewFC32(0, math.MaxInt32, false)
	if err != nil {
		panic(err)
	}

	return r
}
开发者ID:mervin0502,项目名称:kv,代码行数:8,代码来源:all_test.go


示例5: TestModPow2

func TestModPow2(t *testing.T) {
	const N = 1e3
	data := []struct{ e, m uint32 }{
		// e == 0 -> x == 0
		{0, 2},
		{0, 3},
		{0, 4},

		{1, 2},
		{1, 3},
		{1, 4},
		{1, 5},

		{2, 2},
		{2, 3},
		{2, 4},
		{2, 5},

		{3, 2},
		{3, 3},
		{3, 4},
		{3, 5},
		{3, 6},
		{3, 7},
		{3, 8},
		{3, 9},

		{4, 2},
		{4, 3},
		{4, 4},
		{4, 5},
		{4, 6},
		{4, 7},
		{4, 8},
		{4, 9},
	}

	var got big.Int
	f := func(e, m uint32) {
		x := ModPow2(e, m)
		exp := ModPow(2, e, m)
		got.SetInt64(0)
		got.SetBit(&got, int(x), 1)
		if got.Cmp(exp) != 0 {
			t.Fatalf("\ne %d, m %d\ng: %s\ne: %s", e, m, &got, exp)
		}
	}

	for _, v := range data {
		f(v.e, v.m)
	}

	rg, _ := mathutil.NewFC32(2, 1<<10, true)
	for i := 0; i < N; i++ {
		f(uint32(rg.Next()), uint32(rg.Next()))
	}
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:57,代码来源:all_test.go


示例6: newRng

func newRng() *mathutil.FC32 {
	r, err := mathutil.NewFC32(0, math.MaxInt32, true)
	if err != nil {
		panic(err)
	}

	r.Seed(42)
	return r
}
开发者ID:cznic,项目名称:xc,代码行数:9,代码来源:all_test.go


示例7: MakeUniverse

func MakeUniverse(universeid uint) *Universe {
	bodyIdGen, _ := mathutil.NewFC32(0, 999999, true)

	return &Universe{
		Id: universeid,
		Space: &Space{
			Dimension: space.Vector{},
			Division:  nil,
			Sub:       nil,
			Entities:  make([]Entity, 0),
		},
		Entities:  make(map[uint]*Entity),
		bodyIdGen: bodyIdGen,
	}
}
开发者ID:OSPokemon,项目名称:ospokemon,代码行数:15,代码来源:universe.go


示例8: TestMod

func TestMod(t *testing.T) {
	const N = 1e4
	data := []struct {
		mod, n int64
		exp    uint32
	}{
		{0, 0x00, 3},
		{1, 0x01, 3},
		{3, 0x03, 3},
		{0, 0x07, 3},
		{1, 0x0f, 3},
		{3, 0x1f, 3},
		{0, 0x3f, 3},
		{1, 0x7f, 3},
		{3, 0xff, 3},
		{0, 0x1ff, 3},
	}

	var mod, n big.Int
	for _, v := range data {
		n.SetInt64(v.n)
		p := Mod(&mod, &n, v.exp)
		if p != &mod {
			t.Fatal(p)
		}

		if g, e := mod.Int64(), v.mod; g != e {
			t.Fatal(v.n, v.exp, g, e)
		}
	}

	f := func(in int64, exp uint32) {
		n.SetInt64(in)
		mod.Mod(&n, New(exp))
		e := mod.Int64()
		Mod(&mod, &n, exp)
		g := mod.Int64()
		if g != e {
			t.Fatal(in, exp, g, e)
		}
	}

	r32, _ := mathutil.NewFC32(1, 1e6, true)
	r64, _ := mathutil.NewFCBig(_0, big.NewInt(math.MaxInt64), true)
	for i := 0; i < N; i++ {
		f(r64.Next().Int64(), uint32(r32.Next()))
	}
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:48,代码来源:all_test.go


示例9: TestModPow

func TestModPow(t *testing.T) {
	const N = 2e2
	data := []struct{ b, e, m, r uint32 }{
		{0, 1, 1, 0},
		{0, 2, 1, 0},
		{0, 3, 1, 0},

		{1, 0, 1, 0},
		{1, 1, 1, 0},
		{1, 2, 1, 0},
		{1, 3, 1, 0},

		{2, 0, 1, 0},
		{2, 1, 1, 0},
		{2, 2, 1, 0},
		{2, 3, 1, 0},

		{2, 3, 4, 8},
		{2, 3, 5, 4},
		{2, 4, 3, 1},
		{3, 3, 3, 3},
		{3, 4, 5, 30},
	}

	f := func(b, e, m uint32, expect *big.Int) {
		got := ModPow(b, e, m)
		if got.Cmp(expect) != 0 {
			t.Fatal(b, e, m, got, expect)
		}
	}

	var r big.Int
	for _, v := range data {
		r.SetInt64(int64(v.r))
		f(v.b, v.e, v.m, &r)
	}

	rg, _ := mathutil.NewFC32(2, 1<<10, true)
	var bb big.Int
	for i := 0; i < N; i++ {
		b, e, m := uint32(rg.Next()), uint32(rg.Next()), uint32(rg.Next())
		bb.SetInt64(int64(b))
		f(b, e, m, mathutil.ModPowBigInt(&bb, New(e), New(m)))
	}
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:45,代码来源:all_test.go


示例10: main

// $ go run example2.go # view rand.png and rnd.png by your favorite pic viewer
//
// see http://www.boallen.com/random-numbers.html
func main() {
	sqr := image.Rect(0, 0, 511, 511)
	r, err := mathutil.NewFC32(math.MinInt32, math.MaxInt32, true)
	if err != nil {
		log.Fatal("NewFC32", err)
	}

	img := image.NewGray(sqr)
	for y := 0; y < 512; y++ {
		for x := 0; x < 512; x++ {
			if r.Next()&1 != 0 {
				img.Set(x, y, image.White)
			}
		}
	}
	buf := bytes.NewBuffer(nil)
	if err := png.Encode(buf, img); err != nil {
		log.Fatal("Encode rnd.png ", err)
	}

	if err := ioutil.WriteFile("rnd.png", buf.Bytes(), 0666); err != nil {
		log.Fatal("ioutil.WriteFile/rnd.png ", err)
	}

	r2 := rand.New(rand.NewSource(0))
	img = image.NewGray(sqr)
	for y := 0; y < 512; y++ {
		for x := 0; x < 512; x++ {
			if r2.Int()&1 != 0 {
				img.Set(x, y, image.White)
			}
		}
	}
	buf = bytes.NewBuffer(nil)
	if err := png.Encode(buf, img); err != nil {
		log.Fatal("Encode rand.png ", err)
	}

	if err := ioutil.WriteFile("rand.png", buf.Bytes(), 0666); err != nil {
		log.Fatal("ioutil.WriteFile/rand.png ", err)
	}
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:45,代码来源:example2.go


示例11: TestBase32Ext

func TestBase32Ext(t *testing.T) {
	const max = 640
	r, err := mathutil.NewFC32(math.MinInt32, math.MaxInt32, true)
	if err != nil {
		t.Fatal(err)
	}

	bin := []byte{}
	for i := 0; i < max; i++ {
		bin = append(bin, byte(r.Next()))
		cmp, err := Base32ExtDecode(Base32ExtEncode(bin))
		if err != nil {
			t.Fatal(err)
		}

		if !bytes.Equal(bin, cmp) {
			t.Fatalf("a: % x\nb: % x", bin, cmp)
		}
	}
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:20,代码来源:all_test.go


示例12: main

/*

$ # Usage e.g.:
$ go run example.go -max 1024 > mathutil.dat # generate 1kB of "random" data

*/
func main() {
	r, err := mathutil.NewFC32(math.MinInt32, math.MaxInt32, true)
	if err != nil {
		log.Fatal(err)
	}

	var mflag uint64
	flag.Uint64Var(&mflag, "max", 0, "limit output to max bytes")
	flag.Parse()
	stdout := bufio.NewWriter(os.Stdout)
	if mflag != 0 {
		for i := uint64(0); i < mflag; i++ {
			if err := stdout.WriteByte(byte(r.Next())); err != nil {
				log.Fatal(err)
			}
		}
		stdout.Flush()
		return
	}

	for stdout.WriteByte(byte(r.Next())) == nil {
	}
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:29,代码来源:example.go


示例13: testBenchReadRnd

func testBenchReadRnd(t *testing.T, n, block int) (dt int64) {
	println(252, n, block) //TODO-
	f, err := fcreate(*fnFlag)
	println(254) //TODO-
	if err != nil {
		println(254) //TODO-
		t.Fatal(err)
	}

	println(259) //TODO-
	defer func() {
		f.Accessor().Sync()
		probed(t, f)
		ec := f.Close()
		er := os.Remove(*fnFlag)
		if ec != nil {
			t.Fatal(ec)
		}

		if er != nil {
			t.Fatal(er)
		}
	}()

	h := make([]Handle, n)
	b := make([]byte, block)
	perc := 1
	if n >= 1000 {
		perc = n / 1000
	}
	println(281) //TODO-
	t0 := time.Now().UnixNano()
	for i := 0; i < n; i++ {
		if h[i], err = f.Alloc(b); err != nil {
			println(285) //TODO-
			t.Fatal(err)
		}
		if i != 0 && i%perc == 0 {
			dt := float64((time.Now().UnixNano() - t0) / 1e9)
			q := float64(i) / float64(n)
			rt := dt/q - dt
			print("w ", (1000*uint64(i))/uint64(n), " eta ", int(rt/60), ":", int(rt)%60, "              \r")
		}
	}
	rng, err := mathutil.NewFC32(0, n-1, true)
	if err != nil {
		println(297) //TODO-
		t.Fatal(err)
	}
	println("\nsync")
	f.Accessor().Sync()
	println("synced")
	t0 = time.Now().UnixNano()
	for i := 0; i < n; i++ {
		if _, err := f.Read(h[rng.Next()]); err != nil {
			println(306) //TODO-
			t.Fatal(err)
		}
		if i != 0 && i%perc == 0 {
			dt := float64((time.Now().UnixNano() - t0) / 1e9)
			q := float64(i) / float64(n)
			rt := dt/q - dt
			print("r ", (1000*uint64(i))/uint64(n), " eta ", int(rt/60), ":", int(rt)%60, "                   \r")
		}
	}
	println()
	println(314) //TODO-
	dt = time.Now().UnixNano() - t0
	if c, ok := f.Accessor().(*storage.Cache); ok {
		x, _ := c.Stat()
		t.Logf("Cache rq %10d, load %10d, purge %10d, top %10d, fs %10d", c.Rq, c.Load, c.Purge, c.Top, x.Size())
	}
	println(323) //TODO-
	return
}
开发者ID:nictuku,项目名称:fileutil,代码行数:75,代码来源:dev_test.go


示例14: testBTreePut2

func testBTreePut2(t *testing.T, nf func() btreeStore, grow, n int) (tree btree) {
	if *noGrow {
		grow = 0
	}
	rng, err := mathutil.NewFC32(math.MinInt32, math.MaxInt32, true)
	if err != nil {
		t.Fatal(err)
	}

	a := nf()
	if a == nil {
		t.Fatal(a)
	}

	tree, err = newBTree(a)
	if err != nil {
		t.Fatal(err)
	}

	var k, v [7]byte
	for i := 0; i < n; i++ {
		ik, iv := int64(rng.Next()), int64(rng.Next())
		h2b(k[:], ik)
		h2b(v[:], iv)
		kk := append(make([]byte, grow*i), k[:]...)
		vv := append(make([]byte, grow*i), v[:]...)
		prev, err := tree.put(nil, a, nil, kk, vv, true)
		if err != nil || len(prev) != 0 {
			t.Fatal(i, prev, err)
		}

		var buf []byte
		if buf, err = tree.get(a, nil, nil, kk); err != nil {
			t.Fatal(err)
		}

		if !bytes.Equal(buf, vv) {
			t.Fatalf("\n%s%s%s%s", hex.Dump(kk), hex.Dump(buf), hex.Dump(vv), tree.String(a))
		}
	}

	if err := verifyPageLinks(a, tree, n); err != nil {
		t.Fatalf("%s\n%s\n", err, tree.String(a))
	}

	rng.Seek(0)
	for i := 0; i < n; i++ {
		ik, iv := int64(rng.Next()), int64(rng.Next())
		h2b(k[:], ik)
		h2b(v[:], iv)
		kk := append(make([]byte, grow*i), k[:]...)
		vv := append(make([]byte, grow*i), v[:]...)
		var buf []byte
		buf, err := tree.extract(a, nil, nil, kk)
		if err != nil {
			t.Fatal(i, err)
		}

		if !bytes.Equal(buf, vv) {
			t.Fatalf("\n%s\n%s\n%s\n%s", hex.Dump(kk), hex.Dump(buf), hex.Dump(vv), tree.String(a))
		}

		if err := verifyPageLinks(a, tree, n-i-1); err != nil {
			t.Fatalf("%s\n%s", err, tree.String(a))
		}
	}

	return
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:69,代码来源:btree_test.go


示例15: Snapshot

	// data["animations"] = p.Entity.Component(COMP_Animations).(Animations).Snapshot()

	snapshot, _ := json.Marshal(map[string]interface{}{
		"event": "Update",
		"data":  data,
	})

	s.Send(string(snapshot))
}

func (s *Session) Snapshot() map[string]interface{} {
	return nil
}

func (s *Session) WriteSessionId(w http.ResponseWriter) {
	w.Header().Set("Set-Cookie", "SessionId="+strconv.Itoa(int(s.SessionId))+"; Path=/;")
}

func (s *Session) Refresh() {
	s.Expire = time.Now().Add(time.Duration(option.Int("sessionlife")) * time.Second)
}

func (s *Session) Send(message string) {
	websocket.Message.Send(s.Websocket, message)
}

var Sessions = make(map[uint]*Session)

var sessionIdGen, _ = mathutil.NewFC32(0, 999999, true)
开发者ID:OSPokemon,项目名称:ospokemon,代码行数:29,代码来源:session.go



注:本文中的github.com/cznic/mathutil.NewFC32函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ql.NewRWCtx函数代码示例发布时间:2022-05-23
下一篇:
Golang mathutil.Min函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap