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


Golang Vector.At方法代码示例

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


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

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

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

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

示例4: main

func main(){
    var v vector.Vector
    v.Push(1234.) //stored as interface value
    i := v.At(0)
    if i.(float64) != 1234. {}
    //if i.(int) != 1234 {} //runtime err, as the cast fails
    //if i.(MyFloat) != 1234. {} //err, MyFloat unknown

    v.Push(666)
    v.Push("foobar")
    for _, elem := range v{
        if i, ok := elem.(int); ok {
            fmt.Printf("int: %d\n", i)
        } else if f, ok := elem.(float64); ok {
            fmt.Printf("float64: %g\n", f)
        } else {
            fmt.Print("unknown type\n")
        }
    }

    for _, elem := range v{
        switch v := elem.(type){
            case int: 
                fmt.Printf("is int: %d\n", v)
            case float64:
                fmt.Printf("is float64: %g\n", v)
            default:
                fmt.Print("unknown type\n")
        }
    }

}
开发者ID:dgquintas,项目名称:my-code-samples,代码行数:32,代码来源:vector_example.go

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

示例6: parseExpression

func (p *parser) parseExpression() Expression {
	var list vector.Vector

	for {
		x := p.parseSequence()
		if x != nil {
			list.Push(x)
		}
		if p.tok != token.OR {
			break
		}
		p.next()
	}

	// no need for an Alternative node if list.Len() < 2
	switch list.Len() {
	case 0:
		return nil
	case 1:
		return list.At(0).(Expression)
	}

	// convert list into an Alternative node
	alt := make(Alternative, list.Len())
	for i := 0; i < list.Len(); i++ {
		alt[i] = list.At(i).(Expression)
	}
	return alt
}
开发者ID:zhuSilence,项目名称:golang-china,代码行数:29,代码来源:parser.go

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

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

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

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

示例11: parseLiteral

func (p *parser) parseLiteral() literal {
	s := []byte(p.parseString())

	// A string literal may contain %-format specifiers. To simplify
	// and speed up printing of the literal, split it into segments
	// that start with "%" possibly followed by a last segment that
	// starts with some other character.
	var list vector.Vector
	i0 := 0
	for i := 0; i < len(s); i++ {
		if s[i] == '%' && i+1 < len(s) {
			// the next segment starts with a % format
			if i0 < i {
				// the current segment is not empty, split it off
				list.Push(s[i0:i])
				i0 = i
			}
			i++ // skip %; let loop skip over char after %
		}
	}
	// the final segment may start with any character
	// (it is empty iff the string is empty)
	list.Push(s[i0:])

	// convert list into a literal
	lit := make(literal, list.Len())
	for i := 0; i < list.Len(); i++ {
		lit[i] = list.At(i).([]byte)
	}

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

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

示例13: 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 {
	list := new(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, list.Len())
	for i := 0; i < list.Len(); i++ {
		group[i] = list.At(i).(*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:rapgamer,项目名称:golang-china,代码行数:31,代码来源:parser.go

示例14: SeqTime

// takes vector of nodes, returns sequential schedule length
func SeqTime(v vec.Vector) int64 {
	var s int64
	s = 0
	for i := 0; i < v.Len(); i++ {
		s += (v.At(i).(*p.Node)).Ex
	}
	return s
}
开发者ID:mcherba,项目名称:dagsched,代码行数:9,代码来源:getTimes.go

示例15: _AppendParamsData

func _AppendParamsData(buff *bytes.Buffer, sig string, params *vector.Vector) {
	sigOffset := 0
	prmsOffset := 0
	for ; sigOffset < len(sig); prmsOffset++ {
		offset, _ := _AppendValue(buff, sig[sigOffset:len(sig)], params.At(prmsOffset))
		sigOffset += offset
	}
}
开发者ID:papamitra,项目名称:go-dbus,代码行数:8,代码来源:marshall.go


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