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


Golang IntVector.Push方法代码示例

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


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

示例1: main

func main() {

	min := 113
	max := int(^uint32(0) >> 1)

	for currentSum := min; currentSum <= max; currentSum++ {
		var a Sum
		var initVector vector.IntVector

		for i := 0; i < currentSum; i += 1 {
			initVector.Push(1)
		}

		a.Init(initVector)

		count := recursiveMerging(a, currentSum, 0)

		fmt.Println(currentSum, count)

		if count%1000000 == 0 {
			panic("")
		}
	}

}
开发者ID:hydroo,项目名称:coding-and-math-exercises,代码行数:25,代码来源:78.go

示例2: Crossover

// Partially mapped crossover.
func (a *GAOrderedIntGenome) Crossover(bi GAGenome, p1, p2 int) (GAGenome, GAGenome) {
	ca := a.Copy().(*GAOrderedIntGenome)
	b := bi.(*GAOrderedIntGenome)
	cb := b.Copy().(*GAOrderedIntGenome)
	copy(ca.Gene[p1:p2+1], b.Gene[p1:p2+1])
	copy(cb.Gene[p1:p2+1], a.Gene[p1:p2+1])
	//Proto child needs fixing
	amap := new(vector.IntVector)
	bmap := new(vector.IntVector)
	for i := p1; i <= p2; i++ {
		ma, found := ca.pmxmap(ca.Gene[i], p1, p2)
		if found {
			amap.Push(ma)
			if bmap.Len() > 0 {
				i1 := amap.Pop()
				i2 := bmap.Pop()
				ca.Gene[i1], cb.Gene[i2] = cb.Gene[i2], ca.Gene[i1]
			}
		}
		mb, found := cb.pmxmap(cb.Gene[i], p1, p2)
		if found {
			bmap.Push(mb)
			if amap.Len() > 0 {
				i1 := amap.Pop()
				i2 := bmap.Pop()
				ca.Gene[i1], cb.Gene[i2] = cb.Gene[i2], ca.Gene[i1]
			}
		}
	}
	ca.Reset()
	cb.Reset()
	return ca, cb
}
开发者ID:mkb218,项目名称:go-galib,代码行数:34,代码来源:genome_ordered_int.go

示例3: dead

func (t *GoTracker) dead() []int {
	dead := new(vector.IntVector)
	cp := t.Copy().(*GoTracker)
	color := BLACK
	move := 0
	for {
		vertex := cp.weights.Rand(color)
		cp.Play(color, vertex)
		move++
		if move > 3*t.sqsize || cp.Winner() != EMPTY {
			break
		}
		color = Reverse(color)
	}
	for i := 0; i < t.sqsize; i++ {
		if t.board[i] != EMPTY && cp.board[i] != t.board[i] {
			dead.Push(i)
		}
	}
	stones := make([]int, dead.Len())
	for i := 0; i < dead.Len(); i++ {
		stones[i] = dead.At(i)
	}
	return stones
}
开发者ID:etherealmachine,项目名称:hivemind,代码行数:25,代码来源:gotracker.go

示例4: capture

// capture any points connected to vertex, resetting their parent, rank and weight, and liberties
// check if chains adjacent to captured are now out of atari
func (t *GoTracker) capture(vertex int) *vector.IntVector {
	// do a linear search for connected points
	captured := new(vector.IntVector)
	for i := 0; i < t.sqsize; i++ {
		if find(i, t.parent) == vertex {
			captured.Push(i)
		}
	}
	// reset
	for i := 0; i < captured.Len(); i++ {
		capture := captured.At(i)
		t.parent[capture] = capture
		t.rank[capture] = 1
		t.liberties[capture][0] = 0
		t.liberties[capture][1] = 0
		t.board[capture] = EMPTY
		t.weights.Set(BLACK, capture, INIT_WEIGHT)
		t.weights.Set(WHITE, capture, INIT_WEIGHT)
	}
	// update liberties
	for i := 0; i < captured.Len(); i++ {
		capture := captured.At(i)
		for j := 0; j < 4; j++ {
			adj := t.adj[capture][j]
			if adj != -1 {
				root := find(adj, t.parent)
				t.liberties[root][0] |= t.mask[capture][0]
				t.liberties[root][1] |= t.mask[capture][1]
			}
		}
	}
	return captured
}
开发者ID:etherealmachine,项目名称:hivemind,代码行数:35,代码来源:gotracker.go

示例5: GetPartageurs

// renvoie la liste des trolls avec qui le troll passé a un partage actif
func (store *MysqlStore) GetPartageurs(db *mysql.Client, trollId int) ([]int, os.Error) {
	st := strconv.Itoa(trollId)
	sql := "select troll_a, troll_b from partage where (troll_a=" + st + " or troll_b=" + st + ") and statut_a='on' and statut_b='on'"
	err := db.Query(sql)
	if err != nil {
		return nil, err
	}
	result, err := db.UseResult()
	if err != nil {
		return nil, err
	}
	defer result.Free()

	amis := new(vector.IntVector)
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}
		r0 := fieldAsInt(row[0])
		r1 := fieldAsInt(row[1])
		if r0 == trollId {
			amis.Push(r1)
		} else {
			amis.Push(r0)
		}
	}

	return *amis, nil

}
开发者ID:Chouia,项目名称:Chrall,代码行数:32,代码来源:partagestore.go

示例6: GetPrimeFactors

