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

Golang ring.New函数代码示例

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

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



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

示例1: addToKillRing

// addToKillRing adds some text to the kill ring. If mode is 0 it adds it to a
// new node in the end of the kill ring, and move the current pointer to the new
// node. If mode is 1 or 2 it appends or prepends the text to the current entry
// of the killRing.
func (s *State) addToKillRing(text []rune, mode int) {
	// Don't use the same underlying array as text
	killLine := make([]rune, len(text))
	copy(killLine, text)

	// Point killRing to a newNode, procedure depends on the killring state and
	// append mode.
	if mode == 0 { // Add new node to killRing
		if s.killRing == nil { // if killring is empty, create a new one
			s.killRing = ring.New(1)
		} else if s.killRing.Len() >= KillRingMax { // if killring is "full"
			s.killRing = s.killRing.Next()
		} else { // Normal case
			s.killRing.Link(ring.New(1))
			s.killRing = s.killRing.Next()
		}
	} else {
		if s.killRing == nil { // if killring is empty, create a new one
			s.killRing = ring.New(1)
			s.killRing.Value = []rune{}
		}
		if mode == 1 { // Append to last entry
			killLine = append(s.killRing.Value.([]rune), killLine...)
		} else if mode == 2 { // Prepend to last entry
			killLine = append(killLine, s.killRing.Value.([]rune)...)
		}
	}

	// Save text in the current killring node
	s.killRing.Value = killLine
}
开发者ID:onlyafly,项目名称:galapagos,代码行数:35,代码来源:line.go


示例2: ThreeDRotate

func ThreeDRotate(op ThreeDOperation) error {
	newFaceRing := ring.New(8)
	newEdgeRing := ring.New(12)
	trx := ThreeDTransformer{
		newFaceRing, newEdgeRing}
	for _, faceColor := range op.ent[op.cubeId].faceMap[op.face] {
		trx.faceRing.Value = faceColor
		trx.faceRing = trx.faceRing.Next()
	}
	for _, edgeColorPtr := range op.ent[op.cubeId].edgeMap[op.face] {
		trx.edgeRing.Value = *edgeColorPtr
		trx.edgeRing = trx.edgeRing.Next()
	}

	trx.faceRing = trx.faceRing.Move(2 * op.direction)
	trx.edgeRing = trx.edgeRing.Move(3 * op.direction)

	for i, _ := range op.ent[op.cubeId].faceMap[op.face] {
		if v, ok := trx.faceRing.Value.(Color); ok {
			op.ent[op.cubeId].faceMap[op.face][i] = v
		}
		trx.faceRing = trx.faceRing.Next()
	}
	for i, _ := range op.ent[op.cubeId].edgeMap[op.face] {
		if v, ok := trx.edgeRing.Value.(Color); ok {
			*op.ent[op.cubeId].edgeMap[op.face][i] = v
		}
		trx.edgeRing = trx.edgeRing.Next()
	}

	return nil
}
开发者ID:rwbogy,项目名称:innercube,代码行数:32,代码来源:transformations.go


示例3: valueBuffer

// Process values coming from ADC
func valueBuffer(d *EKReceiver) {
	last_sample := make([]time.Time, 31)

	for i := 0; i < 31; i++ {
		d.ValueBufferRaw[i] = ring.New(RAW_BUFFER_SIZE)
		d.ValueBuffer[i] = ring.New(BUFFER_SIZE)
	}
	for {
		v := <-d.buffer_chan

		//Move head forwards
		d.ValueBufferRaw[v.Channel] = d.ValueBufferRaw[v.Channel].Next()
		d.ValueBufferRaw[v.Channel].Value = ChannelData{v.Abstimestamp, v.Value} //Set value

		// FIR Calculation
		p0 := d.ValueBufferRaw[v.Channel]
		i := 0
		out := float64(0)
		for ; i < d.FIRTaps && p0.Value != nil; i++ {
			out += p0.Value.(ChannelData).Value
			p0 = p0.Prev()
		}
		out = out / float64(i)
		if v.Abstimestamp.Sub(last_sample[v.Channel]) >= d.SampleTime {
			d.ValueBuffer[v.Channel] = d.ValueBuffer[v.Channel].Next()
			d.ValueBuffer[v.Channel].Value = ChannelData{v.Abstimestamp, out}
			last_sample[v.Channel] = v.Abstimestamp
		}
	}
}
开发者ID:thoj,项目名称:Delphin-EK200C,代码行数:31,代码来源:expertkey.go


