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


Golang vector.Vector类代码示例

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


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

示例1: parseCallOrConversion

func (p *parser) parseCallOrConversion(fun ast.Expr) *ast.CallExpr {
	if p.trace {
		defer un(trace(p, "CallOrConversion"))
	}

	lparen := p.expect(token.LPAREN)
	p.exprLev++
	var list vector.Vector
	var ellipsis token.Position
	for p.tok != token.RPAREN && p.tok != token.EOF && !ellipsis.IsValid() {
		list.Push(p.parseExpr())
		if p.tok == token.ELLIPSIS {
			ellipsis = p.pos
			p.next()
		}
		if p.tok != token.COMMA {
			break
		}
		p.next()
	}
	p.exprLev--
	rparen := p.expect(token.RPAREN)

	return &ast.CallExpr{fun, lparen, makeExprList(&list), ellipsis, rparen}
}
开发者ID:droundy,项目名称:go-crazy,代码行数:25,代码来源:parser.go

示例2: findRand

func findRand(t *testing.T, conn *db.Connection, ch chan *vector.Vector) {
	stmt, sErr := conn.Prepare(
		"SELECT * FROM t WHERE i != ? ORDER BY RAND()")
	if sErr != nil {
		error(t, sErr, "Couldn't prepare")
	}

	rs, cErr := conn.Execute(stmt, rand.Int())
	if cErr != nil {
		error(t, cErr, "Couldn't select")
	}

	vout := new(vector.Vector)
	for res := range rs.Iter() {
		if res.Error() != nil {
			error(t, res.Error(), "Couldn't fetch")
		}
		vout.Push(res.Data())
	}

	if vout.Len() != len(tableT) {
		t.Error("Invalid length")
	}

	stmt.Close()
	ch <- vout
}
开发者ID:eden,项目名称:mysqlgo,代码行数:27,代码来源:mysql_test.go

示例3: PutAt

// PutAt will put a give piece at the given position and return removed pieces and the response code.
func (b *Board) PutAt(c cell.Cell, x int, y int, h *history.History) (vector.Vector, PutResponse) {
	if b.At(x, y) != cell.SPACE {
		return nil, OCCUPIED
	}

	b.putAt(c, x, y)
	takenOffs := vector.Vector{}
	rc := c.Reverse()
	if b.shouldTakeOff(x-1, y, rc) {
		b.takeOff(x-1, y, rc, &takenOffs)
	}
	if b.shouldTakeOff(x+1, y, rc) {
		b.takeOff(x+1, y, rc, &takenOffs)
	}
	if b.shouldTakeOff(x, y-1, rc) {
		b.takeOff(x, y-1, rc, &takenOffs)
	}
	if b.shouldTakeOff(x, y+1, rc) {
		b.takeOff(x, y+1, rc, &takenOffs)
	}

	if b.shouldTakeOff(x, y, c) {
		b.TakeAt(x, y)
		return nil, FORBIDDEN
	}

	if len(takenOffs) == 1 && h.IsKo(c, x, y) {
		b.putAt(cell.SPACE, x, y)
		taken := takenOffs.Last().(point.Point)
		b.putAt(c.Reverse(), taken.X(), taken.Y())
		return nil, KO
	}

	return takenOffs, OK
}
开发者ID:Kazuya-Muramatsu,项目名称:Go-Go,代码行数:36,代码来源:board.go

示例4: CreateInitialRoute

// Today this function creates a route in Doozer for the
// RouteService.RouteCreditRequest method - which is CLARITY SPECIFIC
// and adds it too Doozer
func CreateInitialRoute() {

	r := &skylib.Route{}
	r.Name = sName
	r.LastUpdated = time.Seconds()
	r.Revision = 1

	rpcScore := &skylib.RpcCall{Service: "GetUserDataService.GetUserData", Async: false, OkToRetry: false, ErrOnFail: true}

	rl := new(vector.Vector)

	r.RouteList = rl
	rl.Push(rpcScore)

	b, err := json.Marshal(r)
	if err != nil {
		log.Panic(err.String())
	}
	rev, err := skylib.DC.Rev()
	if err != nil {
		log.Panic(err.String())
	}
	_, err = skylib.DC.Set("/routes/RouteService.RouteGetUserDataRequest", rev, b)
	if err != nil {
		log.Panic(err.String())
	}
	return
}
开发者ID:paulbellamy,项目名称:skynet,代码行数:31,代码来源:router.go

