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


Golang List.PushBack方法代码示例

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


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

示例1: searchRiverStates

func searchRiverStates(queue *list.List) {
	current := queue.Back().Value.(itemState)

	if current.isFinal() {
		// 已经是最后状态了
		printRiver(queue)
	} else {
		if current.currentAction.direct == 0 {
			for i := 0; i < 5; i++ {
				next := current.move(backAction[i])
				//next.printState()
				if next.validate() && !isProcessedRiverState(queue, next) {
					queue.PushBack(next)
					searchRiverStates(queue)
					queue.Remove(queue.Back())
				}
			}
		} else {
			for i := 0; i < 5; i++ {
				next := current.move(goAction[i])
				//next.printState()
				if next.validate() && !isProcessedRiverState(queue, next) {
					queue.PushBack(next)
					searchRiverStates(queue)
					queue.Remove(queue.Back())
				}
			}
		}
	}
}
开发者ID:yybear,项目名称:-Algorithmfun,代码行数:30,代码来源:demonsAndMonks.go

示例2: DecomposeRecordLayer

func DecomposeRecordLayer(tlsPayload []byte) list.List {
	if len(tlsPayload) < 5 {
		return list.List{}
	}
	log.Println("Parsing one packet......")
	var tlsLayerlist list.List
	total := uint16(len(tlsPayload))
	var offset uint16 = 0

	for offset < total {
		var p TLSHandshakeDecoder.TLSRecordLayer
		p.ContentType = uint8(tlsPayload[0+offset])
		p.Version = uint16(tlsPayload[1+offset])<<8 | uint16(tlsPayload[2+offset])
		p.Length = uint16(tlsPayload[3+offset])<<8 | uint16(tlsPayload[4+offset])
		p.Fragment = make([]byte, p.Length)
		l := copy(p.Fragment, tlsPayload[5+offset:5+p.Length+offset])
		tlsLayerlist.PushBack(p)
		log.Println("Length: ", p.Length, "Type: ", p.ContentType)
		offset += 5 + p.Length
		if l < int(p.Length) {
			fmt.Errorf("Payload to short: copied %d, expected %d.", l, p.Length)
		}
	}
	return tlsLayerlist
}
开发者ID:rahulsom,项目名称:tlsdr,代码行数:25,代码来源:ParserUtil.go

示例3: queueUnseen

// queueUnseenImports scans a package's imports and adds any new ones to the
// processing queue.
func (r *Resolver) queueUnseen(pkg string, queue *list.List) error {
	// A pkg is marked "seen" as soon as we have inspected it the first time.
	// Seen means that we have added all of its imports to the list.

	// Already queued indicates that we've either already put it into the queue
	// or intentionally not put it in the queue for fatal reasons (e.g. no
	// buildable source).

	deps, err := r.imports(pkg)
	if err != nil && !strings.HasPrefix(err.Error(), "no buildable Go source") {
		msg.Error("Could not find %s: %s", pkg, err)
		return err
		// NOTE: If we uncomment this, we get lots of "no buildable Go source" errors,
		// which don't ever seem to be helpful. They don't actually indicate an error
		// condition, and it's perfectly okay to run into that condition.
		//} else if err != nil {
		//	msg.Warn(err.Error())
	}

	for _, d := range deps {
		if _, ok := r.alreadyQ[d]; !ok {
			r.alreadyQ[d] = true
			queue.PushBack(d)
		}
	}
	return nil
}
开发者ID:rudle,项目名称:glide,代码行数:29,代码来源:resolver.go

示例4: NewTasksFromConfig

func (s system) NewTasksFromConfig(config map[string]interface{}) (*list.List, error) {
	tasks, ok := config["tasks"]
	if !ok {
		return nil, errors.New("The field tasks was not found")
	}

	switch vt := tasks.(type) {
	case []interface{}:
		fmt.Printf("vt: %v\n", vt)

		tasks := new(list.List)

		for t, val := range vt {
			fmt.Printf("%v == %v\n", t, val)
			mt, ok := val.(map[string]interface{})
			if ok {
				task, err := s.NewTask(mt)
				if err == nil {
					log.Printf("Adding %v", task)
					tasks.PushBack(task)
				} else {
					log.Printf("Could not add %v, %v", val, err)
				}
			}
		}

		return tasks, nil
	default:
		return nil, errors.New("tasks field was wrong type")
	}

	return nil, nil
}
开发者ID:wolfgarnet,项目名称:automation,代码行数:33,代码来源:system.go

