本文整理汇总了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}
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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
}
示例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()
}
示例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
}
示例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)
}
示例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
}
示例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)})
}
示例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}
}
示例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())
}
示例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
}