当前位置: 首页>>代码示例>>Golang>>正文


Golang Vector.Copy方法代码示例

本文整理汇总了Golang中container/vector.Vector.Copy方法的典型用法代码示例。如果您正苦于以下问题:Golang Vector.Copy方法的具体用法?Golang Vector.Copy怎么用?Golang Vector.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在container/vector.Vector的用法示例。


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

示例1: Collect

// Match all parsers, collecting their outputs into a vector.
// If one parser fails, the whole thing fails.
// NOTE: Consumes input on failure. Wrap calls in Try(...) to avoid.
func Collect(parsers ...Parser) Parser {
	return func(in Vessel) (Output, bool) {
		p := reflect.NewValue(parsers).(*reflect.SliceValue)

		matches := new(vector.Vector)
		for i := 0; i < p.Len(); i++ {
			parser := p.Elem(i).Interface().(Parser)
			match, ok := parser(in)
			if !ok {
				return nil, false
			}
			matches.Push(match)
		}

		return matches.Copy(), true
	}
}
开发者ID:matthieu,项目名称:go-parse,代码行数:20,代码来源:parsec.go

示例2: main

// A very simple chat server
func main() {
	buffer := new(vector.Vector)
	mutex := new(sync.Mutex)

	// create the socket.io server and mux it to /socket.io/
	config := socketio.DefaultConfig
	config.Origins = []string{"localhost:8080"}
	sio := socketio.NewSocketIO(&config)

	go func() {
		if err := sio.ListenAndServeFlashPolicy(":843"); err != nil {
			log.Println(err)
		}
	}()

	// when a client connects - send it the buffer and broadcasta an announcement
	sio.OnConnect(func(c *socketio.Conn) {
		mutex.Lock()
		c.Send(Buffer{buffer.Copy()})
		mutex.Unlock()
		sio.Broadcast(Announcement{"connected: " + c.String()})
	})

	// when a client disconnects - send an announcement
	sio.OnDisconnect(func(c *socketio.Conn) {
		sio.Broadcast(Announcement{"disconnected: " + c.String()})
	})

	// when a client send a message - broadcast and store it
	sio.OnMessage(func(c *socketio.Conn, msg socketio.Message) {
		payload := Message{[]string{c.String(), msg.Data()}}
		mutex.Lock()
		buffer.Push(payload)
		mutex.Unlock()
		sio.Broadcast(payload)
	})

	log.Println("Server starting. Tune your browser to http://localhost:8080/")

	mux := sio.ServeMux()
	mux.Handle("/", http.FileServer(http.Dir("www/")))

	if err := http.ListenAndServe(":8080", mux); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
开发者ID:WaylandGod,项目名称:go-socket.io,代码行数:47,代码来源:example.go

示例3: Many

// Match a parser 0 or more times.
func Many(match Parser) Parser {
	return func(in Vessel) (Output, bool) {
		matches := new(vector.Vector)
		for {
			out, parsed := match(in)
			if !parsed {
				break
			}

			if out != nil {
				matches.Push(out)
			}
		}

		return matches.Copy(), true
	}
}
开发者ID:matthieu,项目名称:go-parse,代码行数:18,代码来源:parsec.go

示例4: getCVec

// turn string of children id's into a vector
func getCVec(s string) vector.Vector {
	var t string = ""
	v := new(vector.Vector)
	for i := 0; i < len(s); i++ {
		if string(s[i]) != "," {
			t += string(s[i])
		} else {
			if t != "" {
				r, _ := strconv.Atoi(t)
				v.Push(r)
				t = ""
			}
		}
	}
	if t != "" {
		r, _ := strconv.Atoi(t)
		v.Push(r)
	}
	return v.Copy()
}
开发者ID:mcherba,项目名称:dagsched,代码行数:21,代码来源:parser.go

示例5: ParseFile


//.........这里部分代码省略.........
				}
			}
		}
		nTArray.Push(nT)
	}

	// check for correctness
	//for i:=0; i<nCount; i++ {
	//	(nTArray.At(i).(*nodeTemp)).printNT()
	//}

	// vector to be returned, note that child lists are set up
	// in the following for loops (indexed by 'i')
	dagVec := new(vector.Vector)

	// push root
	for i := 0; i < nCount; i++ {
		temp := (nTArray.At(i).(*nodeTemp))
		if temp.ty == "ROOT" {
			n := new(Node)
			n.Id = 0
			n.Ty = "ROOT"
			n.Ex = 0
			n.Lev = -1
			for j := 0; j < (temp.cl).Len(); j++ {
				r := new(Rel)
				r.Id = ((temp.cl).At(j)).(int)
				r.Cc = 0
				(n.Cl).Push(r)
			}
			dagVec.Push(n)
			break
		}
	}

	// push computation nodes
	for i := 0; i < nTArray.Len(); i++ {
		temp := nTArray.At(i).(*nodeTemp)
		if temp.ty == "COMPUTATION" {
			n := new(Node)
			n.Id = temp.id
			n.Ty = temp.ty
			n.Ex = temp.cc
			n.Lev = -1
			for j := 0; j < (temp.cl).Len(); j++ {
				r := new(Rel)
				tId := ((temp.cl).At(j)).(int)
				for k := 0; k < nTArray.Len(); k++ {
					tNo := nTArray.At(k).(*nodeTemp)
					if tNo.id == tId {
						if tNo.ty == "TRANSFER" {
							r.Id = (tNo.cl).At(0).(int)
							r.Cc = tNo.cc
						} else if tNo.ty == "END" {
							r.Id = tNo.id
							r.Cc = 0
						}
						break
					}
				}
				(n.Cl).Push(r)
			}
			dagVec.Push(n)
		}
	}

	// push end node (no child list)
	for i := 0; i < nTArray.Len(); i++ {
		temp := nTArray.At(i).(*nodeTemp)
		if temp.ty == "END" {
			n := new(Node)
			n.Id = temp.id
			n.Ty = temp.ty
			n.Ex = 0
			n.Lev = -1
			dagVec.Push(n)
			break
		}
	}

	// set up parent lists
	for i := 0; i < dagVec.Len(); i++ {
		tId := (dagVec.At(i).(*Node)).Id
		for j := 0; j < dagVec.Len(); j++ {
			temp := dagVec.At(j).(*Node)
			for k := 0; k < (temp.Cl).Len(); k++ {
				relT := (temp.Cl).At(k).(*Rel)
				if relT.Id == tId {
					r := new(Rel)
					r.Id = temp.Id
					r.Cc = relT.Cc
					(dagVec.At(i).(*Node)).Pl.Push(r)
				}
			}
		}
	}

	// return dag vector
	return dagVec.Copy()
}
开发者ID:mcherba,项目名称:dagsched,代码行数:101,代码来源:parser.go