示例5: pushMetric

// pushMetric adds the metric to the end of the list and returns a comma separated string of the
// previous 61 entries.  We return 61 instead of 60 (an hour) because the chart on the client
// tracks deltas between these values - there is nothing to compare the first value against.
func pushMetric(history *list.List, ev expvar.Var) string {
	history.PushBack(ev.String())
	if history.Len() > 61 {
		history.Remove(history.Front())
	}
	return JoinStringList(history)
}
开发者ID:barbourkd,项目名称:inbucket,代码行数:10,代码来源:listener.go

示例6: buildArgumentsMonochrome

func (server *Server) buildArgumentsMonochrome(arguments *list.List, params imageserver.Params) error {
	monochrome, _ := params.GetBool("monochrome")
	if monochrome {
		arguments.PushBack("-monochrome")
	}
	return nil
}
开发者ID:phamhongviet,项目名称:imageserver,代码行数:7,代码来源:graphicsmagick.go

示例7: ParseTokens

func ParseTokens(t []string) *list.List {
	tokens := new(list.List)
	for i := range t {
		tokens.PushBack(t[i])
	}
	n := 0
	s, o := new(list.List), new(list.List)
	for e := tokens.Front(); e != nil; e = e.Next() {
		if e.Value.(string) == "(" {
			n++
			listAppend(s, new(list.List))
			listAppend(o, s)
			s = s.Back().Value.(*list.List)
		} else if e.Value.(string) == ")" {
			n--
			s = o.Back().Value.(*list.List)
			listPop(o)
		} else {
			listAppend(s, e.Value.(string))
		}
	}
	if n != 0 {
		Error("unbalanced parantheses")
	}
	return s
}
开发者ID:sfstpala,项目名称:nil,代码行数:26,代码来源:test.go

示例8: testContainers

func testContainers() {
	fmt.Println("\n\n")
	fmt.Println("****************************************************")
	fmt.Println("Containers, lists, sorts")
	fmt.Println("****************************************************")

	var x list.List
	for i := 0; i < 10; i++ {
		x.PushBack(rand.Int() % 20)
	}
	fmt.Println("A list")
	for e := x.Front(); e != nil; e = e.Next() {
		fmt.Println(e.Value.(int))
	}

	//Sort
	kids := []Person{
		{"Kara", 2},
		{"Bethany", 1},
		{"Zach", 3},
	}

	fmt.Println("People:", kids)
	sort.Sort(ByName(kids))
	fmt.Println("Sorted People by Name:", kids)
	sort.Sort(ByAge(kids))
	fmt.Println("Sorted People by Age", kids)

}
开发者ID:SiroDiaz,项目名称:csuf,代码行数:29,代码来源:ch13_everything.go

示例9: prime_gen

func prime_gen(out chan<- int64) {
	out <- int64(2)
	out <- int64(3)
	known_primes := new(list.List)
	known_primes.PushBack(int64(2))
	known_primes.PushBack(int64(3))

	for try := int64(5); ; try += int64(2) {
		try_is_prime := true

		for e := known_primes.Front(); try_is_prime && e != nil; e = e.Next() {
			p, _ := e.Value.(int64)

			if try%p == 0 {
				try_is_prime = false
			} else if (p + p) > try {
				break
			}
		}

		if try_is_prime {
			out <- try
			known_primes.PushBack(try)
		}
	}
}
开发者ID:redeyes2015,项目名称:junkcodes,代码行数:26,代码来源:euler_3.go

示例10: GetAndParseXML