示例4: sendproxy

// Return a channel which serves as a sending proxy to `out`.
// Use a goroutine to receive values from `out` and store them
// in an expanding buffer, so that sending to `out` never blocks.
// See this discussion:
// <http://rogpeppe.wordpress.com/2010/02/10/unlimited-buffering-with-low-overhead>
func sendproxy(out chan<- uint64) chan<- uint64 {
	proxy := make(chan uint64, 1024)
	go func() {
		n := 1024 // the allocated size of the circular queue
		first := ring.New(n)
		last := first
		var c chan<- uint64
		var e uint64
		for {
			c = out
			if first == last {
				// buffer empty: disable output
				c = nil
			} else {
				e = first.Value.(uint64)
			}
			select {
			case e = <-proxy:
				last.Value = e
				if last.Next() == first {
					// buffer full: expand it
					last.Link(ring.New(n))
					n *= 2
				}
				last = last.Next()
			case c <- e:
				first = first.Next()
			}
		}
	}()
	return proxy
}
开发者ID:attilaolah,项目名称:prcert,代码行数:37,代码来源:sieve.go


示例5: main

func main() {
	r := ring.New(5)
	r.Value = 1
	r.Next().Value = 2
	r.Prev().Value = 5

	plus := ring.New(1)
	plus.Value = 10
	r.Link(plus)
	fmt.Println("len: ", r.Len())
	r.Do(printe)
}
开发者ID:hyndio,项目名称:hyd.me,代码行数:12,代码来源:ring.go


示例6: init

func init() {

	testBackend.groups["alt.test"] = &groupStorage{
		group: &nntp.Group{"alt.test", "A test.",
			0, 0, 0, nntp.PostingNotPermitted},
		articles: ring.New(maxArticles),
	}

	testBackend.groups["misc.test"] = &groupStorage{
		group: &nntp.Group{"misc.test", "More testing.",
			0, 0, 0, nntp.PostingPermitted},
		articles: ring.New(maxArticles),
	}

}
开发者ID:welterde,项目名称:go-nntp,代码行数:15,代码来源:exampleserver.go


示例7: NewSimpleMovingPercentile

// Create a new simple moving percentile expvar.Var. It will be
// published under `name` and maintain `size` values for
// calculating the percentile.
//
// percentile must be between 0 and 1
//
// An empty name will cause it to not be published
func NewSimpleMovingPercentile(name string, percentile float64, size int) *SimpleMovingStat {
	sm := new(SimpleMovingStat)
	sm.size = size
	sm.mutex = new(sync.Mutex)
	sm.values = ring.New(size)

	sm.calculate = func(s *SimpleMovingStat) float64 {
		ary := make([]float64, 0)
		s.values.Do(func(val interface{}) {
			if val != nil {
				ary = append(ary, val.(float64))
			}
		})
		length := len(ary)
		if length == 0 {
			return 0.0
		}
		sort.Float64s(ary)
		mid := int(float64(len(ary)) * percentile)
		return ary[mid]
	}

	if name != "" {
		expvar.Publish(name, sm)
	}
	return sm

}
开发者ID:brianm,项目名称:variant,代码行数:35,代码来源:smav.go


示例8: main