示例5: TestGroupBy

func TestGroupBy(t *testing.T) {
	in := IntArray{1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5}
	exp := [][]int{[]int{1}, []int{2, 2}, []int{3, 3, 3}, []int{4, 4, 4, 4}, []int{5, 5, 5, 5, 5}}
	i := 0
	for x := range GroupBy(in, intkey{}).Iter() {
		gr := x.(Group)
		if gr.Key.(int) != i+1 {
			t.Fatal("group key wrong; expected", i+1, "but got", gr.Key.(int))
		}
		vals := Data(gr.Vals)
		assertArraysAreEqual(t, vals, exp[i])
		i++
	}
	if i != 5 {
		t.Fatal("did not return expected number of groups")
	}

	// test 0 length Iterable
	for _ = range GroupBy(IntArray([]int{}), &intkey{}).Iter() {
		t.Fatal("iterator should be empty")
	}

	// test case with only uniques
	var out vector.Vector
	for x := range GroupBy(elevenToTwenty, intkey{}).Iter() {
		out.Push(x.(Group).Key)
	}
	assertArraysAreEqual(t, out.Data(), elevenToTwenty)
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:29,代码来源:iterable_test.go

示例6: codewalkDir

// codewalkDir serves the codewalk directory listing.
// It scans the directory for subdirectories or files named *.xml
// and prepares a table.
func codewalkDir(w http.ResponseWriter, r *http.Request, relpath, abspath string) {
	type elem struct {
		Name  string
		Title string
	}

	dir, err := ioutil.ReadDir(abspath)
	if err != nil {
		log.Print(err)
		serveError(w, r, relpath, err)
		return
	}
	var v vector.Vector
	for _, fi := range dir {
		if fi.IsDirectory() {
			v.Push(&elem{fi.Name + "/", ""})
		} else if strings.HasSuffix(fi.Name, ".xml") {
			cw, err := loadCodewalk(abspath + "/" + fi.Name)
			if err != nil {
				continue
			}
			v.Push(&elem{fi.Name[0 : len(fi.Name)-len(".xml")], cw.Title})
		}
	}

	b := applyTemplate(codewalkdirHTML, "codewalkdir", v)
	servePage(w, "Codewalks", "", "", b)
}
开发者ID:go-nosql,项目名称:golang,代码行数:31,代码来源:codewalk.go

示例7: shorten

func (self Transformer) shorten(arr vec.Vector, index, inside, count int) (rindex int, rinside int) {
	mut := arr[index]
	if IsDeleteMutation(mut) {
		del := toDeleteMutation(mut)
		del.SetCount(del.Count() - count)
		if inside == del.Count() {
			inside = 0
			if del.Count() == 0 {
				arr.Delete(index)
			} else {
				index++
			}
		}
	} else if IsSkipMutation(mut) {
		skip := toSkipMutation(mut)
		skip.SetCount(skip.Count() - 1)
		if inside == skip.Count() {
			inside = 0
			if skip.Count() == 0 {
				arr.Delete(index)
			} else {
				index++
			}
		}
	} else {
		panic("Unsupported mutation for shorten()")
	}

	return index, inside
}
开发者ID:AaronO,项目名称:lightwave,代码行数:30,代码来源:ot.go

示例8: Data

// Data returns a slice containing the elements of iter.
func Data(iter Iterable) []interface{} {
	vec := new(vector.Vector)
	for e := range iter.Iter() {
		vec.Push(e)
	}
	return vec.Data()
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:8,代码来源:iterable.go

示例9: arrayInterface

// arrayInterface is like array but returns []interface{}.
func (d *decodeState) arrayInterface() []interface{} {
	var v vector.Vector
	for {
		// Look ahead for ] - can only happen on first iteration.
		op := d.scanWhile(scanSkipSpace)
		if op == scanEndArray {
			break
		}

		// Back up so d.value can have the byte we just read.
		d.off--
		d.scan.undo(op)

		v.Push(d.valueInterface())

		// Next token must be , or ].
		op = d.scanWhile(scanSkipSpace)
		if op == scanEndArray {
			break
		}
		if op != scanArrayValue {
			d.error(errPhase)
		}
	}
	return v
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:27,代码来源:decode.go

示例10: chooseNextEdgeByGeneration

func chooseNextEdgeByGeneration(T *quadratic.Map) *quadratic.Edge {
	ActiveFaces := new(vector.Vector)
	onGeneration := -1
	T.Faces.Do(func(F interface{}) {
		Fac := F.(*quadratic.Face)
		if Fac.Value.(string) != "active" {
			return
		}
		ActiveFaces.Push(Fac)
		Fac.DoEdges(func(e *quadratic.Edge) {
			//fmt.Fprintf(os.Stderr,"edge generation: %v onGen: %v\n",e.Generation,onGeneration)
			if onGeneration < 0 || e.Generation < onGeneration {
				onGeneration = e.Generation
			}
		})
	})
	activeEdges := new(generationOrderedEdges)

	ActiveFaces.Do(func(F interface{}) {
		Fac := F.(*quadratic.Face)
		Fac.DoEdges(func(e *quadratic.Edge) {
			if e.Generation != onGeneration {
				return
			}
			activeEdges.Push(e)
		})
	})
	//fmt.Fprintf(os.Stderr,"onGen: %v have %v active edges\n",onGeneration,activeEdges.Len())
	sort.Sort(activeEdges)
	return activeEdges.At(0).(*quadratic.Edge)
}
开发者ID:ebering,项目名称:zellij,代码行数:31,代码来源:edges.go

示例11: makeVector

func makeVector(n int) *vector.Vector {
	v := new(vector.Vector)
	for i := 0; i < n; i++ {
		v.Push(&User{"Mike", 1})
	}
	return v
}
开发者ID:kpumuk,项目名称:mustache.go,代码行数:7,代码来源:mustache_test.go

示例12: TestDecodeFlushElem

func TestDecodeFlushElem(t *testing.T) {
	testVec := new(vector.Vector).Resize(2, 2)
	nb := newDecoder(testVec, 1)
	nb.Float64(3.14159)
	nb.Flush()
	assertResult(t, testVec.Data(), []interface{}{nil, float64(3.14159)})
}
开发者ID:lougxing,项目名称:golang-china,代码行数:7,代码来源:decode_test.go

示例13: parseGenDecl

func (p *parser) parseGenDecl(keyword token.Token, f parseSpecFunction) *ast.GenDecl {
	if p.trace {
		defer un(trace(p, keyword.String()+"Decl"))
	}

	doc := p.leadComment
	pos := p.expect(keyword)
	var lparen, rparen token.Position
	var list vector.Vector
	if p.tok == token.LPAREN {
		lparen = p.pos
		p.next()
		for p.tok != token.RPAREN && p.tok != token.EOF {
			list.Push(f(p, p.leadComment))
		}
		rparen = p.expect(token.RPAREN)
		p.expectSemi()
	} else {
		list.Push(f(p, nil))
	}

	// convert vector
	specs := make([]ast.Spec, len(list))
	for i, x := range list {
		specs[i] = x.(ast.Spec)
	}

	return &ast.GenDecl{doc, pos, keyword, lparen, specs, rparen}
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:29,代码来源:parser.go

示例14: TestRecvInvalidPacket

func TestRecvInvalidPacket(t *testing.T) {
	q := new(vector.Vector)
	x := &net.UDPAddr{net.IP{1, 2, 3, 4}, 5}
	p := recvPacket(q, Packet{x, invalidProtobuf})
	assert.Equal(t, (*packet)(nil), p)
	assert.Equal(t, 0, q.Len())
}
开发者ID:piston,项目名称:doozerd,代码行数:7,代码来源:manager_test.go

示例15: consumeCommentGroup

// Consume a group of adjacent comments, add it to the parser's
// comments list, and return the line of which the last comment
// in the group ends. An empty line or non-comment token terminates
// a comment group.
//
func (p *parser) consumeCommentGroup() int {
	var list vector.Vector
	endline := p.pos.Line
	for p.tok == token.COMMENT && endline+1 >= p.pos.Line {
		var comment *ast.Comment
		comment, endline = p.consumeComment()
		list.Push(comment)
	}

	// convert list
	group := make([]*ast.Comment, len(list))
	for i, x := range list {
		group[i] = x.(*ast.Comment)
	}

	// add comment group to the comments list
	g := &ast.CommentGroup{group, nil}
	if p.lastComment != nil {
		p.lastComment.Next = g
	} else {
		p.comments = g
	}
	p.lastComment = g

	return endline
}
开发者ID:lougxing,项目名称:golang-china,代码行数:31,代码来源:parser.go


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