示例6: handlePreUpload

func handlePreUpload(conn http.ResponseWriter, req *http.Request) {
	if !(req.Method == "POST" && req.URL.Path == "/camli/preupload") {
		httputil.BadRequestError(conn, "Inconfigured handler.")
		return
	}

	req.ParseForm()
	camliVersion := req.FormValue("camliversion")
	if camliVersion == "" {
		httputil.BadRequestError(conn, "No camliversion")
		return
	}
	n := 0
	haveVector := new(vector.Vector)

	haveChan := make(chan *map[string]interface{})
	for {
		key := fmt.Sprintf("blob%v", n+1)
		value := req.FormValue(key)
		if value == "" {
			break
		}
		ref := blobref.Parse(value)
		if ref == nil {
			httputil.BadRequestError(conn, "Bogus blobref for key "+key)
			return
		}
		if !ref.IsSupported() {
			httputil.BadRequestError(conn, "Unsupported or bogus blobref "+key)
		}
		n++

		// Parallel stat all the files...
		go func() {
			fi, err := os.Stat(BlobFileName(ref))
			if err == nil && fi.IsRegular() {
				info := make(map[string]interface{})
				info["blobRef"] = ref.String()
				info["size"] = fi.Size
				haveChan <- &info
			} else {
				haveChan <- nil
			}
		}()
	}

	if n > 0 {
		for have := range haveChan {
			if have != nil {
				haveVector.Push(have)
			}
			n--
			if n == 0 {
				break
			}
		}
	}

	ret := commonUploadResponse(req)
	ret["alreadyHave"] = haveVector.Copy()
	httputil.ReturnJson(conn, ret)
}
开发者ID:marsch,项目名称:camlistore,代码行数:62,代码来源:preupload.go