func main() {
	sourceAddress := ":3000"

	ports := []string{
		":3333",
		":3334",
	}
	hostRing := ring.New(len(ports))
	for _, port := range ports {
		url, _ := url.Parse("http://127.0.0.1" + port)
		hostRing.Value = url
		hostRing = hostRing.Next()
	}

	mutex := sync.Mutex{}
	director := func(request *http.Request) {
		mutex.Lock()
		defer mutex.Unlock()
		request.URL.Scheme = "http"
		request.URL.Host = hostRing.Value.(*url.URL).Host
		hostRing = hostRing.Next()
		fmt.Println(hostRing)
	}
	proxy := &httputil.ReverseProxy{Director: director}
	server := http.Server{
		Addr:    sourceAddress,
		Handler: proxy,
	}
	server.ListenAndServe()
}
开发者ID:yanjinzh6,项目名称:reverse-proxy,代码行数:30,代码来源:main.go


示例9: testRing

func testRing() {
	fmt.Println("testRing -----------------------------------------------------")
	// 循环列表
	size := 10
	// 声明和初始化
	r := ring.New(size)

	fmt.Println("len=", r.Len(), ",r=", r, ",r.Prev()=", r.Prev())

	for num, e := 0, r.Prev(); e != nil; e = e.Next() {
		e.Value = num
		num++
		if num >= size {
			break
		}
	}
	for num, e := 0, r.Prev(); e != nil; e = e.Next() {
		fmt.Println("num =", num, ",e.value=", e.Value)
		num++
		if num >= size+1 {
			break
		}
	}

}
开发者ID:shawnpan,项目名称:learnGo,代码行数:25,代码来源:testContainer.go


示例10: NewLoadBalancer

//NewLoadBalancer creates a new instance of a Round Robin load balancer
func (rrf *RoundRobinLoadBalancerFactory) NewLoadBalancer(backendName, caCertPath string, servers []config.ServerConfig) (LoadBalancer, error) {
	var rrlb RoundRobinLoadBalancer

	if backendName == "" {
		return nil, fmt.Errorf("Expected non-empty backend name")
	}

	if len(servers) == 0 {
		return nil, fmt.Errorf("Expected at least one server in servers argument")
	}

	rrlb.backend = backendName
	rrlb.servers = ring.New(len(servers))

	for _, s := range servers {

		lbEndpoint := new(LoadBalancerEndpoint)
		lbEndpoint.Address = fmt.Sprintf("%s:%d", s.Address, s.Port)
		metrics.SetGauge([]string{"endpoint", lbEndpoint.Address}, 1.0)
		lbEndpoint.PingURI = s.PingURI
		lbEndpoint.Up = true
		lbEndpoint.CACertPath = caCertPath

		log.Info("Spawing health check for address ", lbEndpoint.Address)
		healthCheckFunction := MakeHealthCheck(lbEndpoint, s, true)
		go healthCheckFunction()

		log.Info("Adding server with address ", lbEndpoint.Address)
		rrlb.servers.Value = lbEndpoint
		rrlb.servers = rrlb.servers.Next()
	}

	return &rrlb, nil
}
开发者ID:xtracdev,项目名称:xavi,代码行数:35,代码来源:roundrobin.go


示例11: initRedis

//初始化redis连接池
func initRedis(confs []*config.Redis) {
	ids = ring.New(len(confs))
	for _, conf := range confs {
		if !conf.Enable {
			continue
		}
		id := &IdAvailable{Id: conf.Id}
		ids.Value = id
		spec := redis.DefaultSpec().Db(conf.DB).Password(conf.Password).Host(conf.Host).Port(conf.Port)
		//log.Info("redis init at ", spec)
		c := make(chan *RedisClient, PoolSize)
		for j := 0; j < PoolSize; j++ {
			if client, err := redis.NewSynchClientWithSpec(spec); err != nil {
				goto err
			} else {
				c <- &RedisClient{Id: conf.Id, Redis: client}
			}
		}
		pool[conf.Id] = c
		id.IsAvailable = true
		ids = ids.Next()
	err: //如果创建CLIENT时出错,就抛弃这个台机器
		errRedis[conf.Id] = conf
		ids = ids.Next()
	}
}
开发者ID:sdgdsffdsfff,项目名称:monitor-1,代码行数:27,代码来源:redis.go


示例12: main

