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


Golang StringVector.At方法代码示例

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


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

示例1: GetDotString

func (p *Trie) GetDotString() string {
	rsrc := rand.NewSource(140209)
	rgen := rand.New(rsrc)

	outStr := "digraph Trie {"
	vec := new(vector.StringVector)

	p.outputDot(vec, 0, -1, rgen)

	cnt := vec.Len()
	for i := 0; i < cnt; i++ {
		outStr = strings.Join([]string{outStr, vec.At(i)}, "\n")
	}

	return strings.Join([]string{outStr, "}"}, "\n")
}
开发者ID:alangenfeld,项目名称:cs639,代码行数:16,代码来源:trie.go

示例2: gtplist_commands

// List all commands, one by each line, sorted alphabetically
func gtplist_commands(obj *GTPObject) *GTPCommand {
	signature := []int{}
	f := func(object *GTPObject, params []interface{}) (result string, quit bool, err Error) {
		result = ""
		var cmdVector vector.StringVector
		for cmdName, _ := range obj.commands {
			cmdVector.Push(cmdName)
		}
		sort.SortStrings(sort.StringArray(cmdVector))
		result += cmdVector[0]
		for i := 1; i < cmdVector.Len(); i++ {
			result += "\n" + cmdVector.At(i)
		}
		return result, false, nil
	}
	return &GTPCommand{Signature: signature,
		Func: f,
	}
}
开发者ID:Sh4pe,项目名称:komoku,代码行数:20,代码来源:gtpcmd.go

示例3: handleTick

func (exchange *Exchange) handleTick(t int64) {
	removeTheseUnreadyQueues := new(vector.StringVector)
	for toAddress, messageQueue := range exchange.messageQueues {
		for i := 0; i < messageQueue.Len(); i++ {
			msg := messageQueue.At(i).(Message)
			if msg.timeout < t {
				exchange.logf(LogLevelDebug, "> %v %v %v %v", len(msg.Body), msg.TimeoutSeconds, msg.ToAddress, msg.ReplyAddress)
				exchange.logf(LogLevelDebug, "  send timeout")
				messageQueue.Delete(i)
				i--
			}
		}
		if messageQueue.Len() == 0 {
			removeTheseUnreadyQueues.Push(toAddress)
		}
	}
	for i := 0; i < removeTheseUnreadyQueues.Len(); i++ {
		exchange.messageQueues[removeTheseUnreadyQueues.At(i)] = nil, false
	}

	removeTheseReadyStates := new(vector.StringVector)
	for onAddress, readyStateQueue := range exchange.readyStateQueues {
		for i := 0; i < readyStateQueue.Len(); i++ {
			readyState := readyStateQueue.At(i).(*readyState)
			if readyState.timeout < t {
				exchange.logf(LogLevelDebug, "* ready timeout %v", onAddress)
				if !readyState.timeoutReceived {
					readyState.messageChan <- Message{"", "", 0, "", 0}
					readyState.timeoutReceived = true
				}
				readyStateQueue.Delete(i)
				i--
			}
		}
		if readyStateQueue.Len() == 0 {
			removeTheseReadyStates.Push(onAddress)
		}
	}
	for i := 0; i < removeTheseReadyStates.Len(); i++ {
		exchange.readyStateQueues[removeTheseReadyStates.At(i)] = nil, false
	}
}
开发者ID:jmptrader,项目名称:msglite,代码行数:42,代码来源:core.go

示例4: gtpkomoku_sourceforkn

// As gtpkomoku_sourcen, except that it makes replaces the board with a copy of it in each move. This is used to debug
// Board.Copy()
func gtpkomoku_sourceforkn(obj *GTPObject) *GTPCommand {
	signature := []int{GTPString, GTPInt}
	f := func(object *GTPObject, params []interface{}) (result string, quit bool, err Error) {
		filename, _ := params[0].(string)
		n := int(params[1].(uint))
		file, er := os.Open(filename, os.O_RDONLY, 0)
		if er != nil {
			return fmt.Sprintf("error: '%s'", err), false, NewIOError(er)
		}
		input := bufio.NewReader(file)
		var lines vector.StringVector
		line, er := input.ReadString('\n')
		lines.Push(line)
		for er != os.EOF {
			lines.Push(line)
			line, er = input.ReadString('\n')
		}
		length := lines.Len()
		line = ""
		for i := 0; i < length; i++ {
			line = lines.At(i)
			if length-i <= n {
				line = "#" + line
			}
			fmt.Printf(line)
			obj.ai.environment.Game.Board = obj.ai.environment.Game.Board.Copy()
			lineResult, lineQuit, _ := obj.ExecuteCommand(line)
			fmt.Printf(lineResult)
			if lineQuit {
				return "", true, nil
			}
		}
		fmt.Println("\nend komoku-sourceforkn")
		return "", false, nil
	}
	return &GTPCommand{Signature: signature,
		Func: f,
	}
}
开发者ID:Sh4pe,项目名称:komoku,代码行数:41,代码来源:gtpcmd.go

示例5: ExecutionModelSpec