func GetAndParseXML(_xml_url string, _queue *list.List) int {
	if _queue == nil {
		logger.Alwaysln("Error: queue is nil")
		return 0
	}
	// Get .xml file from server
	xmlfile, err := http.Get(_xml_url)
	if err != nil {
		logger.Alwaysln("Get \"" + _xml_url + "\": " + err.Error())
		return 0
	}
	logger.Moreln("Get \"" + _xml_url + "\": OK")
	xmltext, err := ioutil.ReadAll(xmlfile.Body)

	// tokenize .xml file
	var xmldoc XMLSTRUCT
	err = xml.Unmarshal([]byte(xmltext), &xmldoc)
	if err != nil {
		logger.Alwaysln("Unmarshal \"" + _xml_url + "\" failed: " + err.Error())
		return 0
	}
	logger.Moreln("Unmarshal \"" + _xml_url + "\": OK ")

	count := len(xmldoc.Urls)
	for index := 0; index < count; index++ {
		if !ShouldItBeDownloaded(xmldoc.Urls[index]) {
			logger.Debugln(xmldoc.Urls[index] + " already downloaded")
			continue
		}
		_queue.PushBack(xmldoc.Urls[index])
	}
	logger.Alwaysln(_xml_url + " OK")
	return count
}
开发者ID:Vetcher,项目名称:pagedownloader,代码行数:34,代码来源:main.go

示例11: collectNewVideo

func collectNewVideo(endVideoId string, endDateTime string, videos *list.List) {
	count := 0
	breakCount := 0
	limit := 300
	next := true

	for pageNo := 1; next; pageNo++ {
		doc := getSearchResultDoc(pageNo)

		doc.Find(".thumb_col_1").Each(func(_ int, s *goquery.Selection) {
			videoLink := s.Find(".watch")
			rawVideoId, _ := videoLink.Attr("href")
			videoId := regexp.MustCompile("[0-9]+").FindString(rawVideoId)
			postDatetime := regexp.MustCompile("[年月日 /:]").ReplaceAllString(s.Find(".thumb_num strong").Text(), "")
			title, _ := videoLink.Attr("title")

			if len(postDatetime) == 12 {
				// NOP
			} else if len(postDatetime) == 10 {
				postDatetime = "20" + postDatetime
			} else if len(postDatetime) == 8 {
				postMonth, _ := strconv.Atoi(postDatetime[0:2])
				nowMonth, _ := strconv.Atoi(fmt.Sprint(time.Now().Month()))
				if nowMonth < postMonth {
					postDatetime = fmt.Sprint(time.Now().AddDate(-1, 0, 0).Year()) + postDatetime
				} else {
					postDatetime = fmt.Sprint(time.Now().Year()) + postDatetime
				}
			} else {
				panic("投稿日時の長さがおかしいですよ")
			}

			if postDatetime < endDateTime {
				breakCount++
			}

			// 読み込み中断判定
			if (endVideoId != "" && 100 <= breakCount) || (limit != 0 && limit <= count) {
				next = false
				count++
				return
			}

			isNewVideo := true
			for vi := videos.Front(); vi != nil; vi = vi.Next() {
				viMap := vi.Value.(map[string]string)
				if videoId == viMap["id"] {
					isNewVideo = false
					continue
				}
			}

			if isNewVideo {
				videoMap := map[string]string{"id": videoId, "datetime": postDatetime, "title": title}
				videos.PushBack(videoMap)
			}
			count++
		})
	}
}
开发者ID:hogesuke,项目名称:NicoNewVideoChecker,代码行数:60,代码来源:NewVideoCollector.go

示例12: Map

// our simplified version of MapReduce does not supply a
// key to the Map function, as in the paper; only a value,
// which is a part of the input file contents
// map function return a list of KeyValue, represents a words total occurance in each split file
func Map(value string) *list.List {
	f := func(c rune) bool {
		return !unicode.IsLetter(c) && !unicode.IsNumber(c)
	}
	words := strings.FieldsFunc(value, f)

	kvs := make(map[string]int)

	for i := 0; i < len(words); i++ {
		word := words[i]

		_, ok := kvs[word]

		if !ok {
			kvs[word] = 1
		} else {
			kvs[word] += 1
		}

	}

	var r list.List

	for key, value := range kvs {
		r.PushBack(mapreduce.KeyValue{key, strconv.Itoa(value)})
	}

	return &r
}
开发者ID:Sherlock2010,项目名称:6.824,代码行数:33,代码来源:wc.go

