當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Vector.Pop方法代碼示例

本文整理匯總了Golang中container/vector.Vector.Pop方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vector.Pop方法的具體用法?Golang Vector.Pop怎麽用?Golang Vector.Pop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在container/vector.Vector的用法示例。


在下文中一共展示了Vector.Pop方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

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

示例2: main

func main() {
	re1 := new(vector.Vector)
	re1.Push(10)
	fmt.Print(re1.Pop())

	infcheck(5)

	re1.Push(10)
	re1.Push(20)
	//  fmt.Print(re1.Less(0,1))
	fmt.Print("\n")
	i := 10
	checkpoint(&i)
	checkTypeComp()
	//  fmt.Print(int32(10).Less(5));
}
開發者ID:mivi,項目名稱:sb-go,代碼行數:16,代碼來源:try5-vector.go

示例3: renderSection

func renderSection(section *sectionElement, contextChain *vector.Vector, buf io.Writer) {
	value := lookup(contextChain, section.name)
	var context = contextChain.At(contextChain.Len() - 1).(reflect.Value)
	var contexts = new(vector.Vector)
	// if the value is nil, check if it's an inverted section
	isNil := isNil(value)
	if isNil && !section.inverted || !isNil && section.inverted {
		return
	} else {
		valueInd := indirect(value)
		switch val := valueInd; val.Kind() {
		case reflect.Slice:
			for i := 0; i < val.Len(); i++ {
				contexts.Push(val.Index(i))
			}
			if val.Len() == 0 {
				contexts.Push(context)
			}
		case reflect.Array:
			for i := 0; i < val.Len(); i++ {
				contexts.Push(val.Index(i))
			}
			if val.Len() == 0 {
				contexts.Push(context)
			}
		case reflect.Map, reflect.Struct:
			contexts.Push(value)
		default:
			contexts.Push(context)
		}
	}

	//by default we execute the section
	for j := 0; j < contexts.Len(); j++ {
		ctx := contexts.At(j).(reflect.Value)
		contextChain.Push(ctx)
		for i := 0; i < section.elems.Len(); i++ {
			renderElement(section.elems.At(i), contextChain, buf)
		}
		contextChain.Pop()
	}
}
開發者ID:xconstruct,項目名稱:bin-o-bookmarks,代碼行數:42,代碼來源:mustache.go

示例4: run


//.........這裏部分代碼省略.........
			stack.regs[dst] = Void
		case CLOSURE:
			f := make([]Obj, (i&OP1_N)>>OP1_N_SHIFT)
			stack.regs[i&OP1_R2] = wrap(&Procedure{apply: aprun, free: f, code: stack.code})
		case CLOSURE_NAME:
			p := (*stack.regs[i&OP1_R2]).(*Procedure)
			name := stack.regs[(i&OP1_R1)>>OP1_R1_SHIFT]
			if is_immediate(name) {
				continue
			}
			p.name = (*name).(string)
		case CLOSURE_VAR:
			p := (*stack.regs[i&OP1_R2]).(*Procedure)
			value := stack.regs[(i&OP1_R1)>>OP1_R1_SHIFT]
			freevar := (i & OP1_N) >> OP1_N_SHIFT
			p.free[freevar] = value
		case CLOSURE_REF:
			p := stack.cc
			freevar := (i & OP1_N) >> OP1_N_SHIFT
			stack.regs[i&OP1_R2] = p.free[freevar]
		case FUNCALL:
			// stack_trace(stack)
			r := int(i & OP1_R2)
			argnum := int((i & OP1_N) >> OP1_N_SHIFT)
			_p := stack.regs[(i&OP1_R1)>>OP1_R1_SHIFT]
			if is_immediate(_p) {
				panic("Bad type to apply")
			}
			p := (*_p).(*Procedure)
			if p.apply != aprun {
				// This is a primitive.
				args := make([]Obj, argnum)
				for i := argnum - 1; i >= 0; i-- {
					args[i] = (argstack.Pop()).(Obj)
				}
				stack.regs[r] = p.apply(p, args, ct)
				continue
			}
			dst_i := p.code.bc[p.label]
			if (dst_i >> I_SHIFT) != FRAME {
				panic(fmt.Sprintf("Procedure %s at #x%x has no FRAME: #x%x",
					p.name, p.label, i))
			}
			frame := call_frame(stack, r, pc, argnum+int((dst_i&OP1_R2)))
			for i := argnum - 1; i >= 0; i-- {
				frame.regs[i] = (argstack.Pop()).(Obj)
			}
			frame.cc = p
			frame.argnum = argnum
			frame.code = p.code
			stack = frame
			pc = p.label
			// stack_trace(stack)
			//fmt.Printf("funcall to %d (%s), new frame = %v\n",pc,p.name,stack)
		case TAILCALL:
			argnum := int((i & OP1_N) >> OP1_N_SHIFT)
			_p := stack.regs[i&OP1_R2]
			if is_immediate(_p) {
				panic("Bad type to apply")
			}
			p := (*_p).(*Procedure)
			dst_i := p.code.bc[p.label]
			if (dst_i >> I_SHIFT) != FRAME {
				panic(fmt.Sprintf("Procedure at #x%x has no FRAME: #x%x",
					p.label, i))
			}