func GetPrimeFactors(number int) (*vector.IntVector, *vector.IntVector) {
	numbers := new(vector.IntVector)
	counts := new(vector.IntVector)

	primesChannel := GetPrimes()
	result := number
	for {
		prime := <-primesChannel

		if number < prime {
			break
		}

		if result%prime == 0 {
			numbers.Push(prime)
			count := 1

			for result = result / prime; result%prime == 0; result = result / prime {
				count++
			}

			counts.Push(count)
		}
	}

	return numbers, counts
}
开发者ID:andrewsmedina,项目名称:euler,代码行数:27,代码来源:12.go

示例7: PrintSorted

func (d *debugHistogram) PrintSorted() {
	if !printDebugOutput {
		return
	}
	if len(d.mapping) == 0 {
		return
	}
	var scores vector.IntVector
	inverseMapping := make(map[int]string)
	sum := 0
	for key, value := range d.mapping {
		inverseMapping[value] = key
		scores.Push(value)
		sum += value
	}
	scoresArray := sort.IntArray(scores)
	scoresArray.Sort()

	fmt.Fprintf(os.Stderr, "Debug histogram - sorted:\n")
	length := len(scoresArray)
	for i := 0; i < length; i++ {
		current := scoresArray[length-i-1]
		fmt.Fprintf(os.Stderr, "%s: %d (%2.1f%%)\n", inverseMapping[current], current, float(current)/float(sum)*100)
	}
}
开发者ID:Sh4pe,项目名称:komoku,代码行数:25,代码来源:debug.go

示例8: removeZeros

func removeZeros(c []int) []int {
	var ret vector.IntVector
	for _, v := range c {
		if v != 0 {
			ret.Push(v)
		}
	}
	return ret
}
开发者ID:hydroo,项目名称:coding-and-math-exercises,代码行数:9,代码来源:106.go

示例9: BenchmarkIntVector

func BenchmarkIntVector(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var vec vector.IntVector
		for j := 0; j < vectorLength; j++ {
			vec.Push(j)
		}
		for j := 0; j < vectorLength; j++ {
			val := vec.At(j)
			val++
		}
	}
}
开发者ID:Sh4pe,项目名称:komoku,代码行数:12,代码来源:design_decision_benchmark.go

示例10: generatePrimes

func generatePrimes(min int, max int) vector.IntVector {

	var ret vector.IntVector

	for n := min; n <= max; n++ {
		if isPrime(n) {
			ret.Push(n)
		}
	}

	return ret
}
开发者ID:hydroo,项目名称:coding-and-math-exercises,代码行数:12,代码来源:69.go

示例11: SearchPrefix

func (connection *Connection) SearchPrefix(query string) (*vector.IntVector, os.Error) {
	var count _C_int
	resp := C.tcidbsearch(connection.Dystopia, C.CString(query), C.x_prefix(), &count)
	fmt.Printf("searched for %v, num results = %d, resp = %v\n", query, count, resp)

	var result vector.IntVector
	for i := 0; i < int(count); i++ {
		result.Push(int(C.x_get_result_item(resp, _C_int(i))))
	}

	//        return &result, nil;
	return &result, nil
}
开发者ID:patrickxb,项目名称:godystopia,代码行数:13,代码来源:dystopia.go

示例12: find

// find all occurrences of s in source; report at most n occurences
func find(src, s string, n int) []int {
	var res vector.IntVector
	if s != "" && n != 0 {
		// find at most n occurrences of s in src
		for i := -1; n < 0 || len(res) < n; {
			j := strings.Index(src[i+1:], s)
			if j < 0 {
				break
			}
			i += j + 1
			res.Push(i)
		}
	}
	return res
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:16,代码来源:suffixarray_test.go

示例13: readLexeme

func readLexeme(state *LexerState,
	rune int,
	size int,
	err os.Error,
	predicate func(rune int) bool,
	reader *bufio.Reader) (string, os.Error) {
	var runes vector.IntVector
	for predicate(rune) && size > 0 && err == nil {
		runes.Push(rune)
		rune, size, err = readRune(state, reader)
	}
	if err != os.EOF {
		unreadRune(state, reader, rune)
	}
	return lexeme(runes), err
}
开发者ID:klutometis,项目名称:dragonbook,代码行数:16,代码来源:lexer.go

示例14: TestGetPrimeFactorsOfANumber

func TestGetPrimeFactorsOfANumber(t *testing.T) {
	expectedPrimes := new(vector.IntVector)
	for _, integer := range []int{2, 3, 5} {
		expectedPrimes.Push(integer)
	}

	expectedCounts := new(vector.IntVector)
	for _, integer := range []int{1, 2, 1} {
		expectedCounts.Push(integer)
	}

	gotPrimes, gotCounts := GetPrimeFactors(90)
	if !AreTwoIntVectorEquals(expectedPrimes, gotPrimes) || !AreTwoIntVectorEquals(expectedCounts, gotCounts) {
		t.Errorf("Expected primes %q. Got primes %q\nExpected count %q. Got count %q", expectedPrimes, gotPrimes)
	}
}
开发者ID:andrewsmedina,项目名称:euler,代码行数:16,代码来源:12_test.go

示例15: generatePrimes

func generatePrimes(min int, max int) []int {

	var primes vector.IntVector

	for n := min; n <= max; n++ {
		if isPrime(n) {
			primes.Push(n)
		}
	}

	ret := make([]int, len(primes))
	for k, v := range primes {
		ret[k] = v
	}

	return ret
}
开发者ID:hydroo,项目名称:coding-and-math-exercises,代码行数:17,代码来源:88-2.go


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