func ExecutionModelSpec(c nanospec.Context) {

	c.Specify("Specs with children, but without siblings, are executed fully on one run", func() {

		c.Specify("Case: no children", func() {
			runSpecWithContext(DummySpecWithNoChildren, newInitialContext())
			c.Expect(testSpy).Equals("root")
		})
		c.Specify("Case: one child", func() {
			runSpecWithContext(DummySpecWithOneChild, newInitialContext())
			c.Expect(testSpy).Equals("root,a")
		})
		c.Specify("Case: nested children", func() {
			runSpecWithContext(DummySpecWithNestedChildren, newInitialContext())
			c.Expect(testSpy).Equals("root,a,aa")
		})
	})

	c.Specify("Specs with siblings are executed only one sibling at a time", func() {

		c.Specify("Case: on initial run, the 1st child is executed", func() {
			runSpecWithContext(DummySpecWithTwoChildren, newInitialContext())
			c.Expect(testSpy).Equals("root,a")
		})
		c.Specify("Case: explicitly execute the 1st child", func() {
			runSpecWithContext(DummySpecWithTwoChildren, newExplicitContext([]int{0}))
			c.Expect(testSpy).Equals("root,a")
		})
		c.Specify("Case: explicitly execute the 2nd child", func() {
			runSpecWithContext(DummySpecWithTwoChildren, newExplicitContext([]int{1}))
			c.Expect(testSpy).Equals("root,b")
		})
	})

	c.Specify("Specs with nested siblings: eventually all siblings are executed, one at a time, in isolation", func() {
		r := NewRunner()
		r.AddSpec(DummySpecWithMultipleNestedChildren)

		// Execute manually instead of calling Run(), in order to avoid running
		// the specs multi-threadedly, which would mess up the test spy.
		runs := new(vector.StringVector)
		for r.hasScheduledTasks() {
			resetTestSpy()
			r.executeNextScheduledTask()
			runs.Push(testSpy)
		}
		sort.Sort(runs)

		c.Expect(runs.Len()).Equals(5)
		c.Expect(runs.At(0)).Equals("root,a,aa")
		c.Expect(runs.At(1)).Equals("root,a,ab")
		c.Expect(runs.At(2)).Equals("root,b,ba")
		c.Expect(runs.At(3)).Equals("root,b,bb")
		c.Expect(runs.At(4)).Equals("root,b,bc")
	})
}
开发者ID:boggle,项目名称:gospec,代码行数:56,代码来源:execution_model_test.go

示例6: TestMultiFindValue

func TestMultiFindValue(t *testing.T) {
	trie := NewTrie()

	// these are part of the matches for the word 'hyphenation'
	trie.AddPatternString(`hy3ph`)
	trie.AddPatternString(`he2n`)
	trie.AddPatternString(`hena4`)
	trie.AddPatternString(`hen5at`)

	v1 := &vector.IntVector{0, 3, 0, 0}
	v2 := &vector.IntVector{0, 2, 0}
	v3 := &vector.IntVector{0, 0, 0, 4}
	v4 := &vector.IntVector{0, 0, 5, 0, 0}

	expectStr := new(vector.StringVector)
	expectVal := new(vector.Vector) // contains elements of type *vector.IntVector

	expectStr.Push(`hyph`)
	expectVal.Push(v1)
	found, values := trie.AllSubstringsAndValues(`hyphenation`)
	if found.Len() != expectStr.Len() {
		t.Errorf("expected %v but found %v", *expectStr, *found)
	}
	if values.Len() != expectVal.Len() {
		t.Errorf("Length mismatch: expected %v but found %v", *expectVal, *values)
	}
	for i := 0; i < found.Len(); i++ {
		if found.At(i) != expectStr.At(i) {
			t.Errorf("Strings content mismatch: expected %v but found %v", *expectStr, *found)
			break
		}
	}
	for i := 0; i < values.Len(); i++ {
		ev := expectVal.At(i).(*vector.IntVector)
		fv := values.At(i).(*vector.IntVector)
		if ev.Len() != fv.Len() {
			t.Errorf("Value length mismatch: expected %v but found %v", *ev, *fv)
			break
		}
		for i := 0; i < ev.Len(); i++ {
			if ev.At(i) != fv.At(i) {
				t.Errorf("Value mismatch: expected %v but found %v", *ev, *fv)
				break
			}
		}
	}

	expectStr.Cut(0, expectStr.Len())
	expectVal.Cut(0, expectVal.Len())

	expectStr.AppendVector(&vector.StringVector{`hen`, `hena`, `henat`})
	expectVal.Push(v2)
	expectVal.Push(v3)
	expectVal.Push(v4)
	found, values = trie.AllSubstringsAndValues(`henation`)
	if found.Len() != expectStr.Len() {
		t.Errorf("expected %v but found %v", *expectStr, *found)
	}
	if values.Len() != expectVal.Len() {
		t.Errorf("Length mismatch: expected %v but found %v", *expectVal, *values)
	}
	for i := 0; i < found.Len(); i++ {
		if found.At(i) != expectStr.At(i) {
			t.Errorf("Strings content mismatch: expected %v but found %v", *expectStr, *found)
			break
		}
	}
	for i := 0; i < values.Len(); i++ {
		ev := expectVal.At(i).(*vector.IntVector)
		fv := values.At(i).(*vector.IntVector)
		if ev.Len() != fv.Len() {
			t.Errorf("Value length mismatch: expected %v but found %v", *ev, *fv)
			break
		}
		for i := 0; i < ev.Len(); i++ {
			if ev.At(i) != fv.At(i) {
				t.Errorf("Value mismatch: expected %v but found %v", *ev, *fv)
				break
			}
		}
	}
}
开发者ID:AlanQuatermain,项目名称:go-trie,代码行数:82,代码来源:trie_test.go


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