示例7: TopSort

// returns a topologically sorted vector of Node's
func TopSort(dag vec.Vector, s byte) vec.Vector {

	sortDag := new(vec.Vector)
	tempDag := new(vec.Vector)
	destDag := new(vec.Vector)
	setVec := new(vec.Vector)

	for i := 0; i < dag.Len(); i++ {
		tempDag.Push((dag.At(i).(*par.Node)).Copy())
		destDag.Push((dag.At(i).(*par.Node)).Copy())
	}
	// t-level gets regular top sort
	if s == 't' {
		setVec.Push(tempDag.At(0))
		destDag.Delete(0)
		for i := setVec.Len(); i > 0; i = setVec.Len() {
			n := (setVec.Pop().(*par.Node)).Copy()
			sortDag.Push(n)
			for j := 0; j < (n.Cl).Len(); j++ {
				c := ((n.Cl).At(j).(*par.Rel)).Id
				for k := 0; k < destDag.Len(); k++ {
					if (destDag.At(k).(*par.Node)).Id == c {
						for l := 0; l < (destDag.At(k).(*par.Node)).Pl.Len(); l++ {
							if (destDag.At(k).(*par.Node)).Pl.At(l).(*par.Rel).Id == n.Id {
								(destDag.At(k).(*par.Node)).Pl.Delete(l)
								break
							}
						}
					}
				}
			}
			for j := 0; j < destDag.Len(); j++ {
				if (destDag.At(j).(*par.Node)).Pl.Len() == 0 {
					c := (destDag.At(j).(*par.Node)).Id
					for k := 0; k < tempDag.Len(); k++ {
						if (tempDag.At(k).(*par.Node)).Id == c {
							setVec.Push(tempDag.At(k))
							break
						}
					}
					destDag.Delete(j)
					j--
				}
			}
		}
		// b-level gets reverse top sort
	} else if s == 'b' {
		setVec.Push(tempDag.At(tempDag.Len() - 1))
		destDag.Delete(destDag.Len() - 1)
		for i := setVec.Len(); i > 0; i = setVec.Len() {
			n := (setVec.Pop().(*par.Node)).Copy()
			sortDag.Push(n)
			for j := 0; j < (n.Pl).Len(); j++ {
				c := ((n.Pl).At(j).(*par.Rel)).Id
				for k := 0; k < destDag.Len(); k++ {
					if (destDag.At(k).(*par.Node)).Id == c {
						for l := 0; l < (destDag.At(k).(*par.Node)).Cl.Len(); l++ {
							if (destDag.At(k).(*par.Node)).Cl.At(l).(*par.Rel).Id == n.Id {
								(destDag.At(k).(*par.Node)).Cl.Delete(l)
								break
							}
						}
					}
				}
			}
			for j := 0; j < destDag.Len(); j++ {
				if (destDag.At(j).(*par.Node)).Cl.Len() == 0 {
					c := (destDag.At(j).(*par.Node)).Id
					for k := 0; k < tempDag.Len(); k++ {
						if (tempDag.At(k).(*par.Node)).Id == c {
							setVec.Push(tempDag.At(k))
							break
						}
					}
					destDag.Delete(j)
					j--
				}
			}
		}
	} else {
		fmt.Printf("Error")
	}

	return sortDag.Copy()

}
开发者ID:mcherba,项目名称:dagsched,代码行数:87,代码来源:sorter.go


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