func main() {
	// Creates a circular list for round-robin HTTP roundtrip.
	hosts := []string{
		":4000",
		":5000",
		":6000",
	}
	hostRing := ring.New(len(hosts))
	for _, host := range hosts {
		hostRing.Value = host
		hostRing = hostRing.Next()
	}

	// Locks by mutex because hostConverter will be executed in parallel.
	mutex := sync.Mutex{}
	hostConverter := func(originalHost string) string {
		mutex.Lock()
		defer mutex.Unlock()
		host := hostRing.Value.(string)
		hostRing = hostRing.Next()
		return host
	}

	// Runs a reverse-proxy server on http://localhost:3000/
	proxy := entoverse.NewProxyWithHostConverter(hostConverter)
	http.ListenAndServe(":3000", proxy)
}
开发者ID:leobcn,项目名称:entoverse,代码行数:27,代码来源:roundrobin.go


示例13: TestDo

func TestDo(t *testing.T) {
	r := ring.New(5) // 5個の要素

	if r.Len() != 5 {
		t.Errorf("length = %d", r.Len())
	}

	i := 0
	for initialValue := r.Next(); initialValue != r; initialValue = initialValue.Next() {
		value := HogeValue(i)
		initialValue.Value = &value
		i++
	}

	for p := r.Next(); p != r; p = p.Next() {
		t.Logf("value = %d", *p.Value.(*HogeValue))
	}

	r.Do(func(v interface{}) {
		hoge, ok := v.(*HogeValue)
		if ok {
			hoge.Add(1)
		}
	})

	i = 1
	for p := r.Next(); p != r; p = p.Next() {
		check := p.Value.(*HogeValue)
		if int(*check) != i {
			t.Errorf("check = %d, i = %d", *check, i)
		}
		i++
	}
}
开发者ID:qt-luigi,项目名称:golangcafe,代码行数:34,代码来源:ringsample_test.go


示例14: main

func main() {
	myArr := string([]rune{
		0x49, 0x53, 0x54, 0x53, 0x2d, 0x59, 0x41, 0x52,
		0x41, 0x2d, 0x45, 0x4e, 0x55, 0x52, 0x0a,
	})
	myStr := "Haha!!!!  Strings won't find this flag. You need to use something else!!"
	promiseRing := ring.New(15)

	result := make([]byte, len(myStr))
	restore := result

	fmt.Println(myStr)

	for i := 0; i < promiseRing.Len(); i++ {
		result = restore
		for j := 0; j < len(myStr); j++ {
			result[j] = myStr[j] ^ myArr[i]
		}
		promiseRing.Value = b64.StdEncoding.EncodeToString(result)
		promiseRing = promiseRing.Next()
	}

	fmt.Println("============")
	promiseRing.Do(func(x interface{}) {
		fmt.Print(x, "\n============\n")
	})

}
开发者ID:RITSPARSA,项目名称:ISTS14_CTF,代码行数:28,代码来源:GoReversin.go


示例15: main

func main() {
	//创建10个元素的闭环
	r := ring.New(10)

	//给闭环中的元素赋值
	for i := 1; i <= r.Len(); i++ {
		r.Value = i
		r = r.Next()
	}

	//循环打印闭环中的元素值
	r.Do(
		func(p interface{}) {
			println(p.(int))
		})

	//获得当前元素之后的第5个元素
	r5 := r.Move(5)
	fmt.Println(r5.Value)
	fmt.Println(r.Value)

	//链接当前元素r与r5,相当于删除了r与r5之间的元素
	r1 := r.Link(r5)
	fmt.Println(r1.Value)
	fmt.Println(r.Value)
}
开发者ID:quchunguang,项目名称:test,代码行数:26,代码来源:test_ring.go


示例16: NewInMemoryRegistry

func NewInMemoryRegistry() Registry {
	return &inMemoryRegistry{
		taskRegistry:  make(map[string]*T),
		tasksFinished: ring.New(defaultFinishedTasksSize),
		podToTask:     make(map[string]string),
	}
}
开发者ID:40a,项目名称:bootkube,代码行数:7,代码来源:registry.go