開發者ID:weinholt,項目名稱:conscheme,代碼行數:67,代碼來源:vm.go

示例5: AddRegex

func (self *BasicState) AddRegex(re string, m RegexSet) (*BasicState, os.Error) {
	if m == nil {
		m = defaultMeta
	}
	// this is just the sort of horror show that lexical analysis avoids

	// stack machine
	start := self
	end := NewState()
	stack := new(vector.Vector)

	// state flags
	expr, esc, cs := false, false, false
	setstr := ""

	// go into a subexpression
	push := func() {
		rp := &regexPos{start, end}
		stack.Push(rp)
		end = NewState()
		start.AddEmptyTransition(end)
	}
	// come out of a subexpression
	pop := func() {
		rp := stack.Pop().(*regexPos)
		end.AddEmptyTransition(rp.end)
		start = rp.start
		end = rp.end
	}
	// move forward, for the purposes of concatenation
	move := func() {
		start = end
		end = NewState()
	}

	// the expression is inside an implicit ( ... )
	push()

	// parse the expression
	for _, c := range re {
		// escaped characters
		if esc {
			esc = false
			// inside a charset jobby
			if cs {
				setstr += string(c)
				continue
			}
			// check out the metachar action
			if meta, ok := m[c]; ok {
				move()
				chars, err := Charset(meta, end)
				if err != nil {
					return nil, err
				}
				start.AddEmptyTransition(chars)
				expr = true
				continue
			}
			// nothing else going on? well you escaped it for a reason
			goto add
		}
		// charsets
		if cs {
			if c == '\\' {
				esc = true
			} else if c == ']' {
				chars, err := Charset(setstr, end)
				if err != nil {
					return nil, err
				}
				start.AddEmptyTransition(chars)
				setstr = ""
				cs = false
				expr = true
			} else {
				setstr += string(c)
			}
			continue
		}
		// everything else
		switch c {
		// charsets
		case '.':
			move()
			start.AddEmptyTransition(Any(end))
			expr = true
		case '[':
			move()
			cs = true
		case ']':
			if !cs {
				return nil, os.ErrorString("trying to close unopened charset")
			}
		// grouping
		case '(':
			move()
			push()
			expr = false
		case ')':
//.........這裏部分代碼省略.........
開發者ID:ypb,項目名稱:bwl,代碼行數:101,代碼來源:regex.go

示例6: binaryExpr

// Sets multiLine to true if the binary expression spans multiple lines.
func (p *printer) binaryExpr(x *ast.BinaryExpr, prec1 int, multiLine *bool) {
	prec := x.Op.Precedence()
	if prec < prec1 {
		// parenthesis needed
		// Note: The parser inserts an ast.ParenExpr node; thus this case
		//       can only occur if the AST is created in a different way.
		p.print(token.LPAREN)
		p.expr(x, multiLine)
		p.print(token.RPAREN)
		return
	}

	// Traverse left, collect all operations at same precedence
	// and determine if blanks should be printed around operators.
	//
	// This algorithm assumes that the right-hand side of a binary
	// operation has a different (higher) precedence then the current
	// node, which is how the parser creates the AST.
	var list vector.Vector
	line := x.Y.Pos().Line
	printBlanks := prec <= token.EQL.Precedence() || needsBlanks(x.Y)
	for {
		list.Push(x)
		if t, ok := x.X.(*ast.BinaryExpr); ok && t.Op.Precedence() == prec {
			x = t
			prev := line
			line = x.Y.Pos().Line
			if needsBlanks(x.Y) || prev != line {
				printBlanks = true
			}
		} else {
			break
		}
	}
	prev := line
	line = x.X.Pos().Line
	if needsBlanks(x.X) || prev != line {
		printBlanks = true
	}

	// Print collected operations left-to-right, with blanks if necessary.
	ws := indent
	p.expr1(x.X, prec, multiLine)
	for list.Len() > 0 {
		x = list.Pop().(*ast.BinaryExpr)
		prev := line
		line = x.Y.Pos().Line
		if printBlanks {
			if prev != line {
				p.print(blank, x.OpPos, x.Op)
				// at least one line break, but respect an extra empty line
				// in the source
				if p.linebreak(line, 1, 2, ws, true) {
					ws = ignore
					*multiLine = true
				}
			} else {
				p.print(blank, x.OpPos, x.Op, blank)
			}
		} else {
			if prev != line {
				panic("internal error")
			}
			p.print(x.OpPos, x.Op)
		}
		p.expr1(x.Y, prec, multiLine)
	}
	if ws == ignore {
		p.print(unindent)
	}
}
開發者ID:8l,項目名稱:go-learn,代碼行數:72,代碼來源:nodes.go

示例7: parse_forth

func parse_forth(dat string, DataStack *vector.Vector) {
	L := DataStack.Len()

	switch strings.TrimSpace(string(dat)) {
	case "":
	case "<cr>":
		return
	case "t":
		//check the DataStack size using the popped value
		//	if it passes, then the program continues
		minimum := int(DataStack.Pop().(float32))
		if DataStack.Len() < minimum {
			log.Println("DataStack has not enough minerals (values)")
		}
	case ".":
		log.Println(DataStack.Pop())
	case "0SP":
		DataStack.Cut(0, L)
	case ".S":
		log.Println(DataStack)
	case "2/":
		DataStack.Push(DataStack.Pop().(float32) / 2)
	case "2*":
		DataStack.Push(DataStack.Pop().(float32) * 2)
	case "2-":
		DataStack.Push(DataStack.Pop().(float32) - 2)
	case "2+":
		DataStack.Push(DataStack.Pop().(float32) + 2)
	case "1-":
		DataStack.Push(DataStack.Pop().(float32) - 1)
	case "1+":
		DataStack.Push(DataStack.Pop().(float32) + 1)
	case "DUP":
		DataStack.Push(DataStack.Last())
	case "?DUP":
		if DataStack.Last().(float32) != 0 {
			DataStack.Push(DataStack.Last().(float32))
		}
	case "PICK":
		number := int(DataStack.Pop().(float32))

		if number < L {
			DataStack.Push(DataStack.At(L - 1 - number).(float32))
		} else {
			log.Fatal("picking out of stack not allowed. Stack Length: " + string(L) + ". Selecting: " + string(number) + ".")
			return
		}
	case "TUCK":
		DataStack.Insert(L-2, int(DataStack.Last().(float32)))
	case "NIP":
		DataStack.Delete(L - 2)
	case "2DROP":
		DataStack.Pop()
		DataStack.Pop()
	case "2DUP":
		DataStack.Push(DataStack.At(L - 2))
		DataStack.Push(DataStack.At(DataStack.Len() - 2))
	case "DROP":
		DataStack.Pop()
	case "OVER":
		DataStack.Push(DataStack.At(L - 2))
	case "SWAP":
		l := DataStack.Len()
		DataStack.Swap(l-2, l-1)
	case "*":
		num1 := DataStack.Pop().(float32)
		num2 := DataStack.Pop().(float32)
		DataStack.Push(num1 * num2)
	case "+":
		num1 := DataStack.Pop().(float32)
		num2 := DataStack.Pop().(float32)
		DataStack.Push(num1 + num2)
	case "-":
		num1 := DataStack.Pop().(float32)
		num2 := DataStack.Pop().(float32)
		DataStack.Push(num2 - num1)
	case "/":
		num1 := DataStack.Pop().(float32)
		num2 := DataStack.Pop().(float32)
		DataStack.Push(num2 / num1)
	case "-ROT":
		DataStack.Swap(L-1, L-2)
		DataStack.Swap(L-2, L-3)
	case "ROT":
		DataStack.Swap(L-3, L-2)
		DataStack.Swap(L-2, L-1)
	case "2OVER":
		DataStack.Push(DataStack.At(L - 4))
		DataStack.Push(DataStack.At(DataStack.Len() - 4))
	case "2SWAP":
		DataStack.Swap(L-4, L-2)
		DataStack.Swap(L-3, L-1)
	case "EMIT":
		log.Println(string([]byte{uint8(DataStack.Last().(float32))}))
	default:
		val, ok := strconv.Atof32(dat)

		if ok == nil {
			DataStack.Push(val)
		} else {
//.........這裏部分代碼省略.........
開發者ID:nunb,項目名稱:GoForth,代碼行數:101,代碼來源:main.go

示例8: 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.Pop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。