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


Golang Vector.Len方法代码示例

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


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

示例1: parseGroups

// parseGroups is used to parse a list of group states.
func parseGroups(lines []string) ([]Group, os.Error) {
	var res vector.Vector
	for _, line := range lines {
		ss := strings.Split(strings.TrimSpace(line), " ", 4)
		if len(ss) < 4 {
			return nil, ProtocolError("short group info line: " + line)
		}
		high, err := strconv.Atoi(ss[1])
		if err != nil {
			return nil, ProtocolError("bad number in line: " + line)
		}
		low, err := strconv.Atoi(ss[2])
		if err != nil {
			return nil, ProtocolError("bad number in line: " + line)
		}
		res.Push(&Group{ss[0], high, low, ss[3]})
	}
	realres := make([]Group, res.Len())
	i := 0
	for v := range res.Iter() {
		realres[i] = *v.(*Group)
		i++
	}
	return realres, nil
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:26,代码来源:nntp.go

示例2: CountColor

func CountColor(pngR io.Reader) int {
	/* modify here */
	// uniq := new (vector.Vector[uint32])
	var colorVector vector.Vector
	var rVector vector.IntVector
	var gVector vector.IntVector
	var bVector vector.IntVector
	im, _ := png.Decode(pngR)
	for y := 0; y < im.Bounds().Dy(); y++ {
		for x := 0; x < im.Bounds().Dx(); x++ {
			color := im.At(x, y)
			unique := true
			r, g, b, _ := color.RGBA()
			for i := 0; i < colorVector.Len(); i++ {
				if r == uint32(rVector.At(i)) &&
					g == uint32(gVector.At(i)) &&
					b == uint32(bVector.At(i)) {
					unique = false
				}
			}
			if unique == true {
				colorVector.Push(color)
				rVector.Push(int(r))
				gVector.Push(int(g))
				bVector.Push(int(b))
			}
		}
	}
	return colorVector.Len()
}
开发者ID:takano32,项目名称:gdd11jp-CountColor,代码行数:30,代码来源:cc.go

示例3: populateServer

func populateServer(serv *server) []sfs.ReplicateChunkArgs {
	str := fmt.Sprintf("%s:%d", serv.addr.IP.String(), serv.addr.Port)
	log.Printf("master: PopulateServer: populating %s\n", str)
	log.Printf("master: PopulateServer: server heap state:\n%s\n", sHeap.printPresent())

	if len(chunks) == 0 {
		return nil
	}

	thisVec := new(vector.Vector)
	for _, chunk := range chunks {
		//log.Printf("master: PopulateServer: examining chunk %+v, nservers %d\n", *chunk, chunk.servers.Len())
		if chunk.servers.Len() < sfs.NREPLICAS {

			//populate chunk location list
			chunklist := make([]net.TCPAddr, chunk.servers.Len())
			for cnt1 := 0; cnt1 < chunk.servers.Len(); cnt1++ {
				chunklist[cnt1] = chunk.servers.At(cnt1).(*server).addr
			}

			//send rpc call off
			thisVec.Push(sfs.ReplicateChunkArgs{chunk.chunkID, chunklist})
		}
	}

	cnt := thisVec.Len()

	thisSlice := make([]sfs.ReplicateChunkArgs, cnt)
	for i := 0; i < cnt; i++ {
		thisSlice[i] = thisVec.Pop().(sfs.ReplicateChunkArgs) //horribly inefficient but what can you do...
	}

	return thisSlice
}
开发者ID:alangenfeld,项目名称:cs639,代码行数:34,代码来源:master.go

示例4: 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

示例5: test1

func test1() {
	var a [1000]*S
	for i := 0; i < len(a); i++ {
		a[i] = new(S).Init(i)
	}

	v := new(vector.Vector)
	for i := 0; i < len(a); i++ {
		v.Insert(0, a[i])
		if v.Len() != i+1 {
			panic("len = ", v.Len(), "\n")
		}
	}

	for i := 0; i < v.Len(); i++ {
		x := v.At(i).(*S)
		if x.val != v.Len()-i-1 {
			panic("expected ", i, ", found ", x.val, "\n")
		}
	}

	for v.Len() > 10 {
		v.Delete(10)
	}
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:25,代码来源:vectors.go

示例6: makeStmtList

func makeStmtList(list *vector.Vector) []ast.Stmt {
	stats := make([]ast.Stmt, list.Len())
	for i := 0; i < list.Len(); i++ {
		stats[i] = list.At(i).(ast.Stmt)
	}
	return stats
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:7,代码来源:parser.go

示例7: ClassicFetchAll

// Fetch all remaining results. If we get no results at
// all, an error will be returned; otherwise it probably
// still occurred but will be hidden.
func ClassicFetchAll(rs ClassicResultSet) (data [][]interface{}, error os.Error) {
	var v vector.Vector
	var d interface{}
	var e os.Error

	for rs.More() {
		r := rs.Fetch()
		d = r.Data()
		if d != nil {
			v.Push(d)
		}
		e = r.Error()
		if e != nil {
			break
		}
	}

	l := v.Len()

	if l > 0 {
		// TODO: how can this be done better?
		data = make([][]interface{}, l)
		for i := 0; i < l; i++ {
			data[i] = v.At(i).([]interface{})
		}
	} else {
		// no results at all, return the error
		error = e
	}

	return
}
开发者ID:lye,项目名称:go-db,代码行数:35,代码来源:classic.go

示例8: Next

// Next will chose a random point to put a piece.
func (ap *RandomPlayer) Next(m *match.Match) *match.Response {
	color := ap.teban.Color()
	candidates := new(vector.Vector)
	size := m.Board.Size()
	for y := 1; y <= size; y++ {
		for x := 1; x <= size; x++ {
			if m.Board.CanPutAt(color, x, y, m.History) {
				if !m.Board.IsEye(color, x, y) {
					candidates.Push(&point.Point{x, y})
				}
			}
		}
	}

	if candidates.Len() != 0 {
		bs := make([]byte, 1)
		_, err := rand.Read(bs)
		if err == nil {
			p := candidates.At(int(bs[0]) % candidates.Len()).(*point.Point)
			ts, resp := m.Board.PutAt(color, p.X(), p.Y(), m.History)
			if resp == board.OK {
				fmt.Printf("[random] put %d,%d\n", p.X(), p.Y())
				return match.NewPutResponse(p.X(), p.Y(), ts)
			}
		}
	}
	return match.NewPassResponse()
}
开发者ID:Kazuya-Muramatsu,项目名称:Go-Go,代码行数:29,代码来源:random_player.go

示例9: seed

// use win-rate distribution of node to play a legal move in tracker
func (node *Node) seed(t Tracker, path []int) bool {
	if node.parent == nil {
		return false
	}
	dist := new(vector.Vector)
	sum := 0.0
	for sibling := node.parent.Child; sibling != nil; sibling = sibling.Sibling {
		for i := 0; i < len(path); i++ {
			if sibling.Vertex == path[i] {
				continue
			}
		}
		dist.Push(sibling.blendedMean)
		sum += sibling.blendedMean
	}
	node.totalseeds++
	r := rand.Float64() * sum
	for i := 0; i < dist.Len(); i++ {
		r -= dist.At(i).(float64)
		if r <= 0 {
			if t.Legal(node.Color, i) {
				t.Play(node.Color, i)
				node.seeds++
				return true
			}
			return false
		}
	}
	return false
}
开发者ID:etherealmachine,项目名称:hivemind,代码行数:31,代码来源:search.go

示例10: makeBugDocs

func makeBugDocs(v *vector.Vector) []string {
	d := make([]string, v.Len())
	for i := 0; i < v.Len(); i++ {
		d[i] = CommentText(v.At(i).(*ast.CommentGroup))
	}
	return d
}
开发者ID:lougxing,项目名称:golang-china,代码行数:7,代码来源:doc.go

示例11: ContainsExactly

// The actual collection must contain all expected elements and nothing else.
// The order of elements is not significant.
func ContainsExactly(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error) {
	actual, err := toArray(actual_)
	if err != nil {
		return
	}
	expected, err := toArray(expected_)
	if err != nil {
		return
	}

	containsAll := true
	remaining := new(vector.Vector)
	remaining.AppendVector((*vector.Vector)(&actual))
	for i := 0; i < len(expected); i++ {
		if idx, found := findIndex(*remaining, expected[i]); found {
			remaining.Delete(idx)
		} else {
			containsAll = false
			break
		}
	}

	match = containsAll && remaining.Len() == 0
	pos = Messagef(actual, "contains exactly “%v”", expected)
	neg = Messagef(actual, "does NOT contain exactly “%v”", expected)
	return
}
开发者ID:boggle,项目名称:gospec,代码行数:29,代码来源:matchers.go

示例12: test0

func test0() {
	v := new(vector.Vector)
	if v.Len() != 0 {
		print("len = ", v.Len(), "\n")
		panic("fail")
	}
}
开发者ID:go-nosql,项目名称:golang,代码行数:7,代码来源:vectors.go

示例13: parseInterfaceType

func (p *parser) parseInterfaceType() *ast.InterfaceType {
	if p.trace {
		defer un(trace(p, "InterfaceType"))
	}

	pos := p.expect(token.INTERFACE)
	lbrace := p.expect(token.LBRACE)
	list := new(vector.Vector)
	for p.tok == token.IDENT {
		m := p.parseMethodSpec()
		if p.tok != token.RBRACE {
			p.expect(token.SEMICOLON)
		}
		m.Comment = p.lineComment
		list.Push(m)
	}
	rbrace := p.expect(token.RBRACE)
	p.optSemi = true

	// convert vector
	methods := make([]*ast.Field, list.Len())
	for i := list.Len() - 1; i >= 0; i-- {
		methods[i] = list.At(i).(*ast.Field)
	}

	return &ast.InterfaceType{pos, lbrace, methods, rbrace, false}
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:27,代码来源:parser.go

示例14: renderSection

func renderSection(section *sectionElement, context reflect.Value, buf io.Writer) {
    value := lookup(context, section.name)

    valueInd := reflect.Indirect(value)

    var contexts = new(vector.Vector)

    switch val := valueInd.(type) {
    case *reflect.BoolValue:
        if !val.Get() {
            return
        } else {
            contexts.Push(context)
        }
    case *reflect.SliceValue:
        for i := 0; i < val.Len(); i++ {
            contexts.Push(val.Elem(i))
        }
    case *reflect.ArrayValue:
        for i := 0; i < val.Len(); i++ {
            contexts.Push(val.Elem(i))
        }
    default:
        contexts.Push(context)
    }

    //by default we execute the section
    for j := 0; j < contexts.Len(); j++ {
        ctx := contexts.At(j).(reflect.Value)
        for i := 0; i < section.elems.Len(); i++ {
            renderElement(section.elems.At(i), ctx, buf)
        }
    }
}
开发者ID:sschober,项目名称:mustache.go,代码行数:34,代码来源:mustache.go

示例15: parseStructType

func (p *parser) parseStructType() *ast.StructType {
	if p.trace {
		defer un(trace(p, "StructType"))
	}

	pos := p.expect(token.STRUCT)
	lbrace := p.expect(token.LBRACE)
	list := new(vector.Vector)
	for p.tok == token.IDENT || p.tok == token.MUL {
		f := p.parseFieldDecl()
		if p.tok != token.RBRACE {
			p.expect(token.SEMICOLON)
		}
		f.Comment = p.lineComment
		list.Push(f)
	}
	rbrace := p.expect(token.RBRACE)
	p.optSemi = true

	// convert vector
	fields := make([]*ast.Field, list.Len())
	for i := list.Len() - 1; i >= 0; i-- {
		fields[i] = list.At(i).(*ast.Field)
	}

	return &ast.StructType{pos, lbrace, fields, rbrace, false}
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:27,代码来源:parser.go


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