示例17: Test_Ring

//ring实现了环形链表的操作。
func Test_Ring() {
	r := ring.New(10)
	for i := 1; i <= r.Len(); i++ {
		r.Value = i
		r = r.Next()
	}

	for i := 1; i <= r.Len(); i++ {
		fmt.Println(r.Value)
		r = r.Next()
	}

	r = r.Move(6)                      //移动到6
	fmt.Println("move to 6:", r.Value) //6
	deletedLink := r.Unlink(19)        //移除19%10=9个元素,返回删除以后的数据

	fmt.Println("======delete======")
	for i := 0; i < deletedLink.Len(); i++ {
		fmt.Println(deletedLink.Value)
		deletedLink = deletedLink.Next()
	}

	fmt.Println("=====last======")
	fmt.Println(r.Len())           //10-9=1
	fmt.Println(deletedLink.Len()) //9
	fmt.Println(r)
}
开发者ID:yunkaiyueming,项目名称:go_code,代码行数:28,代码来源:ring.go


示例18: load

// load reloads the proxy config from etcd
func (p *PruxyEtcd) load() error {
	response, err := p.client.Get(p.watchPrefix, false, true)
	if err != nil {
		log.Println("err:", err)
		return err
	}

	p.mu.Lock()
	defer p.mu.Unlock()

	// reinit host configs
	p.Hosts = map[string]*ring.Ring{}
	for _, hostNode := range response.Node.Nodes {
		host := strings.Split(hostNode.Key, "/")[2]
		p.Hosts[host] = ring.New(len(hostNode.Nodes))
		for _, upstreamNode := range hostNode.Nodes {
			upstream := strings.Split(upstreamNode.Key, "/")[3]
			if upstream != "" {
				p.Hosts[host].Value = upstream
				p.Hosts[host] = p.Hosts[host].Next()
				log.Printf("added upstream %s -> %s", host, upstream)
			}
		}
	}
	return nil
}
开发者ID:noonat,项目名称:pruxy,代码行数:27,代码来源:etcd.go


示例19: NewMainMenu

func NewMainMenu(mapDir string, w, h int) (m *MainMenu) {
	file, err := os.Open(mapDir)
	defer file.Close()
	if err != nil {
		panic(err)
	}

	fis, err := file.Readdir(0)
	if err != nil {
		panic(err)
	}

	var maps *ring.Ring
	for _, fi := range fis {
		if strings.HasSuffix(fi.Name(), ".txt") {
			name := fi.Name()
			mapName := name[:len(name)-4]
			r := ring.New(1)
			r.Value = mapName
			if maps != nil {
				maps.Link(r)
			} else {
				maps = r
			}
		}
	}
	return &MainMenu{maps, time.Now(), w, h}
}
开发者ID:acieroid,项目名称:nov13,代码行数:28,代码来源:mainmenu.go


示例20: Post

func Post(w rest.ResponseWriter, r *rest.Request) {
	host := Host{}
	err := r.DecodeJsonPayload(&host)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if host.Id == "" {
		rest.Error(w, "id required", 400)
		return
	}
	if host.Address == "" {
		rest.Error(w, "address required", 400)
		return
	}
	ra, err := net.ResolveIPAddr("ip4:icmp", host.Address)
	if err != nil {
		rest.Error(w, err.Error(), 400)
		return
	}
	lock.Lock()
	q := make(chan bool, 1) // chan for stop ping
	store[host.Id] = &HostStore{
		host,
		time.Now(),
		0.0, 0.0, 0.0, 0.0,
		0,
		ring.New(DefCircleLen),
		q}
	go ping(host.Id, ra, time.Second*DefRTT, q, &lock, store)
	lock.Unlock()
	w.WriteJson(&host)
}
开发者ID:hizel,项目名称:pingd,代码行数:33,代码来源:pingd.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang ring.Ring类代码示例发布时间:2022-05-24
下一篇:
Golang list.List类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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