示例13: testScatterDeleteMulti

func testScatterDeleteMulti(tree T, t *testing.T) {
	name := "test"
	pointNum := 1000
	points := fillView(tree.View(), pointNum)
	for i, p := range points {
		for d := 0; d < dups; d++ {
			tree.Insert(p.x, p.y, name+strconv.Itoa(i)+"_"+strconv.Itoa(d))
		}
	}
	delView := subView(tree.View())
	expDel := new(list.List)
	expCol := new(list.List)
	for i, p := range points {
		if delView.contains(p.x, p.y) {
			for d := 0; d < dups; d++ {
				expDel.PushBack(name + strconv.Itoa(i) + "_" + strconv.Itoa(d))
			}
		} else {
			for d := 0; d < dups; d++ {
				expCol.PushBack(name + strconv.Itoa(i) + "_" + strconv.Itoa(d))
			}
		}
	}
	pred, deleted := CollectingDelete()
	testDelete(tree, delView, pred, deleted, expDel, t, "Scatter Insert and Delete Under Area With Three Elements Per Location")
	fun, results := SimpleSurvey()
	testSurvey(tree, tree.View(), fun, results, expCol, t, "Scatter Insert and Delete Under Area With Three Elements Per Location")
}
开发者ID:fmstephe,项目名称:location_server,代码行数:28,代码来源:tquadtree_test.go

示例14: testDeleteSimple

// Tests a very limited deletion scenario. Here we will insert every element in 'insert' into the tree at a
// single random point. Then we will delete every element in delete from the tree.
// If exact == true then the view used to delete covers eactly the insertion point. Otherwise, it covers the
// entire tree.
// We assert that every element of delete has been deleted from the tree (testDelete)
// We assert that every element in insert but not in delete is still in the tree (testSurvey)
// errPrfx is used to distinguish the error messages from different tests using this method.
func testDeleteSimple(tree T, insert, delete []interface{}, exact bool, errPrfx string, t *testing.T) {
	x, y := randomPosition(tree.View())
	for _, e := range insert {
		tree.Insert(x, y, e)
	}
	expCol := new(list.List)
OUTER_LOOP:
	for _, i := range insert {
		for _, d := range delete {
			if i == d {
				continue OUTER_LOOP
			}
		}
		expCol.PushBack(i)
	}
	expDel := new(list.List)
	for _, d := range delete {
		expDel.PushBack(d)
	}
	pred, deleted := makeDelClosure(delete)
	delView := tree.View()
	if exact {
		delView = NewViewP(x, x, y, y)
	}
	testDelete(tree, delView, pred, deleted, expDel, t, errPrfx)
	fun, collected := SimpleSurvey()
	testSurvey(tree, tree.View(), fun, collected, expCol, t, errPrfx)
}
开发者ID:fmstephe,项目名称:location_server,代码行数:35,代码来源:tquadtree_test.go

示例15: loadInputTemplate

func loadInputTemplate(name string, loader TemplateLoader) (Template, error) {
	t, err := loader.LoadTemplate(name)
	if err != nil {
		return Template{}, nil
	}

	load_tracker := map[string]bool{name: true}
	var load_queue list.List
	for _, new_name := range t.InputDependencies {
		if !load_tracker[new_name] {
			load_tracker[new_name] = true
			load_queue.PushBack(new_name)
		}
	}

	for e := load_queue.Front(); e != nil; e = e.Next() {
		template_name := e.Value.(string)
		new_template, err := loader.LoadTemplate(template_name)

		if err != nil {
			return Template{}, err
		}

		t.Inputs = append(t.Inputs, new_template.Inputs...)
		for _, new_name := range new_template.InputDependencies {
			if !load_tracker[new_name] {
				load_tracker[new_name] = true
				load_queue.PushBack(new_name)
			}
		}
	}

	return t, nil
}
开发者ID:Popog,项目名称:gotemp,代码行数:34,代码来源:template.go


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